X-Git-Url: https://www.chiark.greenend.org.uk/ucgi/~mdw/git/yaid/blobdiff_plain/bf4d97617c92530ab67923aaba802333ee258352..HEAD:/addr.c diff --git a/addr.c b/addr.c index 25211df..bfbbabf 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); } @@ -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 },