#define SET_SS_FAMILY(x, y) ((((struct sockaddr *)(x))->sa_family) = y)
#ifdef RB_SOCKADDR_HAS_SA_LEN
#define SET_SS_LEN(x, y) do { \
- struct sockaddr *storage; \
- storage = ((struct sockaddr *)(x));\
- storage->sa_len = (y); \
+ struct sockaddr *_storage; \
+ _storage = ((struct sockaddr *)(x));\
+ _storage->sa_len = (y); \
} while (0)
#define GET_SS_LEN(x) (((struct sockaddr *)(x))->sa_len)
#else /* !RB_SOCKADDR_HAS_SA_LEN */
#endif
#endif
+#ifdef RB_IPV6
+#define GET_SS_PORT(x) (((struct sockaddr *)(x))->sa_family == AF_INET ? ((struct sockaddr_in *)(x))->sin_port : ((struct sockaddr_in6 *)(x))->sin6_port)
+#define SET_SS_PORT(x, y) do { \
+ if(((struct sockaddr *)(x))->sa_family == AF_INET) { \
+ ((struct sockaddr_in *)(x))->sin_port = (y); \
+ } else { \
+ ((struct sockaddr_in6 *)(x))->sin6_port = (y); \
+ } \
+ } while (0)
+#else
+#define GET_SS_PORT(x) (((struct sockaddr_in *)(x))->sin_port)
+#define SET_SS_PORT(x, y) (((struct sockaddr_in *)(x))->sin_port = y)
+#endif
+
#ifndef INADDRSZ
#define INADDRSZ 4
#endif