chiark / gitweb /
addr.c, linux.h, yaid.h: Move things out of the address-type list macro.
authorMark Wooding <mdw@distorted.org.uk>
Thu, 18 Oct 2012 09:27:28 +0000 (10:27 +0100)
committerMark Wooding <mdw@distorted.org.uk>
Sun, 21 Oct 2012 15:08:58 +0000 (16:08 +0100)
Things which are only needed to initialize the table are now in
systematically named macros which are determined by the table population
machinery.  This means we can build the system-specific operations
table in the same way.

addr.c
linux.c
yaid.h

diff --git a/addr.c b/addr.c
index 25211dfdfe0a014a3e58232f425e5fb4bc28c32a..e72a7fd699e5abe5861bd3ea9bbd9ce980eb9bb2 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 },
diff --git a/linux.c b/linux.c
index 7ff1abcc4f619a1eee2bd5f4de3cff6c6c675612..15db30b65a6435a58a49b64c1fef0857a380b1c1 100644 (file)
--- a/linux.c
+++ b/linux.c
@@ -35,12 +35,12 @@ struct addrops_sys {
   int (*parseaddr)(char **, union addr *);
 };
 
+#define PROCFILE_IPV4 "/proc/net/tcp"
+
 static int parseaddr_ipv4(char **pp, union addr *a)
   { a->ipv4.s_addr = strtoul(*pp, pp, 16); return (0); }
 
-const struct addrops_sys addrops_sys_ipv4 = {
-  "/proc/net/tcp", parseaddr_ipv4
-};
+#define PROCFILE_IPV6 "/proc/net/tcp6"
 
 static int parseaddr_ipv6(char **pp, union addr *a)
 {
@@ -65,9 +65,12 @@ static int parseaddr_ipv6(char **pp, union addr *a)
   return (0);
 }
 
-const struct addrops_sys addrops_sys_ipv6 = {
-  "/proc/net/tcp6", parseaddr_ipv6
-};
+#define DEFOPSYS(ty, TY)                                               \
+  const struct addrops_sys addrops_sys_##ty = {                                \
+    PROCFILE_##TY, parseaddr_##ty                                      \
+  };
+ADDRTYPES(DEFOPSYS)
+#undef DEFOPSYS
 
 /*----- Main code ---------------------------------------------------------*/
 
diff --git a/yaid.h b/yaid.h
index 85ad397a4e69e870c7fd04afb11c792fc98315d7..f8f6470fbb0ff5155c3d0ee63da94dba3a7a5a80 100644 (file)
--- a/yaid.h
+++ b/yaid.h
@@ -108,8 +108,8 @@ struct sockpat {
 };
 
 #define ADDRTYPES(_)                                                   \
-  _(ipv4, IPV4, INET, "IPv4", 32)                                      \
-  _(ipv6, IPV6, INET6, "IPv6", 128)
+  _(ipv4, IPV4)                                                                \
+  _(ipv6, IPV6)
 
 struct addrops {
   int af;
@@ -125,14 +125,14 @@ struct addrops {
 };
 
 enum {
-#define DEFADDR(ty, TY, af, name, len) ADDR_##TY,
+#define DEFADDR(ty, TY) ADDR_##TY,
   ADDRTYPES(DEFADDR)
 #undef DEFADDR
   ADDR_LIMIT
 };
 
 extern const struct addrops addroptab[];
-#define OPS_SYS(ty, TY, af, name, len)                                 \
+#define OPS_SYS(ty, TY)                                        \
   extern const struct addrops_sys addrops_sys_##ty;
 ADDRTYPES(OPS_SYS)
 #undef OPS_SYS