1999-08-13 01:37:52 -04:00
|
|
|
/************************************************
|
|
|
|
|
|
|
|
sockport.h -
|
|
|
|
|
|
|
|
$Author$
|
|
|
|
created at: Fri Apr 30 23:19:34 JST 1999
|
|
|
|
|
|
|
|
************************************************/
|
|
|
|
|
|
|
|
#ifndef SOCKPORT_H
|
|
|
|
#define SOCKPORT_H
|
|
|
|
|
2013-02-14 10:17:49 -05:00
|
|
|
#ifdef HAVE_STRUCT_SOCKADDR_SA_LEN
|
|
|
|
# define VALIDATE_SOCKLEN(addr, len) ((addr)->sa_len == (len))
|
|
|
|
#else
|
|
|
|
# define VALIDATE_SOCKLEN(addr, len) ((void)(addr), (void)(len), 1)
|
|
|
|
#endif
|
|
|
|
|
2013-02-13 18:20:27 -05:00
|
|
|
#ifdef HAVE_STRUCT_SOCKADDR_SA_LEN
|
2009-02-13 12:21:53 -05:00
|
|
|
# define SET_SA_LEN(sa, len) (void)((sa)->sa_len = (len))
|
1999-08-13 01:37:52 -04:00
|
|
|
#else
|
2009-02-13 12:21:53 -05:00
|
|
|
# define SET_SA_LEN(sa, len) (void)(len)
|
1999-08-13 01:37:52 -04:00
|
|
|
#endif
|
|
|
|
|
2013-02-15 06:30:19 -05:00
|
|
|
/* for strict-aliasing rule */
|
|
|
|
#ifdef HAVE_STRUCT_SOCKADDR_IN_SIN_LEN
|
|
|
|
# define SET_SIN_LEN(sa, len) (void)((sa)->sin_len = (len))
|
|
|
|
#else
|
|
|
|
# define SET_SIN_LEN(sa, len) SET_SA_LEN((struct sockaddr *)(sa), (len))
|
|
|
|
#endif
|
|
|
|
|
2014-02-19 05:37:43 -05:00
|
|
|
#ifdef HAVE_STRUCT_SOCKADDR_IN6_SIN6_LEN
|
|
|
|
# define SET_SIN6_LEN(sa, len) (void)((sa)->sin6_len = (len))
|
|
|
|
#else
|
|
|
|
# define SET_SIN6_LEN(sa, len) SET_SA_LEN((struct sockaddr *)(sa), (len))
|
|
|
|
#endif
|
|
|
|
|
2013-02-14 18:14:22 -05:00
|
|
|
#define INIT_SOCKADDR(addr, family, len) \
|
|
|
|
do { \
|
|
|
|
struct sockaddr *init_sockaddr_ptr = (addr); \
|
|
|
|
socklen_t init_sockaddr_len = (len); \
|
|
|
|
memset(init_sockaddr_ptr, 0, init_sockaddr_len); \
|
|
|
|
init_sockaddr_ptr->sa_family = (family); \
|
|
|
|
SET_SA_LEN(init_sockaddr_ptr, init_sockaddr_len); \
|
|
|
|
} while (0)
|
1999-08-13 01:37:52 -04:00
|
|
|
|
2013-02-15 17:08:25 -05:00
|
|
|
#define INIT_SOCKADDR_IN(addr, len) \
|
2013-02-15 06:30:19 -05:00
|
|
|
do { \
|
|
|
|
struct sockaddr_in *init_sockaddr_ptr = (addr); \
|
|
|
|
socklen_t init_sockaddr_len = (len); \
|
|
|
|
memset(init_sockaddr_ptr, 0, init_sockaddr_len); \
|
2013-02-15 17:08:25 -05:00
|
|
|
init_sockaddr_ptr->sin_family = AF_INET; \
|
2013-02-15 06:30:19 -05:00
|
|
|
SET_SIN_LEN(init_sockaddr_ptr, init_sockaddr_len); \
|
|
|
|
} while (0)
|
|
|
|
|
2014-02-19 05:37:43 -05:00
|
|
|
#define INIT_SOCKADDR_IN6(addr, len) \
|
|
|
|
do { \
|
|
|
|
struct sockaddr_in6 *init_sockaddr_ptr = (addr); \
|
|
|
|
socklen_t init_sockaddr_len = (len); \
|
|
|
|
memset(init_sockaddr_ptr, 0, init_sockaddr_len); \
|
|
|
|
init_sockaddr_ptr->sin6_family = AF_INET6; \
|
|
|
|
SET_SIN6_LEN(init_sockaddr_ptr, init_sockaddr_len); \
|
|
|
|
} while (0)
|
|
|
|
|
2013-02-15 17:19:05 -05:00
|
|
|
|
|
|
|
/* for strict-aliasing rule */
|
|
|
|
#ifdef HAVE_TYPE_STRUCT_SOCKADDR_UN
|
|
|
|
# ifdef HAVE_STRUCT_SOCKADDR_IN_SUN_LEN
|
|
|
|
# define SET_SUN_LEN(sa, len) (void)((sa)->sun_len = (len))
|
|
|
|
# else
|
|
|
|
# define SET_SUN_LEN(sa, len) SET_SA_LEN((struct sockaddr *)(sa), (len))
|
|
|
|
# endif
|
|
|
|
# define INIT_SOCKADDR_UN(addr, len) \
|
|
|
|
do { \
|
|
|
|
struct sockaddr_un *init_sockaddr_ptr = (addr); \
|
|
|
|
socklen_t init_sockaddr_len = (len); \
|
|
|
|
memset(init_sockaddr_ptr, 0, init_sockaddr_len); \
|
|
|
|
init_sockaddr_ptr->sun_family = AF_UNIX; \
|
|
|
|
SET_SUN_LEN(init_sockaddr_ptr, init_sockaddr_len); \
|
|
|
|
} while (0)
|
|
|
|
#endif
|
|
|
|
|
2000-05-13 12:13:31 -04:00
|
|
|
#ifndef IN_MULTICAST
|
|
|
|
# define IN_CLASSD(i) (((long)(i) & 0xf0000000) == 0xe0000000)
|
|
|
|
# define IN_MULTICAST(i) IN_CLASSD(i)
|
|
|
|
#endif
|
|
|
|
|
2000-07-10 00:49:24 -04:00
|
|
|
#ifndef IN_EXPERIMENTAL
|
|
|
|
# define IN_EXPERIMENTAL(i) ((((long)(i)) & 0xe0000000) == 0xe0000000)
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifndef IN_CLASSA_NSHIFT
|
|
|
|
# define IN_CLASSA_NSHIFT 24
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifndef IN_LOOPBACKNET
|
|
|
|
# define IN_LOOPBACKNET 127
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifndef AF_UNSPEC
|
|
|
|
# define AF_UNSPEC 0
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifndef PF_UNSPEC
|
|
|
|
# define PF_UNSPEC AF_UNSPEC
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifndef PF_INET
|
|
|
|
# define PF_INET AF_INET
|
|
|
|
#endif
|
|
|
|
|
2000-08-24 02:29:30 -04:00
|
|
|
#if defined(HOST_NOT_FOUND) && !defined(h_errno) && !defined(__CYGWIN__)
|
|
|
|
extern int h_errno;
|
|
|
|
#endif
|
|
|
|
|
1999-08-13 01:37:52 -04:00
|
|
|
#endif
|