xorp

comm_api.h

00001 /* -*-  Mode:C; c-basic-offset:4; tab-width:8; indent-tabs-mode:t -*- */
00002 /* vim:set sts=4 ts=8: */
00003 /*
00004  * Copyright (c) 2001-2011 XORP, Inc and Others
00005  * YOID Project.
00006  * University of Southern California/Information Sciences Institute.
00007  * All rights reserved.
00008  *
00009  * Redistribution and use in source and binary forms, with or without
00010  * modification, are permitted provided that the following conditions
00011  * are met:
00012  * 1. Redistributions of source code must retain the above copyright
00013  *    notice, this list of conditions and the following disclaimer.
00014  * 2. Redistributions in binary form must reproduce the above copyright
00015  *    notice, this list of conditions and the following disclaimer in the
00016  *    documentation and/or other materials provided with the distribution.
00017  * 3. Neither the name of the project nor the names of its contributors
00018  *    may be used to endorse or promote products derived from this software
00019  *    without specific prior written permission.
00020  *
00021  * THIS SOFTWARE IS PROVIDED BY THE PROJECT AND CONTRIBUTORS ``AS IS'' AND
00022  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
00023  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
00024  * ARE DISCLAIMED.  IN NO EVENT SHALL THE PROJECT OR CONTRIBUTORS BE LIABLE
00025  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
00026  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
00027  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
00028  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
00029  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
00030  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
00031  * SUCH DAMAGE.
00032  */
00033 
00034 #ifndef __LIBCOMM_COMM_API_H__
00035 #define __LIBCOMM_COMM_API_H__
00036 
00037 
00038 /*
00039  * COMM socket library API header.
00040  */
00041 #ifdef HAVE_SYS_SOCKET_H
00042 #include <sys/socket.h>
00043 #endif
00044 #ifdef HAVE_NETINET_IN_H
00045 #include <netinet/in.h>
00046 #endif
00047 
00048 /*
00049  * Constants definitions
00050  */
00051 #define SO_RCV_BUF_SIZE_MIN (48*1024)  /* min. rcv socket buf size       */
00052 #define SO_RCV_BUF_SIZE_MAX (256*1024) /* desired rcv socket buf size    */
00053 #define SO_SND_BUF_SIZE_MIN (48*1024)  /* min. snd socket buf size       */
00054 #define SO_SND_BUF_SIZE_MAX (256*1024) /* desired snd socket buf size    */
00055 
00056 #define COMM_SOCK_ADDR_PORT_REUSE   1
00057 #define COMM_SOCK_ADDR_PORT_DONTREUSE   0
00058 #define COMM_SOCK_BLOCKING      1
00059 #define COMM_SOCK_NONBLOCKING       0
00060 
00061 #define COMM_LISTEN_DEFAULT_BACKLOG 50
00062 
00063 #ifndef AF_LOCAL
00064 #define AF_LOCAL        AF_UNIX    /* XXX: AF_UNIX is the older name */
00065 #endif
00066 
00067 /*
00068  * Structures, typedefs and macros
00069  */
00070 #ifndef HTONS
00071 #define HTONS(x) ((x) = htons((u_short)(x)))
00072 #endif
00073 #ifndef NTOHS
00074 #define NTOHS(x) ((x) = ntohs((u_short)(x)))
00075 #endif
00076 #ifndef HTONL
00077 #define HTONL(x) ((x) = htonl((u_long)(x)))
00078 #endif
00079 #ifndef NTOHL
00080 #define NTOHL(x) ((x) = ntohl((u_long)(x)))
00081 #endif
00082 
00083 
00084 /*
00085  * Global variables
00086  */
00087 
00088 /*
00089  * Global functions prototypes
00090  */
00091 __BEGIN_DECLS
00092 /*
00093  * The high-level `user' API.
00094  */
00095 
00103 extern int  comm_init(void);
00104 
00110 extern void comm_exit(void);
00111 
00118 extern int  comm_get_last_error(void);
00119 
00128 extern char const * comm_get_error_str(int serrno);
00129 
00135 extern char const *comm_get_last_error_str(void);
00136 
00142 extern int  comm_ipv4_present(void);
00143 
00149 extern int  comm_ipv6_present(void);
00150 
00156 extern int  comm_bindtodevice_present(void);
00157 
00163 extern int  comm_linger_present(void);
00164 
00170 extern int  comm_keepalive_present(void);
00171 
00177 extern int  comm_nosigpipe_present(void);
00178 
00184 extern int  comm_onesbcast_present(void);
00185 
00191 extern int  comm_tos_present(void);
00192 
00198 extern int  comm_nopush_present(void);
00199 
00205 extern int  comm_unicast_ttl_present(void);
00206 
00215 extern xsock_t  comm_open_tcp(int family, int is_blocking);
00216 
00225 extern xsock_t  comm_open_udp(int family, int is_blocking);
00226 
00233 extern int  comm_close(xsock_t sock);
00234 
00242 extern int  comm_listen(xsock_t sock, int backlog);
00243 
00254 extern xsock_t  comm_bind_tcp4(const struct in_addr *my_addr,
00255                    unsigned short my_port, int is_blocking);
00256 
00270 extern xsock_t  comm_bind_tcp6(const struct in6_addr *my_addr,
00271                    unsigned int my_ifindex, unsigned short my_port,
00272                    int is_blocking);
00273 
00284 extern xsock_t  comm_bind_tcp(const struct sockaddr *sin, int is_blocking);
00285 
00296 extern xsock_t  comm_bind_udp4(const struct in_addr *my_addr,
00297                    unsigned short my_port, int is_blocking,
00298                    int reuse_flag);
00299 
00313 extern xsock_t  comm_bind_udp6(const struct in6_addr *my_addr,
00314                    unsigned int my_ifindex, unsigned short my_port,
00315                    int is_blocking);
00316 
00340 extern xsock_t  comm_bind_join_udp4(const struct in_addr *mcast_addr,
00341                     const struct in_addr *join_if_addr,
00342                     unsigned short my_port,
00343                     int reuse_flag, int is_blocking);
00344 
00368 extern xsock_t  comm_bind_join_udp6(const struct in6_addr *mcast_addr,
00369                     unsigned int my_ifindex,
00370                     unsigned short my_port,
00371                     int reuse_flag, int is_blocking);
00372 
00387 extern xsock_t  comm_connect_tcp4(const struct in_addr *remote_addr,
00388                   unsigned short remote_port,
00389                   int is_blocking,
00390                   int *in_progress);
00391 
00406 extern xsock_t  comm_connect_tcp6(const struct in6_addr *remote_addr,
00407                   unsigned short remote_port,
00408                   int is_blocking,
00409                   int *in_progress);
00410 
00425 extern xsock_t  comm_connect_udp4(const struct in_addr *remote_addr,
00426                   unsigned short remote_port,
00427                   int is_blocking,
00428                   int *in_progress);
00429 
00444 extern xsock_t  comm_connect_udp6(const struct in6_addr *remote_addr,
00445                   unsigned short remote_port,
00446                   int is_blocking,
00447                   int *in_progress);
00448 
00467 extern xsock_t  comm_bind_connect_tcp4(const struct in_addr *local_addr,
00468                        unsigned short local_port,
00469                        const struct in_addr *remote_addr,
00470                        unsigned short remote_port,
00471                        int is_blocking,
00472                        int *in_progress);
00473 
00495 extern xsock_t  comm_bind_connect_tcp6(const struct in6_addr *local_addr,
00496                        unsigned int my_ifindex,
00497                        unsigned short local_port,
00498                        const struct in6_addr *remote_addr,
00499                        unsigned short remote_port,
00500                        int is_blocking,
00501                        int *in_progress);
00502 
00521 extern xsock_t  comm_bind_connect_udp4(const struct in_addr *local_addr,
00522                        unsigned short local_port,
00523                        const struct in_addr *remote_addr,
00524                        unsigned short remote_port,
00525                        int is_blocking,
00526                        int *in_progress);
00527 
00549 extern xsock_t  comm_bind_connect_udp6(const struct in6_addr *local_addr,
00550                        unsigned int my_ifindex,
00551                        unsigned short local_port,
00552                        const struct in6_addr *remote_addr,
00553                        unsigned short remote_port,
00554                        int is_blocking,
00555                        int *in_progress);
00556 
00557 extern xsock_t  comm_bind_unix(const char* path, int is_blocking);
00558 extern xsock_t  comm_connect_unix(const char* path, int is_blocking);
00559 
00560 /*
00561  * The low-level `sock' API.
00562  */
00563 
00577 extern xsock_t  comm_sock_open(int domain, int type, int protocol,
00578                    int is_blocking);
00579 
00599 extern int  comm_sock_pair(int domain, int type, int protocol,
00600                    xsock_t sv[2]);
00601 
00611 extern int  comm_sock_bind4(xsock_t sock, const struct in_addr *my_addr,
00612                 unsigned short my_port);
00613 
00626 extern int  comm_sock_bind6(xsock_t sock, const struct in6_addr *my_addr,
00627                 unsigned int my_ifindex,
00628                 unsigned short my_port);
00629 
00639 extern int  comm_sock_bind(xsock_t sock, const struct sockaddr *sin);
00640 
00650 extern int  comm_sock_join4(xsock_t sock,
00651                 const struct in_addr *mcast_addr,
00652                 const struct in_addr *my_addr);
00653 
00663 extern int  comm_sock_join6(xsock_t sock,
00664                 const struct in6_addr *mcast_addr,
00665                 unsigned int my_ifindex);
00666 
00676 extern int  comm_sock_leave4(xsock_t sock,
00677                  const struct in_addr *mcast_addr,
00678                  const struct in_addr *my_addr);
00679 
00689 extern int  comm_sock_leave6(xsock_t sock,
00690                  const struct in6_addr *mcast_addr,
00691                  unsigned int my_ifindex);
00692 
00710 extern int  comm_sock_connect4(xsock_t sock,
00711                    const struct in_addr *remote_addr,
00712                    unsigned short remote_port,
00713                    int is_blocking,
00714                    int *in_progress);
00715 
00733 extern int  comm_sock_connect6(xsock_t sock,
00734                    const struct in6_addr *remote_addr,
00735                    unsigned short remote_port,
00736                    int is_blocking,
00737                    int *in_progress);
00738 
00757 extern int  comm_sock_connect(xsock_t sock, const struct sockaddr *sin,
00758                   int is_blocking, int *in_progress);
00759 
00766 extern xsock_t  comm_sock_accept(xsock_t sock);
00767 
00775 extern int  comm_sock_listen(xsock_t sock, int backlog);
00776 
00783 extern int  comm_sock_close(xsock_t sock);
00784 
00792 extern int  comm_set_send_broadcast(xsock_t sock, int val);
00793 
00802 extern int  comm_set_receive_broadcast(xsock_t sock, int val);
00803 
00811 extern int  comm_set_nodelay(xsock_t sock, int val);
00812 
00820 extern int  comm_set_nopush(xsock_t sock, int val);
00821 
00829 extern int  comm_set_linger(xsock_t sock, int enabled, int secs);
00830 
00838 extern int  comm_set_keepalive(xsock_t sock, int val);
00839 
00847 extern int  comm_set_nosigpipe(xsock_t sock, int val);
00848 
00858 extern int  comm_set_reuseaddr(xsock_t sock, int val);
00859 
00869 extern int  comm_set_reuseport(xsock_t sock, int val);
00870 
00878 extern int  comm_set_loopback(xsock_t sock, int val);
00879 
00889 extern int  comm_set_tcpmd5(xsock_t sock, int val);
00890 
00898 extern int  comm_set_tos(xsock_t sock, int val);
00899 
00907 extern int  comm_set_unicast_ttl(xsock_t sock, int val);
00908 
00916 extern int  comm_set_multicast_ttl(xsock_t sock, int val);
00917 
00927 extern int  comm_set_iface4(xsock_t sock, const struct in_addr *in_addr);
00928 
00938 extern int  comm_set_iface6(xsock_t sock, unsigned int my_ifindex);
00939 
00952 extern int  comm_set_bindtodevice(xsock_t sock, const char * my_ifname);
00953 
00966 extern int  comm_set_onesbcast(xsock_t sock, int enabled);
00967 
00977 extern int  comm_sock_set_sndbuf(xsock_t sock, int desired_bufsize,
00978                      int min_bufsize);
00979 
00989 extern int  comm_sock_set_rcvbuf(xsock_t sock, int desired_bufsize,
00990                      int min_bufsize);
00991 
01000 extern int  comm_sock_get_family(xsock_t sock);
01001 
01011 extern int  comm_sock_get_type(xsock_t sock);
01012 
01020 extern int  comm_sock_set_blocking(xsock_t sock, int is_blocking);
01021 
01030 extern int  comm_sock_is_connected(xsock_t sock, int *is_connected);
01031 
01032 __END_DECLS
01033 
01034 #endif /* __LIBCOMM_COMM_API_H__ */
 All Classes Namespaces Functions Variables Typedefs Enumerations