From 3b1bed1dc06df72338b0ff180169525681c114d0 Mon Sep 17 00:00:00 2001 From: Mark Wooding Date: Thu, 18 Oct 2012 10:27:28 +0100 Subject: [PATCH] addr.c, linux.h, yaid.h: Move things out of the address-type list macro. 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 | 13 +++++++++++-- linux.c | 15 +++++++++------ yaid.h | 8 ++++---- 3 files changed, 24 insertions(+), 12 deletions(-) diff --git a/addr.c b/addr.c index 25211df..e72a7fd 100644 --- a/addr.c +++ b/addr.c @@ -30,6 +30,10 @@ /*----- 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 7ff1abc..15db30b 100644 --- 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 85ad397..f8f6470 100644 --- 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 -- 2.11.0