chiark / gitweb /
linux.c: Mark debugging code with a more useful preprocessor macro name.
[yaid] / addr.c
diff --git a/addr.c b/addr.c
index 25211dfdfe0a014a3e58232f425e5fb4bc28c32a..bfbbabf4aef7e42b41d7570d3a1a706c068f3b86 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); }
 
@@ -106,10 +114,12 @@ static const union addr any_ipv6 = { .ipv6 = IN6ADDR_ANY_INIT };
 
 /*----- General utilities -------------------------------------------------*/
 
+/* Answer whether the sockets SA and SB are equal. */
 int sockeq(const struct addrops *ao,
           const struct socket *sa, const struct socket *sb)
   { return (ao->addreq(&sa->addr, &sb->addr) && sa->port == sb->port); }
 
+/* Write a textual description of S to the string D. */
 void dputsock(dstr *d, const struct addrops *ao, const struct socket *s)
 {
   char buf[ADDRLEN];
@@ -123,8 +133,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 },