diff options
-rw-r--r-- | usr.bin/dig/dig.c | 4 | ||||
-rw-r--r-- | usr.bin/dig/dig.h | 12 | ||||
-rw-r--r-- | usr.bin/dig/dighost.c | 38 | ||||
-rw-r--r-- | usr.bin/dig/host.c | 2 | ||||
-rw-r--r-- | usr.bin/dig/lib/isc/include/isc/sockaddr.h | 46 | ||||
-rw-r--r-- | usr.bin/dig/lib/isc/include/isc/socket.h | 12 | ||||
-rw-r--r-- | usr.bin/dig/lib/isc/include/isc/types.h | 3 | ||||
-rw-r--r-- | usr.bin/dig/lib/isc/sockaddr.c | 160 | ||||
-rw-r--r-- | usr.bin/dig/lib/isc/unix/socket.c | 32 | ||||
-rw-r--r-- | usr.bin/dig/nslookup.c | 4 |
10 files changed, 165 insertions, 148 deletions
diff --git a/usr.bin/dig/dig.c b/usr.bin/dig/dig.c index 0fe3177a91e..a0988a0567b 100644 --- a/usr.bin/dig/dig.c +++ b/usr.bin/dig/dig.c @@ -14,7 +14,7 @@ * PERFORMANCE OF THIS SOFTWARE. */ -/* $Id: dig.c,v 1.17 2020/09/15 11:46:19 florian Exp $ */ +/* $Id: dig.c,v 1.18 2020/09/15 11:47:42 florian Exp $ */ /*! \file */ #include <sys/cdefs.h> @@ -169,7 +169,7 @@ help(void) { * Callback from dighost.c to print the received message. */ static void -received(unsigned int bytes, isc_sockaddr_t *from, dig_query_t *query) { +received(unsigned int bytes, struct sockaddr_storage *from, dig_query_t *query) { time_t tnow; struct tm tmnow; char time_str[100]; diff --git a/usr.bin/dig/dig.h b/usr.bin/dig/dig.h index 9f272738e86..86e7ee65bd6 100644 --- a/usr.bin/dig/dig.h +++ b/usr.bin/dig/dig.h @@ -147,7 +147,7 @@ struct dig_lookup { isc_buffer_t *querysig; uint32_t msgcounter; dns_fixedname_t fdomain; - isc_sockaddr_t *ecs_addr; + struct sockaddr_storage *ecs_addr; int ecs_plen; char *sitvalue; dns_ednsopt_t *ednsopts; @@ -189,7 +189,7 @@ struct dig_query { isc_socket_t *sock; ISC_LINK(dig_query_t) link; ISC_LINK(dig_query_t) clink; - isc_sockaddr_t sockaddr; + struct sockaddr_storage sockaddr; struct timespec time_sent; struct timespec time_recv; uint64_t byte_count; @@ -229,7 +229,7 @@ extern int sendcount; extern int ndots; extern int lookup_counter; extern int exitcode; -extern isc_sockaddr_t bind_address; +extern struct sockaddr_storage bind_address; extern char keynametext[MXNAME]; extern char keyfile[MXNAME]; extern char keysecret[MXNAME]; @@ -254,7 +254,7 @@ int nslookup_main(int, char **); * Routines in dighost.c. */ isc_result_t -get_address(char *host, in_port_t port, isc_sockaddr_t *sockaddr); +get_address(char *host, in_port_t port, struct sockaddr_storage *sockaddr); int getaddresses(dig_lookup_t *lookup, const char *host, isc_result_t *resultp); @@ -298,7 +298,7 @@ void setup_system(int ipv4only, int ipv6only); isc_result_t -parse_netprefix(isc_sockaddr_t **sap, int *plen, const char *value); +parse_netprefix(struct sockaddr_storage **sap, int *plen, const char *value); void parse_hmac(const char *hmacstr); @@ -352,7 +352,7 @@ extern isc_result_t */ extern void -(*dighost_received)(unsigned int bytes, isc_sockaddr_t *from, dig_query_t *query); +(*dighost_received)(unsigned int bytes, struct sockaddr_storage *from, dig_query_t *query); /*%< * Print a message about where and when the response * was received from, like the final comment in the diff --git a/usr.bin/dig/dighost.c b/usr.bin/dig/dighost.c index 278df03bb5d..52afde3d7d3 100644 --- a/usr.bin/dig/dighost.c +++ b/usr.bin/dig/dighost.c @@ -14,7 +14,7 @@ * PERFORMANCE OF THIS SOFTWARE. */ -/* $Id: dighost.c,v 1.33 2020/09/15 11:46:19 florian Exp $ */ +/* $Id: dighost.c,v 1.34 2020/09/15 11:47:42 florian Exp $ */ /*! \file * \note @@ -96,8 +96,8 @@ isc_taskmgr_t *taskmgr = NULL; isc_task_t *global_task = NULL; isc_timermgr_t *timermgr = NULL; isc_socketmgr_t *socketmgr = NULL; -isc_sockaddr_t bind_address; -isc_sockaddr_t bind_any; +struct sockaddr_storage bind_address; +struct sockaddr_storage bind_any; int sendcount = 0; int recvcount = 0; int sockcount = 0; @@ -108,7 +108,7 @@ int lookup_counter = 0; static char sitvalue[256]; isc_socket_t *keep = NULL; -isc_sockaddr_t keepaddr; +struct sockaddr_storage keepaddr; static const struct { const char *ns; @@ -178,7 +178,7 @@ isc_result_t int headers); void -(*dighost_received)(unsigned int bytes, isc_sockaddr_t *from, dig_query_t *query); +(*dighost_received)(unsigned int bytes, struct sockaddr_storage *from, dig_query_t *query); void (*dighost_trying)(char *frm, dig_lookup_t *lookup); @@ -494,7 +494,7 @@ flush_server_list(void) { /* this used to be bind9_getaddresses from lib/bind9 */ static isc_result_t get_addresses(const char *hostname, in_port_t dstport, - isc_sockaddr_t *addrs, int addrsize, int *addrcount) + struct sockaddr_storage *addrs, int addrsize, int *addrcount) { struct addrinfo *ai = NULL, *tmpai, hints; int result, i; @@ -556,7 +556,7 @@ get_addresses(const char *hostname, in_port_t dstport, isc_result_t set_nameserver(char *opt) { isc_result_t result; - isc_sockaddr_t sockaddrs[DIG_MAX_ADDRESSES]; + struct sockaddr_storage sockaddrs[DIG_MAX_ADDRESSES]; int count, i; dig_server_t *srv; char tmp[NI_MAXHOST]; @@ -573,8 +573,8 @@ set_nameserver(char *opt) { for (i = 0; i < count; i++) { int error; - error = getnameinfo(&sockaddrs[i].type.sa, - sockaddrs[i].type.sa.sa_len, tmp, sizeof(tmp), NULL, 0, + error = getnameinfo((struct sockaddr *)&sockaddrs[i], + sockaddrs[i].ss_len, tmp, sizeof(tmp), NULL, 0, NI_NUMERICHOST | NI_NUMERICSERV); if (error) fatal("%s", gai_strerror(error)); @@ -825,7 +825,7 @@ clone_lookup(dig_lookup_t *lookold, int servers) { looknew->eoferr = lookold->eoferr; if (lookold->ecs_addr != NULL) { - size_t len = sizeof(isc_sockaddr_t); + size_t len = sizeof(struct sockaddr_storage); looknew->ecs_addr = malloc(len); if (looknew->ecs_addr == NULL) fatal("out of memory"); @@ -933,8 +933,8 @@ parse_bits(char *arg, uint32_t max) { } isc_result_t -parse_netprefix(isc_sockaddr_t **sap, int *plen, const char *value) { - isc_sockaddr_t *sa = NULL; +parse_netprefix(struct sockaddr_storage **sap, int *plen, const char *value) { + struct sockaddr_storage *sa = NULL; struct in_addr in4; struct in6_addr in6; uint32_t prefix_length = 0xffffffff; @@ -955,7 +955,7 @@ parse_netprefix(isc_sockaddr_t **sap, int *plen, const char *value) { memset(sa, 0, sizeof(*sa)); if (strcmp(buf, "0") == 0) { - sa->type.sa.sa_family = AF_UNSPEC; + sa->ss_family = AF_UNSPEC; prefix_length = 0; goto done; } @@ -2189,7 +2189,7 @@ setup_lookup(dig_lookup_t *lookup) { struct sockaddr_in6 *sin6; size_t addrl; - sa = &lookup->ecs_addr->type.sa; + sa = (struct sockaddr *)lookup->ecs_addr; plen = lookup->ecs_plen; /* Round up prefix len to a multiple of 8 */ @@ -3322,7 +3322,7 @@ recv_done(isc_task_t *task, isc_event_t *event) { ISC_SOCKADDR_CMPSCOPEZERO)) { char buf1[ISC_SOCKADDR_FORMATSIZE]; char buf2[ISC_SOCKADDR_FORMATSIZE]; - isc_sockaddr_t any; + struct sockaddr_storage any; if (isc_sockaddr_pf(&query->sockaddr) == AF_INET) isc_sockaddr_any(&any); @@ -3718,7 +3718,7 @@ recv_done(isc_task_t *task, isc_event_t *event) { * routines, since they may be using a non-DNS system for these lookups. */ isc_result_t -get_address(char *host, in_port_t myport, isc_sockaddr_t *sockaddr) { +get_address(char *host, in_port_t myport, struct sockaddr_storage *sockaddr) { int count; isc_result_t result; @@ -3734,7 +3734,7 @@ get_address(char *host, in_port_t myport, isc_sockaddr_t *sockaddr) { int getaddresses(dig_lookup_t *lookup, const char *host, isc_result_t *resultp) { isc_result_t result; - isc_sockaddr_t sockaddrs[DIG_MAX_ADDRESSES]; + struct sockaddr_storage sockaddrs[DIG_MAX_ADDRESSES]; int count, i; dig_server_t *srv; char tmp[NI_MAXHOST]; @@ -3752,8 +3752,8 @@ getaddresses(dig_lookup_t *lookup, const char *host, isc_result_t *resultp) { for (i = 0; i < count; i++) { int error; - error = getnameinfo(&sockaddrs[i].type.sa, - sockaddrs[i].type.sa.sa_len, tmp, sizeof(tmp), NULL, 0, + error = getnameinfo((struct sockaddr *)&sockaddrs[i], + sockaddrs[i].ss_len, tmp, sizeof(tmp), NULL, 0, NI_NUMERICHOST | NI_NUMERICSERV); if (error) fatal("%s", gai_strerror(error)); diff --git a/usr.bin/dig/host.c b/usr.bin/dig/host.c index d5eeb404410..9a88fd1a7f3 100644 --- a/usr.bin/dig/host.c +++ b/usr.bin/dig/host.c @@ -143,7 +143,7 @@ host_shutdown(void) { } static void -received(unsigned int bytes, isc_sockaddr_t *from, dig_query_t *query) { +received(unsigned int bytes, struct sockaddr_storage *from, dig_query_t *query) { struct timespec now; if (!short_form) { diff --git a/usr.bin/dig/lib/isc/include/isc/sockaddr.h b/usr.bin/dig/lib/isc/include/isc/sockaddr.h index a8b114bb676..c29bbd30760 100644 --- a/usr.bin/dig/lib/isc/include/isc/sockaddr.h +++ b/usr.bin/dig/lib/isc/include/isc/sockaddr.h @@ -14,7 +14,7 @@ * PERFORMANCE OF THIS SOFTWARE. */ -/* $Id: sockaddr.h,v 1.6 2020/09/15 11:46:19 florian Exp $ */ +/* $Id: sockaddr.h,v 1.7 2020/09/15 11:47:42 florian Exp $ */ #ifndef ISC_SOCKADDR_H #define ISC_SOCKADDR_H 1 @@ -28,16 +28,6 @@ #include <isc/types.h> #include <sys/un.h> -struct isc_sockaddr { - union { - struct sockaddr sa; - struct sockaddr_in sin; - struct sockaddr_in6 sin6; - struct sockaddr_storage ss; - struct sockaddr_un sunix; - } type; -}; - #define ISC_SOCKADDR_CMPADDR 0x0001 /*%< compare the address * sin_addr/sin6_addr */ #define ISC_SOCKADDR_CMPPORT 0x0002 /*%< compare the port @@ -48,7 +38,7 @@ struct isc_sockaddr { * zero scopes always match */ int -isc_sockaddr_compare(const isc_sockaddr_t *a, const isc_sockaddr_t *b, +isc_sockaddr_compare(const struct sockaddr_storage *a, const struct sockaddr_storage *b, unsigned int flags); /*%< * Compare the elements of the two address ('a' and 'b') as specified @@ -58,32 +48,32 @@ isc_sockaddr_compare(const isc_sockaddr_t *a, const isc_sockaddr_t *b, */ int -isc_sockaddr_equal(const isc_sockaddr_t *a, const isc_sockaddr_t *b); +isc_sockaddr_equal(const struct sockaddr_storage *a, const struct sockaddr_storage *b); /*%< * Return 1 iff the socket addresses 'a' and 'b' are equal. */ int -isc_sockaddr_eqaddr(const isc_sockaddr_t *a, const isc_sockaddr_t *b); +isc_sockaddr_eqaddr(const struct sockaddr_storage *a, const struct sockaddr_storage *b); /*%< * Return 1 iff the address parts of the socket addresses * 'a' and 'b' are equal, ignoring the ports. */ void -isc_sockaddr_any(isc_sockaddr_t *sockaddr); +isc_sockaddr_any(struct sockaddr_storage *sockaddr); /*%< * Return the IPv4 wildcard address. */ void -isc_sockaddr_any6(isc_sockaddr_t *sockaddr); +isc_sockaddr_any6(struct sockaddr_storage *sockaddr); /*%< * Return the IPv6 wildcard address. */ void -isc_sockaddr_anyofpf(isc_sockaddr_t *sockaddr, int family); +isc_sockaddr_anyofpf(struct sockaddr_storage *sockaddr, int family); /*%< * Set '*sockaddr' to the wildcard address of protocol family * 'family'. @@ -93,21 +83,21 @@ isc_sockaddr_anyofpf(isc_sockaddr_t *sockaddr, int family); */ void -isc_sockaddr_fromin(isc_sockaddr_t *sockaddr, const struct in_addr *ina, +isc_sockaddr_fromin(struct sockaddr_storage *sockaddr, const struct in_addr *ina, in_port_t port); /*%< - * Construct an isc_sockaddr_t from an IPv4 address and port. + * Construct an struct sockaddr_storage from an IPv4 address and port. */ void -isc_sockaddr_fromin6(isc_sockaddr_t *sockaddr, const struct in6_addr *ina6, +isc_sockaddr_fromin6(struct sockaddr_storage *sockaddr, const struct in6_addr *ina6, in_port_t port); /*%< - * Construct an isc_sockaddr_t from an IPv6 address and port. + * Construct an struct sockaddr_storage from an IPv6 address and port. */ int -isc_sockaddr_pf(const isc_sockaddr_t *sockaddr); +isc_sockaddr_pf(const struct sockaddr_storage *sockaddr); /*%< * Get the protocol family of 'sockaddr'. * @@ -122,13 +112,13 @@ isc_sockaddr_pf(const isc_sockaddr_t *sockaddr); */ in_port_t -isc_sockaddr_getport(const isc_sockaddr_t *sockaddr); +isc_sockaddr_getport(const struct sockaddr_storage *sockaddr); /*%< * Get the port stored in 'sockaddr'. */ isc_result_t -isc_sockaddr_totext(const isc_sockaddr_t *sockaddr, isc_buffer_t *target); +isc_sockaddr_totext(const struct sockaddr_storage *sockaddr, isc_buffer_t *target); /*%< * Append a text representation of 'sockaddr' to the buffer 'target'. * The text will include both the IP address (v4 or v6) and the port. @@ -141,7 +131,7 @@ isc_sockaddr_totext(const isc_sockaddr_t *sockaddr, isc_buffer_t *target); */ void -isc_sockaddr_format(const isc_sockaddr_t *sa, char *array, unsigned int size); +isc_sockaddr_format(const struct sockaddr_storage *sa, char *array, unsigned int size); /*%< * Format a human-readable representation of the socket address '*sa' * into the character array 'array', which is of size 'size'. @@ -149,19 +139,19 @@ isc_sockaddr_format(const isc_sockaddr_t *sa, char *array, unsigned int size); */ int -isc_sockaddr_ismulticast(const isc_sockaddr_t *sa); +isc_sockaddr_ismulticast(const struct sockaddr_storage *sa); /*%< * Returns #1 if the address is a multicast address. */ int -isc_sockaddr_islinklocal(const isc_sockaddr_t *sa); +isc_sockaddr_islinklocal(const struct sockaddr_storage *sa); /*%< * Returns 1 if the address is a link local address. */ int -isc_sockaddr_issitelocal(const isc_sockaddr_t *sa); +isc_sockaddr_issitelocal(const struct sockaddr_storage *sa); /*%< * Returns 1 if the address is a sitelocal address. */ diff --git a/usr.bin/dig/lib/isc/include/isc/socket.h b/usr.bin/dig/lib/isc/include/isc/socket.h index 188381d6e06..0a5b143aa5c 100644 --- a/usr.bin/dig/lib/isc/include/isc/socket.h +++ b/usr.bin/dig/lib/isc/include/isc/socket.h @@ -14,7 +14,7 @@ * PERFORMANCE OF THIS SOFTWARE. */ -/* $Id: socket.h,v 1.6 2020/02/24 13:49:39 jsg Exp $ */ +/* $Id: socket.h,v 1.7 2020/09/15 11:47:42 florian Exp $ */ #ifndef ISC_SOCKET_H #define ISC_SOCKET_H 1 @@ -93,7 +93,7 @@ struct isc_socketevent { unsigned int offset; /*%< offset into buffer list */ isc_region_t region; /*%< for single-buffer i/o */ isc_bufferlist_t bufferlist; /*%< list of buffers */ - isc_sockaddr_t address; /*%< source address */ + struct sockaddr_storage address; /*%< source address */ struct timespec timestamp; /*%< timestamp of packet recv */ struct in6_pktinfo pktinfo; /*%< ipv6 pktinfo */ uint32_t attributes; /*%< see below */ @@ -106,7 +106,7 @@ struct isc_socket_newconnev { ISC_EVENT_COMMON(isc_socket_newconnev_t); isc_socket_t * newsocket; isc_result_t result; /*%< OK, EOF, whatever else */ - isc_sockaddr_t address; /*%< source address */ + struct sockaddr_storage address; /*%< source address */ }; typedef struct isc_socket_connev isc_socket_connev_t; @@ -309,7 +309,7 @@ isc_socket_detach(isc_socket_t **socketp); */ isc_result_t -isc_socket_bind(isc_socket_t *sock, isc_sockaddr_t *addressp, +isc_socket_bind(isc_socket_t *sock, struct sockaddr_storage *addressp, unsigned int options); /*%< * Bind 'socket' to '*addressp'. @@ -331,7 +331,7 @@ isc_socket_bind(isc_socket_t *sock, isc_sockaddr_t *addressp, */ isc_result_t -isc_socket_connect(isc_socket_t *sock, isc_sockaddr_t *addressp, +isc_socket_connect(isc_socket_t *sock, struct sockaddr_storage *addressp, isc_task_t *task, isc_taskaction_t action, void *arg); /*%< @@ -449,7 +449,7 @@ isc_socket_sendv(isc_socket_t *sock, isc_bufferlist_t *buflist, isc_result_t isc_socket_sendtov2(isc_socket_t *sock, isc_bufferlist_t *buflist, isc_task_t *task, isc_taskaction_t action, void *arg, - isc_sockaddr_t *address, struct in6_pktinfo *pktinfo, + struct sockaddr_storage *address, struct in6_pktinfo *pktinfo, unsigned int flags); /*! * Send the contents of 'region' to the socket's peer. diff --git a/usr.bin/dig/lib/isc/include/isc/types.h b/usr.bin/dig/lib/isc/include/isc/types.h index 6822ae6c41b..000d43300c3 100644 --- a/usr.bin/dig/lib/isc/include/isc/types.h +++ b/usr.bin/dig/lib/isc/include/isc/types.h @@ -14,7 +14,7 @@ * PERFORMANCE OF THIS SOFTWARE. */ -/* $Id: types.h,v 1.6 2020/09/15 08:19:29 florian Exp $ */ +/* $Id: types.h,v 1.7 2020/09/15 11:47:42 florian Exp $ */ #ifndef ISC_TYPES_H #define ISC_TYPES_H 1 @@ -44,7 +44,6 @@ typedef struct isc_logconfig isc_logconfig_t; /*%< Log Configuration */ typedef struct isc_logmodule isc_logmodule_t; /*%< Log Module */ typedef struct isc_region isc_region_t; /*%< Region */ typedef unsigned int isc_result_t; /*%< Result */ -typedef struct isc_sockaddr isc_sockaddr_t; /*%< Socket Address */ typedef struct isc_socket isc_socket_t; /*%< Socket */ typedef struct isc_socketevent isc_socketevent_t; /*%< Socket Event */ typedef struct isc_socketmgr isc_socketmgr_t; /*%< Socket Manager */ diff --git a/usr.bin/dig/lib/isc/sockaddr.c b/usr.bin/dig/lib/isc/sockaddr.c index ee2cd7f5300..64be01a6ba7 100644 --- a/usr.bin/dig/lib/isc/sockaddr.c +++ b/usr.bin/dig/lib/isc/sockaddr.c @@ -14,7 +14,7 @@ * PERFORMANCE OF THIS SOFTWARE. */ -/* $Id: sockaddr.c,v 1.12 2020/09/15 11:46:19 florian Exp $ */ +/* $Id: sockaddr.c,v 1.13 2020/09/15 11:47:42 florian Exp $ */ /*! \file */ #include <sys/types.h> @@ -30,25 +30,28 @@ #include <isc/util.h> int -isc_sockaddr_equal(const isc_sockaddr_t *a, const isc_sockaddr_t *b) { +isc_sockaddr_equal(const struct sockaddr_storage *a, const struct sockaddr_storage *b) { return (isc_sockaddr_compare(a, b, ISC_SOCKADDR_CMPADDR| ISC_SOCKADDR_CMPPORT| ISC_SOCKADDR_CMPSCOPE)); } int -isc_sockaddr_eqaddr(const isc_sockaddr_t *a, const isc_sockaddr_t *b) { +isc_sockaddr_eqaddr(const struct sockaddr_storage *a, const struct sockaddr_storage *b) { return (isc_sockaddr_compare(a, b, ISC_SOCKADDR_CMPADDR| ISC_SOCKADDR_CMPSCOPE)); } int -isc_sockaddr_compare(const isc_sockaddr_t *a, const isc_sockaddr_t *b, +isc_sockaddr_compare(const struct sockaddr_storage *a, const struct sockaddr_storage *b, unsigned int flags) { + struct sockaddr_in *sin_a, *sin_b; + struct sockaddr_in6 *sin6_a, *sin6_b; + REQUIRE(a != NULL && b != NULL); - if (a->type.ss.ss_len != b->type.ss.ss_len) + if (a->ss_len != b->ss_len) return (0); /* @@ -56,46 +59,53 @@ isc_sockaddr_compare(const isc_sockaddr_t *a, const isc_sockaddr_t *b, * zero. */ - if (a->type.sa.sa_family != b->type.sa.sa_family) + if (a->ss_family != b->ss_family) return (0); - switch (a->type.sa.sa_family) { + switch (a->ss_family) { case AF_INET: + sin_a = (struct sockaddr_in *) a; + sin_b = (struct sockaddr_in *) b; if ((flags & ISC_SOCKADDR_CMPADDR) != 0 && - memcmp(&a->type.sin.sin_addr, &b->type.sin.sin_addr, - sizeof(a->type.sin.sin_addr)) != 0) + memcmp(&sin_a->sin_addr, &sin_b->sin_addr, + sizeof(sin_a->sin_addr)) != 0) return (0); if ((flags & ISC_SOCKADDR_CMPPORT) != 0 && - a->type.sin.sin_port != b->type.sin.sin_port) + sin_a->sin_port != sin_b->sin_port) return (0); break; case AF_INET6: + sin6_a = (struct sockaddr_in6 *) a; + sin6_b = (struct sockaddr_in6 *) b; + if ((flags & ISC_SOCKADDR_CMPADDR) != 0 && - memcmp(&a->type.sin6.sin6_addr, &b->type.sin6.sin6_addr, - sizeof(a->type.sin6.sin6_addr)) != 0) + memcmp(&sin6_a->sin6_addr, &sin6_b->sin6_addr, + sizeof(sin6_a->sin6_addr)) != 0) return (0); /* * If ISC_SOCKADDR_CMPSCOPEZERO is set then don't return * 0 if one of the scopes in zero. */ if ((flags & ISC_SOCKADDR_CMPSCOPE) != 0 && - a->type.sin6.sin6_scope_id != b->type.sin6.sin6_scope_id && + sin6_a->sin6_scope_id != sin6_b->sin6_scope_id && ((flags & ISC_SOCKADDR_CMPSCOPEZERO) == 0 || - (a->type.sin6.sin6_scope_id != 0 && - b->type.sin6.sin6_scope_id != 0))) + (sin6_a->sin6_scope_id != 0 && + sin6_b->sin6_scope_id != 0))) return (0); if ((flags & ISC_SOCKADDR_CMPPORT) != 0 && - a->type.sin6.sin6_port != b->type.sin6.sin6_port) + sin6_a->sin6_port != sin6_b->sin6_port) return (0); break; default: - if (memcmp(&a->type, &b->type, a->type.ss.ss_len) != 0) + if (memcmp(a, b, a->ss_len) != 0) return (0); } return (1); } isc_result_t -isc_sockaddr_totext(const isc_sockaddr_t *sockaddr, isc_buffer_t *target) { +isc_sockaddr_totext(const struct sockaddr_storage *sockaddr, isc_buffer_t *target) { + struct sockaddr_in *sin; + struct sockaddr_in6 *sin6; char pbuf[sizeof("65000")]; unsigned int plen; isc_region_t avail; @@ -108,12 +118,14 @@ isc_sockaddr_totext(const isc_sockaddr_t *sockaddr, isc_buffer_t *target) { * Do the port first, giving us the opportunity to check for * unsupported address families. */ - switch (sockaddr->type.sa.sa_family) { + switch (sockaddr->ss_family) { case AF_INET: - snprintf(pbuf, sizeof(pbuf), "%u", ntohs(sockaddr->type.sin.sin_port)); + sin = (struct sockaddr_in *)sockaddr; + snprintf(pbuf, sizeof(pbuf), "%u", ntohs(sin->sin_port)); break; case AF_INET6: - snprintf(pbuf, sizeof(pbuf), "%u", ntohs(sockaddr->type.sin6.sin6_port)); + sin6 = (struct sockaddr_in6 *)sockaddr; + snprintf(pbuf, sizeof(pbuf), "%u", ntohs(sin6->sin6_port)); break; default: return (ISC_R_FAILURE); @@ -122,8 +134,8 @@ isc_sockaddr_totext(const isc_sockaddr_t *sockaddr, isc_buffer_t *target) { plen = strlen(pbuf); INSIST(plen < sizeof(pbuf)); - error = getnameinfo(&sockaddr->type.sa, sockaddr->type.sa.sa_len, tmp, - sizeof(tmp), NULL, 0, NI_NUMERICHOST | NI_NUMERICSERV); + error = getnameinfo((struct sockaddr *)sockaddr, sockaddr->ss_len, + tmp, sizeof(tmp), NULL, 0, NI_NUMERICHOST | NI_NUMERICSERV); if (strlen(tmp) > isc_buffer_availablelength(target)) return (ISC_R_NOSPACE); isc_buffer_putmem(target, tmp, strlen(tmp)); @@ -145,7 +157,7 @@ isc_sockaddr_totext(const isc_sockaddr_t *sockaddr, isc_buffer_t *target) { } void -isc_sockaddr_format(const isc_sockaddr_t *sa, char *array, unsigned int size) { +isc_sockaddr_format(const struct sockaddr_storage *sa, char *array, unsigned int size) { isc_result_t result; isc_buffer_t buf; @@ -156,44 +168,47 @@ isc_sockaddr_format(const isc_sockaddr_t *sa, char *array, unsigned int size) { result = isc_sockaddr_totext(sa, &buf); if (result != ISC_R_SUCCESS) { snprintf(array, size, "<unknown address, family %u>", - sa->type.sa.sa_family); + sa->ss_family); array[size - 1] = '\0'; } } void -isc_sockaddr_any(isc_sockaddr_t *sockaddr) +isc_sockaddr_any(struct sockaddr_storage *sockaddr) { + struct sockaddr_in *sin = (struct sockaddr_in *) sockaddr; memset(sockaddr, 0, sizeof(*sockaddr)); - sockaddr->type.sin.sin_family = AF_INET; - sockaddr->type.sin.sin_len = sizeof(sockaddr->type.sin); - sockaddr->type.sin.sin_addr.s_addr = INADDR_ANY; - sockaddr->type.sin.sin_port = 0; + sin->sin_family = AF_INET; + sin->sin_len = sizeof(*sin); + sin->sin_addr.s_addr = INADDR_ANY; + sin->sin_port = 0; } void -isc_sockaddr_any6(isc_sockaddr_t *sockaddr) +isc_sockaddr_any6(struct sockaddr_storage *sockaddr) { + struct sockaddr_in6 *sin6 = (struct sockaddr_in6 *) sockaddr; memset(sockaddr, 0, sizeof(*sockaddr)); - sockaddr->type.sin6.sin6_family = AF_INET6; - sockaddr->type.sin6.sin6_len = sizeof(sockaddr->type.sin6); - sockaddr->type.sin6.sin6_addr = in6addr_any; - sockaddr->type.sin6.sin6_port = 0; + sin6->sin6_family = AF_INET6; + sin6->sin6_len = sizeof(*sin6); + sin6->sin6_addr = in6addr_any; + sin6->sin6_port = 0; } void -isc_sockaddr_fromin(isc_sockaddr_t *sockaddr, const struct in_addr *ina, +isc_sockaddr_fromin(struct sockaddr_storage *sockaddr, const struct in_addr *ina, in_port_t port) { + struct sockaddr_in *sin = (struct sockaddr_in *) sockaddr; memset(sockaddr, 0, sizeof(*sockaddr)); - sockaddr->type.sin.sin_family = AF_INET; - sockaddr->type.sin.sin_len = sizeof(sockaddr->type.sin); - sockaddr->type.sin.sin_addr = *ina; - sockaddr->type.sin.sin_port = htons(port); + sin->sin_family = AF_INET; + sin->sin_len = sizeof(*sin); + sin->sin_addr = *ina; + sin->sin_port = htons(port); } void -isc_sockaddr_anyofpf(isc_sockaddr_t *sockaddr, int pf) { +isc_sockaddr_anyofpf(struct sockaddr_storage *sockaddr, int pf) { switch (pf) { case AF_INET: isc_sockaddr_any(sockaddr); @@ -207,68 +222,81 @@ isc_sockaddr_anyofpf(isc_sockaddr_t *sockaddr, int pf) { } void -isc_sockaddr_fromin6(isc_sockaddr_t *sockaddr, const struct in6_addr *ina6, +isc_sockaddr_fromin6(struct sockaddr_storage *sockaddr, const struct in6_addr *ina6, in_port_t port) { + struct sockaddr_in6 *sin6 = (struct sockaddr_in6 *) sockaddr; memset(sockaddr, 0, sizeof(*sockaddr)); - sockaddr->type.sin6.sin6_family = AF_INET6; - sockaddr->type.sin6.sin6_len = sizeof(sockaddr->type.sin6); - sockaddr->type.sin6.sin6_addr = *ina6; - sockaddr->type.sin6.sin6_port = htons(port); + sin6->sin6_family = AF_INET6; + sin6->sin6_len = sizeof(*sin6); + sin6->sin6_addr = *ina6; + sin6->sin6_port = htons(port); } int -isc_sockaddr_pf(const isc_sockaddr_t *sockaddr) { +isc_sockaddr_pf(const struct sockaddr_storage *sockaddr) { /* * Get the protocol family of 'sockaddr'. */ - return (sockaddr->type.sa.sa_family); + return (sockaddr->ss_family); } in_port_t -isc_sockaddr_getport(const isc_sockaddr_t *sockaddr) { - in_port_t port = 0; +isc_sockaddr_getport(const struct sockaddr_storage *sockaddr) { + struct sockaddr_in *sin; + struct sockaddr_in6 *sin6; - switch (sockaddr->type.sa.sa_family) { + switch (sockaddr->ss_family) { case AF_INET: - port = ntohs(sockaddr->type.sin.sin_port); + sin = (struct sockaddr_in *)sockaddr; + return (ntohs(sin->sin_port)); break; case AF_INET6: - port = ntohs(sockaddr->type.sin6.sin6_port); + sin6 = (struct sockaddr_in6 *)sockaddr; + return (ntohs(sin6->sin6_port)); break; default: FATAL_ERROR(__FILE__, __LINE__, "unknown address family: %d", - (int)sockaddr->type.sa.sa_family); + (int)sockaddr->ss_family); } - - return (port); } int -isc_sockaddr_ismulticast(const isc_sockaddr_t *sockaddr) { - switch (sockaddr->type.sa.sa_family) { +isc_sockaddr_ismulticast(const struct sockaddr_storage *sockaddr) { + struct sockaddr_in *sin; + struct sockaddr_in6 *sin6; + + switch (sockaddr->ss_family) { case AF_INET: - return (IN_MULTICAST(&sockaddr->type.sin.sin_addr.s_addr)); + sin = (struct sockaddr_in *)sockaddr; + return (IN_MULTICAST(&sin->sin_addr.s_addr)); case AF_INET6: - return (IN6_IS_ADDR_MULTICAST(&sockaddr->type.sin6.sin6_addr)); + sin6 = (struct sockaddr_in6 *)sockaddr; + return (IN6_IS_ADDR_MULTICAST(&sin6->sin6_addr)); default: return (0); } } int -isc_sockaddr_issitelocal(const isc_sockaddr_t *sockaddr) { - if (sockaddr->type.sa.sa_family == AF_INET6) - return (IN6_IS_ADDR_SITELOCAL(&sockaddr->type.sin6.sin6_addr)); +isc_sockaddr_issitelocal(const struct sockaddr_storage *sockaddr) { + struct sockaddr_in6 *sin6; + if (sockaddr->ss_family == AF_INET6) { + sin6 = (struct sockaddr_in6 *)sockaddr; + return (IN6_IS_ADDR_SITELOCAL(&sin6->sin6_addr)); + } return (0); } int -isc_sockaddr_islinklocal(const isc_sockaddr_t *sockaddr) { - if (sockaddr->type.sa.sa_family == AF_INET6) - return (IN6_IS_ADDR_LINKLOCAL(&sockaddr->type.sin6.sin6_addr)); +isc_sockaddr_islinklocal(const struct sockaddr_storage *sockaddr) { + struct sockaddr_in6 *sin6; + if (sockaddr->ss_family == AF_INET6) { + sin6 = (struct sockaddr_in6 *)sockaddr; + return (IN6_IS_ADDR_LINKLOCAL(&sin6->sin6_addr)); + } return (0); } diff --git a/usr.bin/dig/lib/isc/unix/socket.c b/usr.bin/dig/lib/isc/unix/socket.c index 4e3a77d317f..4e6141b56a2 100644 --- a/usr.bin/dig/lib/isc/unix/socket.c +++ b/usr.bin/dig/lib/isc/unix/socket.c @@ -153,7 +153,7 @@ struct isc_socket { intev_t readable_ev; intev_t writable_ev; - isc_sockaddr_t peer_address; /* remote address */ + struct sockaddr_storage peer_address; /* remote address */ unsigned int pending_recv : 1, pending_send : 1, @@ -239,11 +239,11 @@ enum { }; static void -socket_log(isc_socket_t *sock, isc_sockaddr_t *address, +socket_log(isc_socket_t *sock, struct sockaddr_storage *address, isc_logcategory_t *category, isc_logmodule_t *module, int level, const char *fmt, ...) __attribute__((__format__(__printf__, 6, 7))); static void -socket_log(isc_socket_t *sock, isc_sockaddr_t *address, +socket_log(isc_socket_t *sock, struct sockaddr_storage *address, isc_logcategory_t *category, isc_logmodule_t *module, int level, const char *fmt, ...) { @@ -505,8 +505,8 @@ build_msghdr_send(isc_socket_t *sock, char* cmsgbuf, isc_socketevent_t *dev, memset(msg, 0, sizeof(*msg)); if (!sock->connected) { - msg->msg_name = (void *)&dev->address.type.sa; - msg->msg_namelen = dev->address.type.ss.ss_len; + msg->msg_name = (void *)&dev->address; + msg->msg_namelen = dev->address.ss_len; } else { msg->msg_name = NULL; msg->msg_namelen = 0; @@ -703,8 +703,8 @@ build_msghdr_recv(isc_socket_t *sock, char *cmsgbuf, isc_socketevent_t *dev, if (sock->type == isc_sockettype_udp) { memset(&dev->address, 0, sizeof(dev->address)); - msg->msg_name = (void *)&dev->address.type.sa; - msg->msg_namelen = sizeof(dev->address.type); + msg->msg_name = (void *)&dev->address; + msg->msg_namelen = sizeof(dev->address); } else { /* TCP */ msg->msg_name = NULL; msg->msg_namelen = 0; @@ -768,7 +768,7 @@ build_msghdr_recv(isc_socket_t *sock, char *cmsgbuf, isc_socketevent_t *dev, } static void -set_dev_address(isc_sockaddr_t *address, isc_socket_t *sock, +set_dev_address(struct sockaddr_storage *address, isc_socket_t *sock, isc_socketevent_t *dev) { if (sock->type == isc_sockettype_udp) { @@ -910,7 +910,7 @@ doio_recv(isc_socket_t *sock, isc_socketevent_t *dev) { } if (sock->type == isc_sockettype_udp) { - dev->address.type.ss.ss_len = msghdr.msg_namelen; + dev->address.ss_len = msghdr.msg_namelen; if (isc_sockaddr_getport(&dev->address) == 0) { if (isc_log_wouldlog(isc_lctx, IOEVENT_LEVEL)) { socket_log(sock, &dev->address, IOEVENT, @@ -2042,7 +2042,7 @@ isc_socket_recvv(isc_socket_t *sock0, isc_bufferlist_t *buflist, static isc_result_t socket_send(isc_socket_t *sock, isc_socketevent_t *dev, isc_task_t *task, - isc_sockaddr_t *address, struct in6_pktinfo *pktinfo, + struct sockaddr_storage *address, struct in6_pktinfo *pktinfo, unsigned int flags) { int io_state; @@ -2132,7 +2132,7 @@ isc_socket_sendv(isc_socket_t *sock, isc_bufferlist_t *buflist, isc_result_t isc_socket_sendtov2(isc_socket_t *sock0, isc_bufferlist_t *buflist, isc_task_t *task, isc_taskaction_t action, void *arg, - isc_sockaddr_t *address, struct in6_pktinfo *pktinfo, + struct sockaddr_storage *address, struct in6_pktinfo *pktinfo, unsigned int flags) { isc_socket_t *sock = (isc_socket_t *)sock0; @@ -2167,14 +2167,14 @@ isc_socket_sendtov2(isc_socket_t *sock0, isc_bufferlist_t *buflist, } isc_result_t -isc_socket_bind(isc_socket_t *sock0, isc_sockaddr_t *sockaddr, +isc_socket_bind(isc_socket_t *sock0, struct sockaddr_storage *sockaddr, unsigned int options) { isc_socket_t *sock = (isc_socket_t *)sock0; int on = 1; INSIST(!sock->bound); - if (sock->pf != sockaddr->type.sa.sa_family) { + if (sock->pf != sockaddr->ss_family) { return (ISC_R_FAMILYMISMATCH); } @@ -2189,7 +2189,7 @@ isc_socket_bind(isc_socket_t *sock0, isc_sockaddr_t *sockaddr, "setsockopt(%d) %s", sock->fd, "failed"); /* Press on... */ } - if (bind(sock->fd, &sockaddr->type.sa, sockaddr->type.sa.sa_len) < 0) { + if (bind(sock->fd, (struct sockaddr *)sockaddr, sockaddr->ss_len) < 0) { switch (errno) { case EACCES: return (ISC_R_NOPERM); @@ -2213,7 +2213,7 @@ isc_socket_bind(isc_socket_t *sock0, isc_sockaddr_t *sockaddr, } isc_result_t -isc_socket_connect(isc_socket_t *sock0, isc_sockaddr_t *addr, +isc_socket_connect(isc_socket_t *sock0, struct sockaddr_storage *addr, isc_task_t *task, isc_taskaction_t action, void *arg) { isc_socket_t *sock = (isc_socket_t *)sock0; @@ -2249,7 +2249,7 @@ isc_socket_connect(isc_socket_t *sock0, isc_sockaddr_t *addr, * outstanding, and it might happen to complete. */ sock->peer_address = *addr; - cc = connect(sock->fd, &addr->type.sa, addr->type.sa.sa_len); + cc = connect(sock->fd, (struct sockaddr *)addr, addr->ss_len); if (cc < 0) { /* * HP-UX "fails" to connect a UDP socket and sets errno to diff --git a/usr.bin/dig/nslookup.c b/usr.bin/dig/nslookup.c index b4b6943dcf2..131be105f43 100644 --- a/usr.bin/dig/nslookup.c +++ b/usr.bin/dig/nslookup.c @@ -369,7 +369,7 @@ detailsection(dig_query_t *query, dns_message_t *msg, int headers, } static void -received(unsigned int bytes, isc_sockaddr_t *from, dig_query_t *query) +received(unsigned int bytes, struct sockaddr_storage *from, dig_query_t *query) { UNUSED(bytes); UNUSED(from); @@ -442,7 +442,7 @@ printmessage(dig_query_t *query, dns_message_t *msg, int headers) { static void show_settings(int full, int serv_only) { dig_server_t *srv; - isc_sockaddr_t sockaddr; + struct sockaddr_storage sockaddr; dig_searchlist_t *listent; isc_result_t result; |