]>
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.
46 static const char rcsid
[] =
47 "@(#) $Header: /tcpdump/master/tcpdump/missing/getaddrinfo.c,v 1.7 2000-01-09 21:35:44 fenner Exp $";
50 #include <sys/types.h>
51 #include <sys/param.h>
53 #include <sys/sysctl.h>
55 #include <sys/socket.h>
57 #include <netinet/in.h>
58 #include <arpa/inet.h>
59 #include <arpa/nameser.h>
70 #ifndef HAVE_PORTABLE_PROTOTYPE
71 #include "cdecl_ext.h"
75 #ifndef HAVE_U_INT32_T
80 #ifndef HAVE_SOCKADDR_STORAGE
81 #include "sockstorage.h"
86 #if defined(__KAME__) && defined(INET6)
96 static int translate
= NO
;
97 static struct in6_addr faith_prefix
= IN6ADDR_ANY_INIT
;
100 static const char in_addrany
[] = { 0, 0, 0, 0 };
101 static const char in6_addrany
[] = {
102 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
104 static const char in_loopback
[] = { 127, 0, 0, 1 };
105 static const char in6_loopback
[] = {
106 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1
113 u_int32_t si_scope_id
;
116 static const struct afd
{
121 const char *a_addrany
;
122 const char *a_loopback
;
126 {PF_INET6
, sizeof(struct in6_addr
),
127 sizeof(struct sockaddr_in6
),
128 offsetof(struct sockaddr_in6
, sin6_addr
),
129 in6_addrany
, in6_loopback
, 1},
131 {PF_INET
, sizeof(struct in_addr
),
132 sizeof(struct sockaddr_in
),
133 offsetof(struct sockaddr_in
, sin_addr
),
134 in_addrany
, in_loopback
, 0},
135 {0, 0, 0, 0, NULL
, NULL
, 0},
142 const char *e_protostr
;
144 #define WILD_AF(ex) ((ex)->e_wild & 0x01)
145 #define WILD_SOCKTYPE(ex) ((ex)->e_wild & 0x02)
146 #define WILD_PROTOCOL(ex) ((ex)->e_wild & 0x04)
149 static const struct explore explore
[] = {
151 { PF_LOCAL
, 0, ANY
, ANY
, NULL
, 0x01 },
154 { PF_INET6
, SOCK_DGRAM
, IPPROTO_UDP
, "udp", 0x07 },
155 { PF_INET6
, SOCK_STREAM
, IPPROTO_TCP
, "tcp", 0x07 },
156 { PF_INET6
, SOCK_RAW
, ANY
, NULL
, 0x05 },
158 { PF_INET
, SOCK_DGRAM
, IPPROTO_UDP
, "udp", 0x07 },
159 { PF_INET
, SOCK_STREAM
, IPPROTO_TCP
, "tcp", 0x07 },
160 { PF_INET
, SOCK_RAW
, ANY
, NULL
, 0x05 },
161 { -1, 0, 0, NULL
, 0 },
171 static int str_isnumber
__P((const char *));
172 static int explore_fqdn
__P((const struct addrinfo
*, const char *,
173 const char *, struct addrinfo
**));
174 static int explore_null
__P((const struct addrinfo
*, const char *,
175 const char *, struct addrinfo
**));
176 static int explore_numeric
__P((const struct addrinfo
*, const char *,
177 const char *, struct addrinfo
**));
178 static int explore_numeric_scope
__P((const struct addrinfo
*, const char *,
179 const char *, struct addrinfo
**));
180 static int get_name
__P((const char *, const struct afd
*, struct addrinfo
**,
181 char *, const struct addrinfo
*, const char *));
182 static int get_canonname
__P((const struct addrinfo
*,
183 struct addrinfo
*, const char *));
184 static struct addrinfo
*get_ai
__P((const struct addrinfo
*,
185 const struct afd
*, const char *));
186 static int get_portmatch
__P((const struct addrinfo
*, const char *));
187 static int get_port
__P((struct addrinfo
*, const char *, int));
188 static const struct afd
*find_afd
__P((int));
190 static char *ai_errlist
[] = {
192 "Address family for hostname not supported", /* EAI_ADDRFAMILY */
193 "Temporary failure in name resolution", /* EAI_AGAIN */
194 "Invalid value for ai_flags", /* EAI_BADFLAGS */
195 "Non-recoverable failure in name resolution", /* EAI_FAIL */
196 "ai_family not supported", /* EAI_FAMILY */
197 "Memory allocation failure", /* EAI_MEMORY */
198 "No address associated with hostname", /* EAI_NODATA */
199 "hostname nor servname provided, or not known", /* EAI_NONAME */
200 "servname not supported for ai_socktype", /* EAI_SERVICE */
201 "ai_socktype not supported", /* EAI_SOCKTYPE */
202 "System error returned in errno", /* EAI_SYSTEM */
203 "Invalid value for hints", /* EAI_BADHINTS */
204 "Resolved protocol is unknown", /* EAI_PROTOCOL */
205 "Unknown error", /* EAI_MAX */
208 /* XXX macros that make external reference is BAD. */
210 #define GET_AI(ai, afd, addr) \
212 /* external reference: pai, error, and label free */ \
213 (ai) = get_ai(pai, (afd), (addr)); \
214 if ((ai) == NULL) { \
215 error = EAI_MEMORY; \
220 #define GET_PORT(ai, serv) \
222 /* external reference: error and label free */ \
223 error = get_port((ai), (serv), 0); \
228 #define GET_CANONNAME(ai, str) \
230 /* external reference: pai, error and label free */ \
231 error = get_canonname(pai, (ai), (str)); \
238 /* external reference: error, and label bad */ \
243 #define MATCH_FAMILY(x, y, w) \
244 ((x) == (y) || ((w) && ((x) == PF_UNSPEC || (y) == PF_UNSPEC)))
245 #define MATCH(x, y, w) \
246 ((x) == (y) || ((w) && ((x) == ANY || (y) == ANY)))
252 if (ecode
< 0 || ecode
> EAI_MAX
)
254 return ai_errlist
[ecode
];
261 struct addrinfo
*next
;
265 if (ai
->ai_canonname
)
266 free(ai
->ai_canonname
);
267 /* no need to free(ai->ai_addr) */
269 } while ((ai
= next
) != NULL
);
286 getaddrinfo(hostname
, servname
, hints
, res
)
287 const char *hostname
, *servname
;
288 const struct addrinfo
*hints
;
289 struct addrinfo
**res
;
291 struct addrinfo sentinel
;
292 struct addrinfo
*cur
;
296 struct addrinfo
*pai
;
297 const struct afd
*afd
;
298 const struct explore
*ex
;
301 static int firsttime
= 1;
304 /* translator hack */
305 char *q
= getenv("GAI");
306 if (q
&& inet_pton(AF_INET6
, q
, &faith_prefix
) == 1)
312 sentinel
.ai_next
= NULL
;
316 pai
->ai_family
= PF_UNSPEC
;
317 pai
->ai_socktype
= ANY
;
318 pai
->ai_protocol
= ANY
;
320 pai
->ai_canonname
= NULL
;
324 if (hostname
== NULL
&& servname
== NULL
)
327 /* error check for hints */
328 if (hints
->ai_addrlen
|| hints
->ai_canonname
||
329 hints
->ai_addr
|| hints
->ai_next
)
330 ERR(EAI_BADHINTS
); /* xxx */
331 if (hints
->ai_flags
& ~AI_MASK
)
333 switch (hints
->ai_family
) {
343 memcpy(pai
, hints
, sizeof(*pai
));
346 * if both socktype/protocol are specified, check if they
347 * are meaningful combination.
349 if (pai
->ai_socktype
!= ANY
&& pai
->ai_protocol
!= ANY
) {
350 for (ex
= explore
; ex
->e_af
>= 0; ex
++) {
351 if (pai
->ai_family
!= ex
->e_af
)
353 if (ex
->e_socktype
== ANY
)
355 if (ex
->e_protocol
== ANY
)
357 if (pai
->ai_socktype
== ex
->e_socktype
358 && pai
->ai_protocol
!= ex
->e_protocol
) {
366 * check for special cases. (1) numeric servname is disallowed if
367 * socktype/protocol are left unspecified. (2) servname is disallowed
368 * for raw and other inet{,6} sockets.
370 if (MATCH_FAMILY(pai
->ai_family
, PF_INET
, 1)
372 || MATCH_FAMILY(pai
->ai_family
, PF_INET6
, 1)
377 if (pai
->ai_family
== PF_UNSPEC
)
379 pai
->ai_family
= PF_INET6
;
381 pai
->ai_family
= PF_INET
;
383 error
= get_portmatch(pai
, servname
);
392 /* NULL hostname, or numeric hostname */
393 for (ex
= explore
; ex
->e_af
>= 0; ex
++) {
396 if (!MATCH_FAMILY(pai
->ai_family
, ex
->e_af
, WILD_AF(ex
)))
398 if (!MATCH(pai
->ai_socktype
, ex
->e_socktype
, WILD_SOCKTYPE(ex
)))
400 if (!MATCH(pai
->ai_protocol
, ex
->e_protocol
, WILD_PROTOCOL(ex
)))
403 if (pai
->ai_family
== PF_UNSPEC
)
404 pai
->ai_family
= ex
->e_af
;
405 if (pai
->ai_socktype
== ANY
&& ex
->e_socktype
!= ANY
)
406 pai
->ai_socktype
= ex
->e_socktype
;
407 if (pai
->ai_protocol
== ANY
&& ex
->e_protocol
!= ANY
)
408 pai
->ai_protocol
= ex
->e_protocol
;
410 if (hostname
== NULL
)
411 error
= explore_null(pai
, hostname
, servname
, &cur
->ai_next
);
413 error
= explore_numeric_scope(pai
, hostname
, servname
, &cur
->ai_next
);
418 while (cur
&& cur
->ai_next
)
424 * If numreic representation of AF1 can be interpreted as FQDN
425 * representation of AF2, we need to think again about the code below.
427 if (sentinel
.ai_next
)
430 if (pai
->ai_flags
& AI_NUMERICHOST
)
432 if (hostname
== NULL
)
436 * hostname as alphabetical name.
437 * we would like to prefer AF_INET6 than AF_INET, so we'll make a
440 for (afd
= afdl
; afd
->a_af
; afd
++) {
443 if (!MATCH_FAMILY(pai
->ai_family
, afd
->a_af
, 1))
446 for (ex
= explore
; ex
->e_af
>= 0; ex
++) {
449 if (pai
->ai_family
== PF_UNSPEC
)
450 pai
->ai_family
= afd
->a_af
;
452 if (!MATCH_FAMILY(pai
->ai_family
, ex
->e_af
, WILD_AF(ex
)))
454 if (!MATCH(pai
->ai_socktype
, ex
->e_socktype
,
455 WILD_SOCKTYPE(ex
))) {
458 if (!MATCH(pai
->ai_protocol
, ex
->e_protocol
,
459 WILD_PROTOCOL(ex
))) {
463 if (pai
->ai_family
== PF_UNSPEC
)
464 pai
->ai_family
= ex
->e_af
;
465 if (pai
->ai_socktype
== ANY
&& ex
->e_socktype
!= ANY
)
466 pai
->ai_socktype
= ex
->e_socktype
;
467 if (pai
->ai_protocol
== ANY
&& ex
->e_protocol
!= ANY
)
468 pai
->ai_protocol
= ex
->e_protocol
;
470 error
= explore_fqdn(pai
, hostname
, servname
,
473 while (cur
&& cur
->ai_next
)
479 if (sentinel
.ai_next
)
485 if (sentinel
.ai_next
) {
487 *res
= sentinel
.ai_next
;
494 if (sentinel
.ai_next
)
495 freeaddrinfo(sentinel
.ai_next
);
501 * FQDN hostname, DNS lookup
504 explore_fqdn(pai
, hostname
, servname
, res
)
505 const struct addrinfo
*pai
;
506 const char *hostname
;
507 const char *servname
;
508 struct addrinfo
**res
;
515 struct addrinfo sentinel
, *cur
;
517 const struct afd
*afd
;
521 sentinel
.ai_next
= NULL
;
525 * filter out AFs that are not supported by the kernel
528 s
= socket(pai
->ai_family
, SOCK_DGRAM
, 0);
534 * if the servname does not match socktype/protocol, ignore it.
536 if (get_portmatch(pai
, servname
) != 0)
539 afd
= find_afd(pai
->ai_family
);
541 #ifdef USE_GETIPNODEBY
542 hp
= getipnodebyname(hostname
, pai
->ai_family
, AI_ADDRCONFIG
, &h_error
);
543 #elif defined(HAVE_GETHOSTBYNAME2)
544 hp
= gethostbyname2(hostname
, pai
->ai_family
);
551 if (pai
->ai_family
!= AF_INET
)
553 hp
= gethostbyname(hostname
);
576 } else if ((hp
->h_name
== NULL
) || (hp
->h_name
[0] == 0)
577 || (hp
->h_addr_list
[0] == NULL
)) {
578 #ifdef USE_GETIPNODEBY
588 for (i
= 0; hp
->h_addr_list
[i
] != NULL
; i
++) {
590 ap
= hp
->h_addr_list
[i
];
593 && IN6_IS_ADDR_V4MAPPED((struct in6_addr
*)ap
)) {
595 ap
= ap
+ sizeof(struct in6_addr
)
596 - sizeof(struct in_addr
);
600 if (af
!= pai
->ai_family
)
603 if ((pai
->ai_flags
& AI_CANONNAME
) == 0) {
604 GET_AI(cur
->ai_next
, afd
, ap
);
605 GET_PORT(cur
->ai_next
, servname
);
608 * if AI_CANONNAME and if reverse lookup
609 * fail, return ai anyway to pacify
610 * calling application.
612 * XXX getaddrinfo() is a name->address
613 * translation function, and it looks
614 * strange that we do addr->name
617 get_name(ap
, afd
, &cur
->ai_next
,
621 while (cur
&& cur
->ai_next
)
625 *res
= sentinel
.ai_next
;
629 #ifdef USE_GETIPNODEBY
633 if (sentinel
.ai_next
)
634 freeaddrinfo(sentinel
.ai_next
);
640 * passive socket -> anyaddr (0.0.0.0 or ::)
641 * non-passive socket -> localhost (127.0.0.1 or ::1)
644 explore_null(pai
, hostname
, servname
, res
)
645 const struct addrinfo
*pai
;
646 const char *hostname
;
647 const char *servname
;
648 struct addrinfo
**res
;
651 const struct afd
*afd
;
652 struct addrinfo
*cur
;
653 struct addrinfo sentinel
;
657 sentinel
.ai_next
= NULL
;
661 * filter out AFs that are not supported by the kernel
664 s
= socket(pai
->ai_family
, SOCK_DGRAM
, 0);
670 * if the servname does not match socktype/protocol, ignore it.
672 if (get_portmatch(pai
, servname
) != 0)
675 afd
= find_afd(pai
->ai_family
);
677 if (pai
->ai_flags
& AI_PASSIVE
) {
678 GET_AI(cur
->ai_next
, afd
, afd
->a_addrany
);
680 * GET_CANONNAME(cur->ai_next, "anyaddr");
682 GET_PORT(cur
->ai_next
, servname
);
684 GET_AI(cur
->ai_next
, afd
, afd
->a_loopback
);
686 * GET_CANONNAME(cur->ai_next, "localhost");
688 GET_PORT(cur
->ai_next
, servname
);
692 *res
= sentinel
.ai_next
;
696 if (sentinel
.ai_next
)
697 freeaddrinfo(sentinel
.ai_next
);
705 explore_numeric(pai
, hostname
, servname
, res
)
706 const struct addrinfo
*pai
;
707 const char *hostname
;
708 const char *servname
;
709 struct addrinfo
**res
;
711 const struct afd
*afd
;
712 struct addrinfo
*cur
;
713 struct addrinfo sentinel
;
719 sentinel
.ai_next
= NULL
;
723 * if the servname does not match socktype/protocol, ignore it.
725 if (get_portmatch(pai
, servname
) != 0)
728 afd
= find_afd(pai
->ai_family
);
729 flags
= pai
->ai_flags
;
731 if (inet_pton(afd
->a_af
, hostname
, pton
) == 1) {
739 v4a
= (u_int32_t
)ntohl(((struct in_addr
*)pton
)->s_addr
);
740 if (IN_MULTICAST(v4a
) || IN_EXPERIMENTAL(v4a
))
741 flags
&= ~AI_CANONNAME
;
742 v4a
>>= IN_CLASSA_NSHIFT
;
743 if (v4a
== 0 || v4a
== IN_LOOPBACKNET
)
744 flags
&= ~AI_CANONNAME
;
748 pfx
= ((struct in6_addr
*)pton
)->s6_addr
[0];
749 if (pfx
== 0 || pfx
== 0xfe || pfx
== 0xff)
750 flags
&= ~AI_CANONNAME
;
755 if (pai
->ai_family
== afd
->a_af
||
756 pai
->ai_family
== PF_UNSPEC
/*?*/) {
757 if ((flags
& AI_CANONNAME
) == 0) {
758 GET_AI(cur
->ai_next
, afd
, pton
);
759 GET_PORT(cur
->ai_next
, servname
);
762 * if AI_CANONNAME and if reverse lookup
763 * fail, return ai anyway to pacify
764 * calling application.
766 * XXX getaddrinfo() is a name->address
767 * translation function, and it looks
768 * strange that we do addr->name
771 get_name(pton
, afd
, &cur
->ai_next
,
772 pton
, pai
, servname
);
774 while (cur
&& cur
->ai_next
)
777 ERR(EAI_FAMILY
); /*xxx*/
780 *res
= sentinel
.ai_next
;
785 if (sentinel
.ai_next
)
786 freeaddrinfo(sentinel
.ai_next
);
791 * numeric hostname with scope
794 explore_numeric_scope(pai
, hostname
, servname
, res
)
795 const struct addrinfo
*pai
;
796 const char *hostname
;
797 const char *servname
;
798 struct addrinfo
**res
;
800 #ifndef SCOPE_DELIMITER
801 return explore_numeric(pai
, hostname
, servname
, res
);
803 const struct afd
*afd
;
804 struct addrinfo
*cur
;
806 char *cp
, *hostname2
= NULL
;
808 struct sockaddr_in6
*sin6
;
811 * if the servname does not match socktype/protocol, ignore it.
813 if (get_portmatch(pai
, servname
) != 0)
816 afd
= find_afd(pai
->ai_family
);
818 return explore_numeric(pai
, hostname
, servname
, res
);
820 cp
= strchr(hostname
, SCOPE_DELIMITER
);
822 return explore_numeric(pai
, hostname
, servname
, res
);
825 * Handle special case of <scoped_address><delimiter><scope id>
827 hostname2
= strdup(hostname
);
828 if (hostname2
== NULL
)
830 /* terminate at the delimiter */
831 hostname2
[cp
- hostname
] = '\0';
834 switch (pai
->ai_family
) {
837 scope
= if_nametoindex(cp
);
842 error
= explore_numeric(pai
, hostname2
, servname
, res
);
844 for (cur
= *res
; cur
; cur
= cur
->ai_next
) {
845 if (cur
->ai_family
!= AF_INET6
)
847 sin6
= (struct sockaddr_in6
*)cur
->ai_addr
;
848 if (IN6_IS_ADDR_LINKLOCAL(&sin6
->sin6_addr
) ||
849 IN6_IS_ADDR_MC_LINKLOCAL(&sin6
->sin6_addr
))
850 sin6
->sin6_scope_id
= scope
;
861 get_name(addr
, afd
, res
, numaddr
, pai
, servname
)
863 const struct afd
*afd
;
864 struct addrinfo
**res
;
866 const struct addrinfo
*pai
;
867 const char *servname
;
870 struct addrinfo
*cur
;
872 #ifdef USE_GETIPNODEBY
875 hp
= getipnodebyaddr(addr
, afd
->a_addrlen
, afd
->a_af
, &h_error
);
877 hp
= gethostbyaddr(addr
, afd
->a_addrlen
, afd
->a_af
);
879 if (hp
&& hp
->h_name
&& hp
->h_name
[0] && hp
->h_addr_list
[0]) {
880 GET_AI(cur
, afd
, hp
->h_addr_list
[0]);
881 GET_PORT(cur
, servname
);
882 GET_CANONNAME(cur
, hp
->h_name
);
884 GET_AI(cur
, afd
, numaddr
);
885 GET_PORT(cur
, servname
);
888 #ifdef USE_GETIPNODEBY
897 #ifdef USE_GETIPNODEBY
907 get_canonname(pai
, ai
, str
)
908 const struct addrinfo
*pai
;
912 if ((pai
->ai_flags
& AI_CANONNAME
) != 0) {
913 ai
->ai_canonname
= (char *)malloc(strlen(str
) + 1);
914 if (ai
->ai_canonname
== NULL
)
916 strcpy(ai
->ai_canonname
, str
);
921 static struct addrinfo
*
922 get_ai(pai
, afd
, addr
)
923 const struct addrinfo
*pai
;
924 const struct afd
*afd
;
930 ai
= (struct addrinfo
*)malloc(sizeof(struct addrinfo
)
935 memcpy(ai
, pai
, sizeof(struct addrinfo
));
936 ai
->ai_addr
= (struct sockaddr
*)(ai
+ 1);
937 memset(ai
->ai_addr
, 0, afd
->a_socklen
);
938 #ifdef HAVE_SOCKADDR_SA_LEN
939 ai
->ai_addr
->sa_len
= afd
->a_socklen
;
941 ai
->ai_addrlen
= afd
->a_socklen
;
942 ai
->ai_addr
->sa_family
= ai
->ai_family
= afd
->a_af
;
943 p
= (char *)(ai
->ai_addr
);
944 memcpy(p
+ afd
->a_off
, addr
, afd
->a_addrlen
);
949 get_portmatch(ai
, servname
)
950 const struct addrinfo
*ai
;
951 const char *servname
;
953 /* get_port does not touch first argument. when matchonly == 1. */
954 return get_port((struct addrinfo
*)ai
, servname
, 1);
958 get_port(ai
, servname
, matchonly
)
960 const char *servname
;
968 if (servname
== NULL
)
970 if (ai
->ai_family
!= AF_INET
972 && ai
->ai_family
!= AF_INET6
977 switch (ai
->ai_socktype
) {
991 if (str_isnumber(servname
)) {
994 port
= htons(atoi(servname
));
995 if (port
< 0 || port
> 65535)
998 switch (ai
->ai_socktype
) {
1010 if ((sp
= getservbyname(servname
, proto
)) == NULL
)
1016 switch (ai
->ai_family
) {
1018 ((struct sockaddr_in
*)ai
->ai_addr
)->sin_port
= port
;
1022 ((struct sockaddr_in6
*)ai
->ai_addr
)->sin6_port
= port
;
1031 static const struct afd
*
1035 const struct afd
*afd
;
1037 if (af
== PF_UNSPEC
)
1039 for (afd
= afdl
; afd
->a_af
; afd
++) {
1040 if (afd
->a_af
== af
)