]>
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"
83 #if defined(__KAME__) && defined(INET6)
93 static int translate
= NO
;
94 static struct in6_addr faith_prefix
= IN6ADDR_ANY_INIT
;
97 static const char in_addrany
[] = { 0, 0, 0, 0 };
98 static const char in6_addrany
[] = {
99 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
101 static const char in_loopback
[] = { 127, 0, 0, 1 };
102 static const char in6_loopback
[] = {
103 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1
110 u_int32_t si_scope_id
;
113 static const struct afd
{
118 const char *a_addrany
;
119 const char *a_loopback
;
123 {PF_INET6
, sizeof(struct in6_addr
),
124 sizeof(struct sockaddr_in6
),
125 offsetof(struct sockaddr_in6
, sin6_addr
),
126 in6_addrany
, in6_loopback
, 1},
128 {PF_INET
, sizeof(struct in_addr
),
129 sizeof(struct sockaddr_in
),
130 offsetof(struct sockaddr_in
, sin_addr
),
131 in_addrany
, in_loopback
, 0},
132 {0, 0, 0, 0, NULL
, NULL
, 0},
139 const char *e_protostr
;
141 #define WILD_AF(ex) ((ex)->e_wild & 0x01)
142 #define WILD_SOCKTYPE(ex) ((ex)->e_wild & 0x02)
143 #define WILD_PROTOCOL(ex) ((ex)->e_wild & 0x04)
146 static const struct explore explore
[] = {
148 { PF_LOCAL
, 0, ANY
, ANY
, NULL
, 0x01 },
151 { PF_INET6
, SOCK_DGRAM
, IPPROTO_UDP
, "udp", 0x07 },
152 { PF_INET6
, SOCK_STREAM
, IPPROTO_TCP
, "tcp", 0x07 },
153 { PF_INET6
, SOCK_RAW
, ANY
, NULL
, 0x05 },
155 { PF_INET
, SOCK_DGRAM
, IPPROTO_UDP
, "udp", 0x07 },
156 { PF_INET
, SOCK_STREAM
, IPPROTO_TCP
, "tcp", 0x07 },
157 { PF_INET
, SOCK_RAW
, ANY
, NULL
, 0x05 },
158 { -1, 0, 0, NULL
, 0 },
168 static int str_isnumber
__P((const char *));
169 static int explore_fqdn
__P((const struct addrinfo
*, const char *,
170 const char *, struct addrinfo
**));
171 static int explore_null
__P((const struct addrinfo
*, const char *,
172 const char *, struct addrinfo
**));
173 static int explore_numeric
__P((const struct addrinfo
*, const char *,
174 const char *, struct addrinfo
**));
175 static int explore_numeric_scope
__P((const struct addrinfo
*, const char *,
176 const char *, struct addrinfo
**));
177 static int get_name
__P((const char *, const struct afd
*, struct addrinfo
**,
178 char *, const struct addrinfo
*, const char *));
179 static int get_canonname
__P((const struct addrinfo
*,
180 struct addrinfo
*, const char *));
181 static struct addrinfo
*get_ai
__P((const struct addrinfo
*,
182 const struct afd
*, const char *));
183 static int get_portmatch
__P((const struct addrinfo
*, const char *));
184 static int get_port
__P((struct addrinfo
*, const char *, int));
185 static const struct afd
*find_afd
__P((int));
187 static char *ai_errlist
[] = {
189 "Address family for hostname not supported", /* EAI_ADDRFAMILY */
190 "Temporary failure in name resolution", /* EAI_AGAIN */
191 "Invalid value for ai_flags", /* EAI_BADFLAGS */
192 "Non-recoverable failure in name resolution", /* EAI_FAIL */
193 "ai_family not supported", /* EAI_FAMILY */
194 "Memory allocation failure", /* EAI_MEMORY */
195 "No address associated with hostname", /* EAI_NODATA */
196 "hostname nor servname provided, or not known", /* EAI_NONAME */
197 "servname not supported for ai_socktype", /* EAI_SERVICE */
198 "ai_socktype not supported", /* EAI_SOCKTYPE */
199 "System error returned in errno", /* EAI_SYSTEM */
200 "Invalid value for hints", /* EAI_BADHINTS */
201 "Resolved protocol is unknown", /* EAI_PROTOCOL */
202 "Unknown error", /* EAI_MAX */
205 /* XXX macros that make external reference is BAD. */
207 #define GET_AI(ai, afd, addr) \
209 /* external reference: pai, error, and label free */ \
210 (ai) = get_ai(pai, (afd), (addr)); \
211 if ((ai) == NULL) { \
212 error = EAI_MEMORY; \
217 #define GET_PORT(ai, serv) \
219 /* external reference: error and label free */ \
220 error = get_port((ai), (serv), 0); \
225 #define GET_CANONNAME(ai, str) \
227 /* external reference: pai, error and label free */ \
228 error = get_canonname(pai, (ai), (str)); \
235 /* external reference: error, and label bad */ \
240 #define MATCH_FAMILY(x, y, w) \
241 ((x) == (y) || ((w) && ((x) == PF_UNSPEC || (y) == PF_UNSPEC)))
242 #define MATCH(x, y, w) \
243 ((x) == (y) || ((w) && ((x) == ANY || (y) == ANY)))
249 if (ecode
< 0 || ecode
> EAI_MAX
)
251 return ai_errlist
[ecode
];
258 struct addrinfo
*next
;
262 if (ai
->ai_canonname
)
263 free(ai
->ai_canonname
);
264 /* no need to free(ai->ai_addr) */
266 } while ((ai
= next
) != NULL
);
283 getaddrinfo(hostname
, servname
, hints
, res
)
284 const char *hostname
, *servname
;
285 const struct addrinfo
*hints
;
286 struct addrinfo
**res
;
288 struct addrinfo sentinel
;
289 struct addrinfo
*cur
;
293 struct addrinfo
*pai
;
294 const struct afd
*afd
;
295 const struct explore
*ex
;
298 static int firsttime
= 1;
301 /* translator hack */
302 char *q
= getenv("GAI");
303 if (q
&& inet_pton(AF_INET6
, q
, &faith_prefix
) == 1)
309 sentinel
.ai_next
= NULL
;
313 pai
->ai_family
= PF_UNSPEC
;
314 pai
->ai_socktype
= ANY
;
315 pai
->ai_protocol
= ANY
;
317 pai
->ai_canonname
= NULL
;
321 if (hostname
== NULL
&& servname
== NULL
)
324 /* error check for hints */
325 if (hints
->ai_addrlen
|| hints
->ai_canonname
||
326 hints
->ai_addr
|| hints
->ai_next
)
327 ERR(EAI_BADHINTS
); /* xxx */
328 if (hints
->ai_flags
& ~AI_MASK
)
330 switch (hints
->ai_family
) {
340 memcpy(pai
, hints
, sizeof(*pai
));
343 * if both socktype/protocol are specified, check if they
344 * are meaningful combination.
346 if (pai
->ai_socktype
!= ANY
&& pai
->ai_protocol
!= ANY
) {
347 for (ex
= explore
; ex
->e_af
>= 0; ex
++) {
348 if (pai
->ai_family
!= ex
->e_af
)
350 if (ex
->e_socktype
== ANY
)
352 if (ex
->e_protocol
== ANY
)
354 if (pai
->ai_socktype
== ex
->e_socktype
355 && pai
->ai_protocol
!= ex
->e_protocol
) {
363 * check for special cases. (1) numeric servname is disallowed if
364 * socktype/protocol are left unspecified. (2) servname is disallowed
365 * for raw and other inet{,6} sockets.
367 if (MATCH_FAMILY(pai
->ai_family
, PF_INET
, 1)
369 || MATCH_FAMILY(pai
->ai_family
, PF_INET6
, 1)
374 if (pai
->ai_family
== PF_UNSPEC
)
376 pai
->ai_family
= PF_INET6
;
378 pai
->ai_family
= PF_INET
;
380 error
= get_portmatch(pai
, servname
);
389 /* NULL hostname, or numeric hostname */
390 for (ex
= explore
; ex
->e_af
>= 0; ex
++) {
393 if (!MATCH_FAMILY(pai
->ai_family
, ex
->e_af
, WILD_AF(ex
)))
395 if (!MATCH(pai
->ai_socktype
, ex
->e_socktype
, WILD_SOCKTYPE(ex
)))
397 if (!MATCH(pai
->ai_protocol
, ex
->e_protocol
, WILD_PROTOCOL(ex
)))
400 if (pai
->ai_family
== PF_UNSPEC
)
401 pai
->ai_family
= ex
->e_af
;
402 if (pai
->ai_socktype
== ANY
&& ex
->e_socktype
!= ANY
)
403 pai
->ai_socktype
= ex
->e_socktype
;
404 if (pai
->ai_protocol
== ANY
&& ex
->e_protocol
!= ANY
)
405 pai
->ai_protocol
= ex
->e_protocol
;
407 if (hostname
== NULL
)
408 error
= explore_null(pai
, hostname
, servname
, &cur
->ai_next
);
410 error
= explore_numeric_scope(pai
, hostname
, servname
, &cur
->ai_next
);
415 while (cur
&& cur
->ai_next
)
421 * If numreic representation of AF1 can be interpreted as FQDN
422 * representation of AF2, we need to think again about the code below.
424 if (sentinel
.ai_next
)
427 if (pai
->ai_flags
& AI_NUMERICHOST
)
429 if (hostname
== NULL
)
433 * hostname as alphabetical name.
434 * we would like to prefer AF_INET6 than AF_INET, so we'll make a
437 for (afd
= afdl
; afd
->a_af
; afd
++) {
440 if (!MATCH_FAMILY(pai
->ai_family
, afd
->a_af
, 1))
443 for (ex
= explore
; ex
->e_af
>= 0; ex
++) {
446 if (pai
->ai_family
== PF_UNSPEC
)
447 pai
->ai_family
= afd
->a_af
;
449 if (!MATCH_FAMILY(pai
->ai_family
, ex
->e_af
, WILD_AF(ex
)))
451 if (!MATCH(pai
->ai_socktype
, ex
->e_socktype
,
452 WILD_SOCKTYPE(ex
))) {
455 if (!MATCH(pai
->ai_protocol
, ex
->e_protocol
,
456 WILD_PROTOCOL(ex
))) {
460 if (pai
->ai_family
== PF_UNSPEC
)
461 pai
->ai_family
= ex
->e_af
;
462 if (pai
->ai_socktype
== ANY
&& ex
->e_socktype
!= ANY
)
463 pai
->ai_socktype
= ex
->e_socktype
;
464 if (pai
->ai_protocol
== ANY
&& ex
->e_protocol
!= ANY
)
465 pai
->ai_protocol
= ex
->e_protocol
;
467 error
= explore_fqdn(pai
, hostname
, servname
,
470 while (cur
&& cur
->ai_next
)
476 if (sentinel
.ai_next
)
482 if (sentinel
.ai_next
) {
484 *res
= sentinel
.ai_next
;
491 if (sentinel
.ai_next
)
492 freeaddrinfo(sentinel
.ai_next
);
498 * FQDN hostname, DNS lookup
501 explore_fqdn(pai
, hostname
, servname
, res
)
502 const struct addrinfo
*pai
;
503 const char *hostname
;
504 const char *servname
;
505 struct addrinfo
**res
;
512 struct addrinfo sentinel
, *cur
;
514 const struct afd
*afd
;
518 sentinel
.ai_next
= NULL
;
522 * filter out AFs that are not supported by the kernel
525 s
= socket(pai
->ai_family
, SOCK_DGRAM
, 0);
531 * if the servname does not match socktype/protocol, ignore it.
533 if (get_portmatch(pai
, servname
) != 0)
536 afd
= find_afd(pai
->ai_family
);
538 #ifdef USE_GETIPNODEBY
539 hp
= getipnodebyname(hostname
, pai
->ai_family
, AI_ADDRCONFIG
, &h_error
);
540 #elif defined(HAVE_GETHOSTBYNAME2)
541 hp
= gethostbyname2(hostname
, pai
->ai_family
);
544 if (pai
->ai_family
!= AF_INET
)
546 hp
= gethostbyname(hostname
);
565 } else if ((hp
->h_name
== NULL
) || (hp
->h_name
[0] == 0)
566 || (hp
->h_addr_list
[0] == NULL
)) {
567 #ifdef USE_GETIPNODEBY
577 for (i
= 0; hp
->h_addr_list
[i
] != NULL
; i
++) {
579 ap
= hp
->h_addr_list
[i
];
582 && IN6_IS_ADDR_V4MAPPED((struct in6_addr
*)ap
)) {
584 ap
= ap
+ sizeof(struct in6_addr
)
585 - sizeof(struct in_addr
);
589 if (af
!= pai
->ai_family
)
592 if ((pai
->ai_flags
& AI_CANONNAME
) == 0) {
593 GET_AI(cur
->ai_next
, afd
, ap
);
594 GET_PORT(cur
->ai_next
, servname
);
597 * if AI_CANONNAME and if reverse lookup
598 * fail, return ai anyway to pacify
599 * calling application.
601 * XXX getaddrinfo() is a name->address
602 * translation function, and it looks
603 * strange that we do addr->name
606 get_name(ap
, afd
, &cur
->ai_next
,
610 while (cur
&& cur
->ai_next
)
614 *res
= sentinel
.ai_next
;
618 #ifdef USE_GETIPNODEBY
622 if (sentinel
.ai_next
)
623 freeaddrinfo(sentinel
.ai_next
);
629 * passive socket -> anyaddr (0.0.0.0 or ::)
630 * non-passive socket -> localhost (127.0.0.1 or ::1)
633 explore_null(pai
, hostname
, servname
, res
)
634 const struct addrinfo
*pai
;
635 const char *hostname
;
636 const char *servname
;
637 struct addrinfo
**res
;
640 const struct afd
*afd
;
641 struct addrinfo
*cur
;
642 struct addrinfo sentinel
;
646 sentinel
.ai_next
= NULL
;
650 * filter out AFs that are not supported by the kernel
653 s
= socket(pai
->ai_family
, SOCK_DGRAM
, 0);
659 * if the servname does not match socktype/protocol, ignore it.
661 if (get_portmatch(pai
, servname
) != 0)
664 afd
= find_afd(pai
->ai_family
);
666 if (pai
->ai_flags
& AI_PASSIVE
) {
667 GET_AI(cur
->ai_next
, afd
, afd
->a_addrany
);
669 * GET_CANONNAME(cur->ai_next, "anyaddr");
671 GET_PORT(cur
->ai_next
, servname
);
673 GET_AI(cur
->ai_next
, afd
, afd
->a_loopback
);
675 * GET_CANONNAME(cur->ai_next, "localhost");
677 GET_PORT(cur
->ai_next
, servname
);
681 *res
= sentinel
.ai_next
;
685 if (sentinel
.ai_next
)
686 freeaddrinfo(sentinel
.ai_next
);
694 explore_numeric(pai
, hostname
, servname
, res
)
695 const struct addrinfo
*pai
;
696 const char *hostname
;
697 const char *servname
;
698 struct addrinfo
**res
;
700 const struct afd
*afd
;
701 struct addrinfo
*cur
;
702 struct addrinfo sentinel
;
708 sentinel
.ai_next
= NULL
;
712 * if the servname does not match socktype/protocol, ignore it.
714 if (get_portmatch(pai
, servname
) != 0)
717 afd
= find_afd(pai
->ai_family
);
718 flags
= pai
->ai_flags
;
720 if (inet_pton(afd
->a_af
, hostname
, pton
) == 1) {
728 v4a
= (u_int32_t
)ntohl(((struct in_addr
*)pton
)->s_addr
);
729 if (IN_MULTICAST(v4a
) || IN_EXPERIMENTAL(v4a
))
730 flags
&= ~AI_CANONNAME
;
731 v4a
>>= IN_CLASSA_NSHIFT
;
732 if (v4a
== 0 || v4a
== IN_LOOPBACKNET
)
733 flags
&= ~AI_CANONNAME
;
737 pfx
= ((struct in6_addr
*)pton
)->s6_addr
[0];
738 if (pfx
== 0 || pfx
== 0xfe || pfx
== 0xff)
739 flags
&= ~AI_CANONNAME
;
744 if (pai
->ai_family
== afd
->a_af
||
745 pai
->ai_family
== PF_UNSPEC
/*?*/) {
746 if ((flags
& AI_CANONNAME
) == 0) {
747 GET_AI(cur
->ai_next
, afd
, pton
);
748 GET_PORT(cur
->ai_next
, servname
);
751 * if AI_CANONNAME and if reverse lookup
752 * fail, return ai anyway to pacify
753 * calling application.
755 * XXX getaddrinfo() is a name->address
756 * translation function, and it looks
757 * strange that we do addr->name
760 get_name(pton
, afd
, &cur
->ai_next
,
761 pton
, pai
, servname
);
763 while (cur
&& cur
->ai_next
)
766 ERR(EAI_FAMILY
); /*xxx*/
769 *res
= sentinel
.ai_next
;
774 if (sentinel
.ai_next
)
775 freeaddrinfo(sentinel
.ai_next
);
780 * numeric hostname with scope
783 explore_numeric_scope(pai
, hostname
, servname
, res
)
784 const struct addrinfo
*pai
;
785 const char *hostname
;
786 const char *servname
;
787 struct addrinfo
**res
;
789 #ifndef SCOPE_DELIMITER
790 return explore_numeric(pai
, hostname
, servname
, res
);
792 const struct afd
*afd
;
793 struct addrinfo
*cur
;
795 char *cp
, *hostname2
= NULL
;
797 struct sockaddr_in6
*sin6
;
800 * if the servname does not match socktype/protocol, ignore it.
802 if (get_portmatch(pai
, servname
) != 0)
805 afd
= find_afd(pai
->ai_family
);
807 return explore_numeric(pai
, hostname
, servname
, res
);
809 cp
= strchr(hostname
, SCOPE_DELIMITER
);
811 return explore_numeric(pai
, hostname
, servname
, res
);
814 * Handle special case of <scoped_address><delimiter><scope id>
816 hostname2
= strdup(hostname
);
817 if (hostname2
== NULL
)
819 /* terminate at the delimiter */
820 hostname2
[cp
- hostname
] = '\0';
823 switch (pai
->ai_family
) {
826 scope
= if_nametoindex(cp
);
831 error
= explore_numeric(pai
, hostname2
, servname
, res
);
833 for (cur
= *res
; cur
; cur
= cur
->ai_next
) {
834 if (cur
->ai_family
!= AF_INET6
)
836 sin6
= (struct sockaddr_in6
*)cur
->ai_addr
;
837 if (IN6_IS_ADDR_LINKLOCAL(&sin6
->sin6_addr
) ||
838 IN6_IS_ADDR_MC_LINKLOCAL(&sin6
->sin6_addr
))
839 sin6
->sin6_scope_id
= scope
;
850 get_name(addr
, afd
, res
, numaddr
, pai
, servname
)
852 const struct afd
*afd
;
853 struct addrinfo
**res
;
855 const struct addrinfo
*pai
;
856 const char *servname
;
859 struct addrinfo
*cur
;
861 #ifdef USE_GETIPNODEBY
864 hp
= getipnodebyaddr(addr
, afd
->a_addrlen
, afd
->a_af
, &h_error
);
866 hp
= gethostbyaddr(addr
, afd
->a_addrlen
, afd
->a_af
);
868 if (hp
&& hp
->h_name
&& hp
->h_name
[0] && hp
->h_addr_list
[0]) {
869 GET_AI(cur
, afd
, hp
->h_addr_list
[0]);
870 GET_PORT(cur
, servname
);
871 GET_CANONNAME(cur
, hp
->h_name
);
873 GET_AI(cur
, afd
, numaddr
);
874 GET_PORT(cur
, servname
);
877 #ifdef USE_GETIPNODEBY
886 #ifdef USE_GETIPNODEBY
896 get_canonname(pai
, ai
, str
)
897 const struct addrinfo
*pai
;
901 if ((pai
->ai_flags
& AI_CANONNAME
) != 0) {
902 ai
->ai_canonname
= (char *)malloc(strlen(str
) + 1);
903 if (ai
->ai_canonname
== NULL
)
905 strcpy(ai
->ai_canonname
, str
);
910 static struct addrinfo
*
911 get_ai(pai
, afd
, addr
)
912 const struct addrinfo
*pai
;
913 const struct afd
*afd
;
919 ai
= (struct addrinfo
*)malloc(sizeof(struct addrinfo
)
924 memcpy(ai
, pai
, sizeof(struct addrinfo
));
925 ai
->ai_addr
= (struct sockaddr
*)(ai
+ 1);
926 memset(ai
->ai_addr
, 0, afd
->a_socklen
);
927 #ifdef HAVE_SOCKADDR_SA_LEN
928 ai
->ai_addr
->sa_len
= afd
->a_socklen
;
930 ai
->ai_addrlen
= afd
->a_socklen
;
931 ai
->ai_addr
->sa_family
= ai
->ai_family
= afd
->a_af
;
932 p
= (char *)(ai
->ai_addr
);
933 memcpy(p
+ afd
->a_off
, addr
, afd
->a_addrlen
);
938 get_portmatch(ai
, servname
)
939 const struct addrinfo
*ai
;
940 const char *servname
;
942 /* get_port does not touch first argument. when matchonly == 1. */
943 return get_port((struct addrinfo
*)ai
, servname
, 1);
947 get_port(ai
, servname
, matchonly
)
949 const char *servname
;
957 if (servname
== NULL
)
959 if (ai
->ai_family
!= AF_INET
961 && ai
->ai_family
!= AF_INET6
966 switch (ai
->ai_socktype
) {
980 if (str_isnumber(servname
)) {
983 port
= htons(atoi(servname
));
984 if (port
< 0 || port
> 65535)
987 switch (ai
->ai_socktype
) {
999 if ((sp
= getservbyname(servname
, proto
)) == NULL
)
1005 switch (ai
->ai_family
) {
1007 ((struct sockaddr_in
*)ai
->ai_addr
)->sin_port
= port
;
1011 ((struct sockaddr_in6
*)ai
->ai_addr
)->sin6_port
= port
;
1020 static const struct afd
*
1024 const struct afd
*afd
;
1026 if (af
== PF_UNSPEC
)
1028 for (afd
= afdl
; afd
->a_af
; afd
++) {
1029 if (afd
->a_af
== af
)