summaryrefslogtreecommitdiffhomepage
path: root/src/sock.h
diff options
context:
space:
mode:
Diffstat (limited to 'src/sock.h')
-rw-r--r--src/sock.h14
1 files changed, 14 insertions, 0 deletions
diff --git a/src/sock.h b/src/sock.h
index 722371d..aee5bf5 100644
--- a/src/sock.h
+++ b/src/sock.h
@@ -31,6 +31,20 @@
#include "common.h"
#include "sblist.h"
+#define SOCKADDR_UNION_AF(PTR) (PTR)->v4.sin_family
+
+#define SOCKADDR_UNION_LENGTH(PTR) ( \
+ ( SOCKADDR_UNION_AF(PTR) == AF_INET ) ? sizeof((PTR)->v4) : ( \
+ ( SOCKADDR_UNION_AF(PTR) == AF_INET6 ) ? sizeof((PTR)->v6) : 0 ) )
+
+#define SOCKADDR_UNION_ADDRESS(PTR) ( \
+ ( SOCKADDR_UNION_AF(PTR) == AF_INET ) ? (void*) &(PTR)->v4.sin_addr : ( \
+ ( SOCKADDR_UNION_AF(PTR) == AF_INET6 ) ? (void*) &(PTR)->v6.sin6_addr : (void*) 0 ) )
+
+#define SOCKADDR_UNION_PORT(PTR) ( \
+ ( SOCKADDR_UNION_AF(PTR) == AF_INET ) ? (PTR)->v4.sin_port : ( \
+ ( SOCKADDR_UNION_AF(PTR) == AF_INET6 ) ? (PTR)->v6.sin6_port : 0 ) )
+
union sockaddr_union {
struct sockaddr_in v4;
struct sockaddr_in6 v6;