linux.c: Do NAT detection using address-independent machinery.
[yaid] / addr.c
diff --git a/addr.c b/addr.c
index 25211df..e72a7fd 100644 (file)
--- a/addr.c
+++ b/addr.c
 
 /*----- IPv4 addresses ----------------------------------------------------*/
 
+#define ADDRFAM_IPV4 AF_INET
+#define NAME_IPV4 "IPv4"
+#define ADDRLEN_IPV4 32
+
 static int addreq_ipv4(const union addr *a, const union addr *b)
   { return a->ipv4.s_addr == b->ipv4.s_addr; }
 
@@ -62,6 +66,10 @@ static const union addr any_ipv4 = { .ipv4.s_addr = INADDR_ANY };
 
 /*----- IPv6 addresses ----------------------------------------------------*/
 
+#define ADDRFAM_IPV6 AF_INET6
+#define NAME_IPV6 "IPv6"
+#define ADDRLEN_IPV6 128
+
 static int addreq_ipv6(const union addr *a, const union addr *b)
   { return !memcmp(a->ipv6.s6_addr, b->ipv6.s6_addr, 16); }
 
@@ -123,8 +131,9 @@ void dputsock(dstr *d, const struct addrops *ao, const struct socket *s)
 /*----- The operations table ----------------------------------------------*/
 
 const struct addrops addroptab[] = {
-#define DEFOPS(ty, TY, af, name, len)                                  \
-  { AF_##af, name, len, &any_##ty, &addrops_sys_##ty,                  \
+#define DEFOPS(ty, TY)                                                 \
+  { ADDRFAM_##TY, NAME_##TY, ADDRLEN_##TY,                             \
+    &any_##ty, &addrops_sys_##ty,                                      \
     addreq_##ty, match_addrpat_##ty,                                   \
     socket_to_sockaddr_##ty, sockaddr_to_addr_##ty,                    \
     init_listen_socket_##ty },