]>
The Tcpdump Group git mirrors - tcpdump/blob - missing/getaddrinfo.c
2 * Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project.
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
13 * 3. Neither the name of the project nor the names of its contributors
14 * may be used to endorse or promote products derived from this software
15 * without specific prior written permission.
17 * THIS SOFTWARE IS PROVIDED BY THE PROJECT AND CONTRIBUTORS ``AS IS'' AND
18 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20 * ARE DISCLAIMED. IN NO EVENT SHALL THE PROJECT OR CONTRIBUTORS BE LIABLE
21 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
23 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
24 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
26 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
31 * "#ifdef FAITH" part is local hack for supporting IPv4-v6 translator.
33 * Issues to be discussed:
34 * - Thread safe-ness must be checked.
35 * - Return values. There are nonstandard return values defined and used
36 * in the source code. This is because RFC2553 is silent about which error
37 * code must be returned for which situation.
38 * - PF_UNSPEC case would be handled in getipnodebyname() with the AI_ALL flag.
45 #include <sys/types.h>
46 #include <sys/param.h>
48 #include <sys/sysctl.h>
50 #include <sys/socket.h>
52 #include <netinet/in.h>
53 #include <arpa/inet.h>
54 #include <arpa/nameser.h>
65 #ifndef HAVE_PORTABLE_PROTOTYPE
66 #include "cdecl_ext.h"
70 #ifndef HAVE_U_INT32_T
75 #ifndef HAVE_SOCKADDR_STORAGE
76 #include "sockstorage.h"
81 #if defined(__KAME__) && defined(INET6)
91 static int translate
= NO
;
92 static struct in6_addr faith_prefix
= IN6ADDR_ANY_INIT
;
95 static const char in_addrany
[] = { 0, 0, 0, 0 };
96 static const char in6_addrany
[] = {
97 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
99 static const char in_loopback
[] = { 127, 0, 0, 1 };
100 static const char in6_loopback
[] = {
101 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1
108 u_int32_t si_scope_id
;
111 static const struct afd
{
116 const char *a_addrany
;
117 const char *a_loopback
;
121 {PF_INET6
, sizeof(struct in6_addr
),
122 sizeof(struct sockaddr_in6
),
123 offsetof(struct sockaddr_in6
, sin6_addr
),
124 in6_addrany
, in6_loopback
, 1},
126 {PF_INET
, sizeof(struct in_addr
),
127 sizeof(struct sockaddr_in
),
128 offsetof(struct sockaddr_in
, sin_addr
),
129 in_addrany
, in_loopback
, 0},
130 {0, 0, 0, 0, NULL
, NULL
, 0},
137 const char *e_protostr
;
139 #define WILD_AF(ex) ((ex)->e_wild & 0x01)
140 #define WILD_SOCKTYPE(ex) ((ex)->e_wild & 0x02)
141 #define WILD_PROTOCOL(ex) ((ex)->e_wild & 0x04)
144 static const struct explore explore
[] = {
146 { PF_LOCAL
, 0, ANY
, ANY
, NULL
, 0x01 },
149 { PF_INET6
, SOCK_DGRAM
, IPPROTO_UDP
, "udp", 0x07 },
150 { PF_INET6
, SOCK_STREAM
, IPPROTO_TCP
, "tcp", 0x07 },
151 { PF_INET6
, SOCK_RAW
, ANY
, NULL
, 0x05 },
153 { PF_INET
, SOCK_DGRAM
, IPPROTO_UDP
, "udp", 0x07 },
154 { PF_INET
, SOCK_STREAM
, IPPROTO_TCP
, "tcp", 0x07 },
155 { PF_INET
, SOCK_RAW
, ANY
, NULL
, 0x05 },
156 { -1, 0, 0, NULL
, 0 },
166 static int str_isnumber
__P((const char *));
167 static int explore_fqdn
__P((const struct addrinfo
*, const char *,
168 const char *, struct addrinfo
**));
169 static int explore_null
__P((const struct addrinfo
*, const char *,
170 const char *, struct addrinfo
**));
171 static int explore_numeric
__P((const struct addrinfo
*, const char *,
172 const char *, struct addrinfo
**));
173 static int explore_numeric_scope
__P((const struct addrinfo
*, const char *,
174 const char *, struct addrinfo
**));
175 static int get_name
__P((const char *, const struct afd
*, struct addrinfo
**,
176 char *, const struct addrinfo
*, const char *));
177 static int get_canonname
__P((const struct addrinfo
*,
178 struct addrinfo
*, const char *));
179 static struct addrinfo
*get_ai
__P((const struct addrinfo
*,
180 const struct afd
*, const char *));
181 static int get_portmatch
__P((const struct addrinfo
*, const char *));
182 static int get_port
__P((struct addrinfo
*, const char *, int));
183 static const struct afd
*find_afd
__P((int));
185 static char *ai_errlist
[] = {
187 "Address family for hostname not supported", /* EAI_ADDRFAMILY */
188 "Temporary failure in name resolution", /* EAI_AGAIN */
189 "Invalid value for ai_flags", /* EAI_BADFLAGS */
190 "Non-recoverable failure in name resolution", /* EAI_FAIL */
191 "ai_family not supported", /* EAI_FAMILY */
192 "Memory allocation failure", /* EAI_MEMORY */
193 "No address associated with hostname", /* EAI_NODATA */
194 "hostname nor servname provided, or not known", /* EAI_NONAME */
195 "servname not supported for ai_socktype", /* EAI_SERVICE */
196 "ai_socktype not supported", /* EAI_SOCKTYPE */
197 "System error returned in errno", /* EAI_SYSTEM */
198 "Invalid value for hints", /* EAI_BADHINTS */
199 "Resolved protocol is unknown", /* EAI_PROTOCOL */
200 "Unknown error", /* EAI_MAX */
203 /* XXX macros that make external reference is BAD. */
205 #define GET_AI(ai, afd, addr) \
207 /* external reference: pai, error, and label free */ \
208 (ai) = get_ai(pai, (afd), (addr)); \
209 if ((ai) == NULL) { \
210 error = EAI_MEMORY; \
215 #define GET_PORT(ai, serv) \
217 /* external reference: error and label free */ \
218 error = get_port((ai), (serv), 0); \
223 #define GET_CANONNAME(ai, str) \
225 /* external reference: pai, error and label free */ \
226 error = get_canonname(pai, (ai), (str)); \
233 /* external reference: error, and label bad */ \
238 #define MATCH_FAMILY(x, y, w) \
239 ((x) == (y) || ((w) && ((x) == PF_UNSPEC || (y) == PF_UNSPEC)))
240 #define MATCH(x, y, w) \
241 ((x) == (y) || ((w) && ((x) == ANY || (y) == ANY)))
247 if (ecode
< 0 || ecode
> EAI_MAX
)
249 return ai_errlist
[ecode
];
256 struct addrinfo
*next
;
260 if (ai
->ai_canonname
)
261 free(ai
->ai_canonname
);
262 /* no need to free(ai->ai_addr) */
264 } while ((ai
= next
) != NULL
);
281 getaddrinfo(hostname
, servname
, hints
, res
)
282 const char *hostname
, *servname
;
283 const struct addrinfo
*hints
;
284 struct addrinfo
**res
;
286 struct addrinfo sentinel
;
287 struct addrinfo
*cur
;
291 struct addrinfo
*pai
;
292 const struct afd
*afd
;
293 const struct explore
*ex
;
296 static int firsttime
= 1;
299 /* translator hack */
300 char *q
= getenv("GAI");
301 if (q
&& inet_pton(AF_INET6
, q
, &faith_prefix
) == 1)
307 sentinel
.ai_next
= NULL
;
311 pai
->ai_family
= PF_UNSPEC
;
312 pai
->ai_socktype
= ANY
;
313 pai
->ai_protocol
= ANY
;
315 pai
->ai_canonname
= NULL
;
319 if (hostname
== NULL
&& servname
== NULL
)
322 /* error check for hints */
323 if (hints
->ai_addrlen
|| hints
->ai_canonname
||
324 hints
->ai_addr
|| hints
->ai_next
)
325 ERR(EAI_BADHINTS
); /* xxx */
326 if (hints
->ai_flags
& ~AI_MASK
)
328 switch (hints
->ai_family
) {
338 memcpy(pai
, hints
, sizeof(*pai
));
341 * if both socktype/protocol are specified, check if they
342 * are meaningful combination.
344 if (pai
->ai_socktype
!= ANY
&& pai
->ai_protocol
!= ANY
) {
345 for (ex
= explore
; ex
->e_af
>= 0; ex
++) {
346 if (pai
->ai_family
!= ex
->e_af
)
348 if (ex
->e_socktype
== ANY
)
350 if (ex
->e_protocol
== ANY
)
352 if (pai
->ai_socktype
== ex
->e_socktype
353 && pai
->ai_protocol
!= ex
->e_protocol
) {
361 * check for special cases. (1) numeric servname is disallowed if
362 * socktype/protocol are left unspecified. (2) servname is disallowed
363 * for raw and other inet{,6} sockets.
365 if (MATCH_FAMILY(pai
->ai_family
, PF_INET
, 1)
367 || MATCH_FAMILY(pai
->ai_family
, PF_INET6
, 1)
372 if (pai
->ai_family
== PF_UNSPEC
)
374 pai
->ai_family
= PF_INET6
;
376 pai
->ai_family
= PF_INET
;
378 error
= get_portmatch(pai
, servname
);
387 /* NULL hostname, or numeric hostname */
388 for (ex
= explore
; ex
->e_af
>= 0; ex
++) {
391 if (!MATCH_FAMILY(pai
->ai_family
, ex
->e_af
, WILD_AF(ex
)))
393 if (!MATCH(pai
->ai_socktype
, ex
->e_socktype
, WILD_SOCKTYPE(ex
)))
395 if (!MATCH(pai
->ai_protocol
, ex
->e_protocol
, WILD_PROTOCOL(ex
)))
398 if (pai
->ai_family
== PF_UNSPEC
)
399 pai
->ai_family
= ex
->e_af
;
400 if (pai
->ai_socktype
== ANY
&& ex
->e_socktype
!= ANY
)
401 pai
->ai_socktype
= ex
->e_socktype
;
402 if (pai
->ai_protocol
== ANY
&& ex
->e_protocol
!= ANY
)
403 pai
->ai_protocol
= ex
->e_protocol
;
405 if (hostname
== NULL
)
406 error
= explore_null(pai
, hostname
, servname
, &cur
->ai_next
);
408 error
= explore_numeric_scope(pai
, hostname
, servname
, &cur
->ai_next
);
413 while (cur
&& cur
->ai_next
)
419 * If numreic representation of AF1 can be interpreted as FQDN
420 * representation of AF2, we need to think again about the code below.
422 if (sentinel
.ai_next
)
425 if (pai
->ai_flags
& AI_NUMERICHOST
)
427 if (hostname
== NULL
)
431 * hostname as alphabetical name.
432 * we would like to prefer AF_INET6 than AF_INET, so we'll make a
435 for (afd
= afdl
; afd
->a_af
; afd
++) {
438 if (!MATCH_FAMILY(pai
->ai_family
, afd
->a_af
, 1))
441 for (ex
= explore
; ex
->e_af
>= 0; ex
++) {
444 if (pai
->ai_family
== PF_UNSPEC
)
445 pai
->ai_family
= afd
->a_af
;
447 if (!MATCH_FAMILY(pai
->ai_family
, ex
->e_af
, WILD_AF(ex
)))
449 if (!MATCH(pai
->ai_socktype
, ex
->e_socktype
,
450 WILD_SOCKTYPE(ex
))) {
453 if (!MATCH(pai
->ai_protocol
, ex
->e_protocol
,
454 WILD_PROTOCOL(ex
))) {
458 if (pai
->ai_family
== PF_UNSPEC
)
459 pai
->ai_family
= ex
->e_af
;
460 if (pai
->ai_socktype
== ANY
&& ex
->e_socktype
!= ANY
)
461 pai
->ai_socktype
= ex
->e_socktype
;
462 if (pai
->ai_protocol
== ANY
&& ex
->e_protocol
!= ANY
)
463 pai
->ai_protocol
= ex
->e_protocol
;
465 error
= explore_fqdn(pai
, hostname
, servname
,
468 while (cur
&& cur
->ai_next
)
474 if (sentinel
.ai_next
)
480 if (sentinel
.ai_next
) {
482 *res
= sentinel
.ai_next
;
489 if (sentinel
.ai_next
)
490 freeaddrinfo(sentinel
.ai_next
);
496 * FQDN hostname, DNS lookup
499 explore_fqdn(pai
, hostname
, servname
, res
)
500 const struct addrinfo
*pai
;
501 const char *hostname
;
502 const char *servname
;
503 struct addrinfo
**res
;
510 struct addrinfo sentinel
, *cur
;
512 const struct afd
*afd
;
516 sentinel
.ai_next
= NULL
;
520 * filter out AFs that are not supported by the kernel
523 s
= socket(pai
->ai_family
, SOCK_DGRAM
, 0);
529 * if the servname does not match socktype/protocol, ignore it.
531 if (get_portmatch(pai
, servname
) != 0)
534 afd
= find_afd(pai
->ai_family
);
536 #ifdef USE_GETIPNODEBY
537 hp
= getipnodebyname(hostname
, pai
->ai_family
, AI_ADDRCONFIG
, &h_error
);
538 #elif defined(HAVE_GETHOSTBYNAME2)
539 hp
= gethostbyname2(hostname
, pai
->ai_family
);
546 if (pai
->ai_family
!= AF_INET
)
548 hp
= gethostbyname(hostname
);
571 } else if ((hp
->h_name
== NULL
) || (hp
->h_name
[0] == 0)
572 || (hp
->h_addr_list
[0] == NULL
)) {
573 #ifdef USE_GETIPNODEBY
583 for (i
= 0; hp
->h_addr_list
[i
] != NULL
; i
++) {
585 ap
= hp
->h_addr_list
[i
];
588 && IN6_IS_ADDR_V4MAPPED((struct in6_addr
*)ap
)) {
590 ap
= ap
+ sizeof(struct in6_addr
)
591 - sizeof(struct in_addr
);
595 if (af
!= pai
->ai_family
)
598 if ((pai
->ai_flags
& AI_CANONNAME
) == 0) {
599 GET_AI(cur
->ai_next
, afd
, ap
);
600 GET_PORT(cur
->ai_next
, servname
);
603 * if AI_CANONNAME and if reverse lookup
604 * fail, return ai anyway to pacify
605 * calling application.
607 * XXX getaddrinfo() is a name->address
608 * translation function, and it looks
609 * strange that we do addr->name
612 get_name(ap
, afd
, &cur
->ai_next
,
616 while (cur
&& cur
->ai_next
)
620 *res
= sentinel
.ai_next
;
624 #ifdef USE_GETIPNODEBY
628 if (sentinel
.ai_next
)
629 freeaddrinfo(sentinel
.ai_next
);
635 * passive socket -> anyaddr (0.0.0.0 or ::)
636 * non-passive socket -> localhost (127.0.0.1 or ::1)
639 explore_null(pai
, hostname
, servname
, res
)
640 const struct addrinfo
*pai
;
641 const char *hostname
;
642 const char *servname
;
643 struct addrinfo
**res
;
646 const struct afd
*afd
;
647 struct addrinfo
*cur
;
648 struct addrinfo sentinel
;
652 sentinel
.ai_next
= NULL
;
656 * filter out AFs that are not supported by the kernel
659 s
= socket(pai
->ai_family
, SOCK_DGRAM
, 0);
665 * if the servname does not match socktype/protocol, ignore it.
667 if (get_portmatch(pai
, servname
) != 0)
670 afd
= find_afd(pai
->ai_family
);
672 if (pai
->ai_flags
& AI_PASSIVE
) {
673 GET_AI(cur
->ai_next
, afd
, afd
->a_addrany
);
675 * GET_CANONNAME(cur->ai_next, "anyaddr");
677 GET_PORT(cur
->ai_next
, servname
);
679 GET_AI(cur
->ai_next
, afd
, afd
->a_loopback
);
681 * GET_CANONNAME(cur->ai_next, "localhost");
683 GET_PORT(cur
->ai_next
, servname
);
687 *res
= sentinel
.ai_next
;
691 if (sentinel
.ai_next
)
692 freeaddrinfo(sentinel
.ai_next
);
700 explore_numeric(pai
, hostname
, servname
, res
)
701 const struct addrinfo
*pai
;
702 const char *hostname
;
703 const char *servname
;
704 struct addrinfo
**res
;
706 const struct afd
*afd
;
707 struct addrinfo
*cur
;
708 struct addrinfo sentinel
;
714 sentinel
.ai_next
= NULL
;
718 * if the servname does not match socktype/protocol, ignore it.
720 if (get_portmatch(pai
, servname
) != 0)
723 afd
= find_afd(pai
->ai_family
);
724 flags
= pai
->ai_flags
;
726 if (inet_pton(afd
->a_af
, hostname
, pton
) == 1) {
734 v4a
= (u_int32_t
)ntohl(((struct in_addr
*)pton
)->s_addr
);
735 if (IN_MULTICAST(v4a
) || IN_EXPERIMENTAL(v4a
))
736 flags
&= ~AI_CANONNAME
;
737 v4a
>>= IN_CLASSA_NSHIFT
;
738 if (v4a
== 0 || v4a
== IN_LOOPBACKNET
)
739 flags
&= ~AI_CANONNAME
;
743 pfx
= ((struct in6_addr
*)pton
)->s6_addr
[0];
744 if (pfx
== 0 || pfx
== 0xfe || pfx
== 0xff)
745 flags
&= ~AI_CANONNAME
;
750 if (pai
->ai_family
== afd
->a_af
||
751 pai
->ai_family
== PF_UNSPEC
/*?*/) {
752 if ((flags
& AI_CANONNAME
) == 0) {
753 GET_AI(cur
->ai_next
, afd
, pton
);
754 GET_PORT(cur
->ai_next
, servname
);
757 * if AI_CANONNAME and if reverse lookup
758 * fail, return ai anyway to pacify
759 * calling application.
761 * XXX getaddrinfo() is a name->address
762 * translation function, and it looks
763 * strange that we do addr->name
766 get_name(pton
, afd
, &cur
->ai_next
,
767 pton
, pai
, servname
);
769 while (cur
&& cur
->ai_next
)
772 ERR(EAI_FAMILY
); /*xxx*/
775 *res
= sentinel
.ai_next
;
780 if (sentinel
.ai_next
)
781 freeaddrinfo(sentinel
.ai_next
);
786 * numeric hostname with scope
789 explore_numeric_scope(pai
, hostname
, servname
, res
)
790 const struct addrinfo
*pai
;
791 const char *hostname
;
792 const char *servname
;
793 struct addrinfo
**res
;
795 #ifndef SCOPE_DELIMITER
796 return explore_numeric(pai
, hostname
, servname
, res
);
798 const struct afd
*afd
;
799 struct addrinfo
*cur
;
801 char *cp
, *hostname2
= NULL
;
803 struct sockaddr_in6
*sin6
;
806 * if the servname does not match socktype/protocol, ignore it.
808 if (get_portmatch(pai
, servname
) != 0)
811 afd
= find_afd(pai
->ai_family
);
813 return explore_numeric(pai
, hostname
, servname
, res
);
815 cp
= strchr(hostname
, SCOPE_DELIMITER
);
817 return explore_numeric(pai
, hostname
, servname
, res
);
820 * Handle special case of <scoped_address><delimiter><scope id>
822 hostname2
= strdup(hostname
);
823 if (hostname2
== NULL
)
825 /* terminate at the delimiter */
826 hostname2
[cp
- hostname
] = '\0';
829 switch (pai
->ai_family
) {
832 scope
= if_nametoindex(cp
);
837 error
= explore_numeric(pai
, hostname2
, servname
, res
);
839 for (cur
= *res
; cur
; cur
= cur
->ai_next
) {
840 if (cur
->ai_family
!= AF_INET6
)
842 sin6
= (struct sockaddr_in6
*)cur
->ai_addr
;
843 if (IN6_IS_ADDR_LINKLOCAL(&sin6
->sin6_addr
) ||
844 IN6_IS_ADDR_MC_LINKLOCAL(&sin6
->sin6_addr
))
845 sin6
->sin6_scope_id
= scope
;
856 get_name(addr
, afd
, res
, numaddr
, pai
, servname
)
858 const struct afd
*afd
;
859 struct addrinfo
**res
;
861 const struct addrinfo
*pai
;
862 const char *servname
;
865 struct addrinfo
*cur
;
867 #ifdef USE_GETIPNODEBY
870 hp
= getipnodebyaddr(addr
, afd
->a_addrlen
, afd
->a_af
, &h_error
);
872 hp
= gethostbyaddr(addr
, afd
->a_addrlen
, afd
->a_af
);
874 if (hp
&& hp
->h_name
&& hp
->h_name
[0] && hp
->h_addr_list
[0]) {
875 GET_AI(cur
, afd
, hp
->h_addr_list
[0]);
876 GET_PORT(cur
, servname
);
877 GET_CANONNAME(cur
, hp
->h_name
);
879 GET_AI(cur
, afd
, numaddr
);
880 GET_PORT(cur
, servname
);
883 #ifdef USE_GETIPNODEBY
892 #ifdef USE_GETIPNODEBY
902 get_canonname(pai
, ai
, str
)
903 const struct addrinfo
*pai
;
907 if ((pai
->ai_flags
& AI_CANONNAME
) != 0) {
908 ai
->ai_canonname
= (char *)malloc(strlen(str
) + 1);
909 if (ai
->ai_canonname
== NULL
)
911 strcpy(ai
->ai_canonname
, str
);
916 static struct addrinfo
*
917 get_ai(pai
, afd
, addr
)
918 const struct addrinfo
*pai
;
919 const struct afd
*afd
;
925 ai
= (struct addrinfo
*)malloc(sizeof(struct addrinfo
)
930 memcpy(ai
, pai
, sizeof(struct addrinfo
));
931 ai
->ai_addr
= (struct sockaddr
*)(ai
+ 1);
932 memset(ai
->ai_addr
, 0, afd
->a_socklen
);
933 #ifdef HAVE_SOCKADDR_SA_LEN
934 ai
->ai_addr
->sa_len
= afd
->a_socklen
;
936 ai
->ai_addrlen
= afd
->a_socklen
;
937 ai
->ai_addr
->sa_family
= ai
->ai_family
= afd
->a_af
;
938 p
= (char *)(ai
->ai_addr
);
939 memcpy(p
+ afd
->a_off
, addr
, afd
->a_addrlen
);
944 get_portmatch(ai
, servname
)
945 const struct addrinfo
*ai
;
946 const char *servname
;
948 /* get_port does not touch first argument. when matchonly == 1. */
949 return get_port((struct addrinfo
*)ai
, servname
, 1);
953 get_port(ai
, servname
, matchonly
)
955 const char *servname
;
963 if (servname
== NULL
)
965 if (ai
->ai_family
!= AF_INET
967 && ai
->ai_family
!= AF_INET6
972 switch (ai
->ai_socktype
) {
986 if (str_isnumber(servname
)) {
989 port
= htons(atoi(servname
));
990 if (port
< 0 || port
> 65535)
993 switch (ai
->ai_socktype
) {
1005 if ((sp
= getservbyname(servname
, proto
)) == NULL
)
1011 switch (ai
->ai_family
) {
1013 ((struct sockaddr_in
*)ai
->ai_addr
)->sin_port
= port
;
1017 ((struct sockaddr_in6
*)ai
->ai_addr
)->sin6_port
= port
;
1026 static const struct afd
*
1030 const struct afd
*afd
;
1032 if (af
== PF_UNSPEC
)
1034 for (afd
= afdl
; afd
->a_af
; afd
++) {
1035 if (afd
->a_af
== af
)