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.
/*----- IPv4 addresses ----------------------------------------------------*/
/*----- 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; }
static int addreq_ipv4(const union addr *a, const union addr *b)
{ return a->ipv4.s_addr == b->ipv4.s_addr; }
/*----- IPv6 addresses ----------------------------------------------------*/
/*----- 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); }
static int addreq_ipv6(const union addr *a, const union addr *b)
{ return !memcmp(a->ipv6.s6_addr, b->ipv6.s6_addr, 16); }
/*----- The operations table ----------------------------------------------*/
const struct addrops addroptab[] = {
/*----- 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 },
addreq_##ty, match_addrpat_##ty, \
socket_to_sockaddr_##ty, sockaddr_to_addr_##ty, \
init_listen_socket_##ty },
int (*parseaddr)(char **, union addr *);
};
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); }
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)
{
static int parseaddr_ipv6(char **pp, union addr *a)
{
-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 ---------------------------------------------------------*/
/*----- Main code ---------------------------------------------------------*/
};
#define ADDRTYPES(_) \
};
#define ADDRTYPES(_) \
- _(ipv4, IPV4, INET, "IPv4", 32) \
- _(ipv6, IPV6, INET6, "IPv6", 128)
+ _(ipv4, IPV4) \
+ _(ipv6, IPV6)
-#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[];
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
extern const struct addrops_sys addrops_sys_##ty;
ADDRTYPES(OPS_SYS)
#undef OPS_SYS