summaryrefslogtreecommitdiff
path: root/src/lib/libc/net/getaddrinfo.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/lib/libc/net/getaddrinfo.c')
-rw-r--r--src/lib/libc/net/getaddrinfo.c60
1 files changed, 14 insertions, 46 deletions
diff --git a/src/lib/libc/net/getaddrinfo.c b/src/lib/libc/net/getaddrinfo.c
index eb7bd7b3b1..8fb8975ad8 100644
--- a/src/lib/libc/net/getaddrinfo.c
+++ b/src/lib/libc/net/getaddrinfo.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: getaddrinfo.c,v 1.48 2003/07/21 23:17:53 marc Exp $ */ 1/* $OpenBSD: getaddrinfo.c,v 1.49 2004/04/14 07:06:15 itojun Exp $ */
2/* $KAME: getaddrinfo.c,v 1.31 2000/08/31 17:36:43 itojun Exp $ */ 2/* $KAME: getaddrinfo.c,v 1.31 2000/08/31 17:36:43 itojun Exp $ */
3 3
4/* 4/*
@@ -197,7 +197,7 @@ struct res_target {
197 int n; /* result length */ 197 int n; /* result length */
198}; 198};
199 199
200static int str_isnumber(const char *); 200static int str2number(const char *);
201static int explore_fqdn(const struct addrinfo *, const char *, 201static int explore_fqdn(const struct addrinfo *, const char *,
202 const char *, struct addrinfo **); 202 const char *, struct addrinfo **);
203static int explore_null(const struct addrinfo *, 203static int explore_null(const struct addrinfo *,
@@ -213,9 +213,6 @@ static struct addrinfo *get_ai(const struct addrinfo *,
213static int get_portmatch(const struct addrinfo *, const char *); 213static int get_portmatch(const struct addrinfo *, const char *);
214static int get_port(struct addrinfo *, const char *, int); 214static int get_port(struct addrinfo *, const char *, int);
215static const struct afd *find_afd(int); 215static const struct afd *find_afd(int);
216#if 0
217static int addrconfig(const struct addrinfo *);
218#endif
219#ifdef INET6 216#ifdef INET6
220static int ip6_str2scopeid(char *, struct sockaddr_in6 *, u_int32_t *); 217static int ip6_str2scopeid(char *, struct sockaddr_in6 *, u_int32_t *);
221#endif 218#endif
@@ -282,20 +279,21 @@ do { \
282 ((x) == (y) || (/*CONSTCOND*/(w) && ((x) == ANY || (y) == ANY))) 279 ((x) == (y) || (/*CONSTCOND*/(w) && ((x) == ANY || (y) == ANY)))
283 280
284static int 281static int
285str_isnumber(p) 282str2number(p)
286 const char *p; 283 const char *p;
287{ 284{
288 char *ep; 285 char *ep;
286 unsigned long v;
289 287
290 if (*p == '\0') 288 if (*p == '\0')
291 return NO; 289 return -1;
292 ep = NULL; 290 ep = NULL;
293 errno = 0; 291 errno = 0;
294 (void)strtoul(p, &ep, 10); 292 v = strtoul(p, &ep, 10);
295 if (errno == 0 && ep && *ep == '\0') 293 if (errno == 0 && ep && *ep == '\0' && v <= UINT_MAX)
296 return YES; 294 return v;
297 else 295 else
298 return NO; 296 return -1;
299} 297}
300 298
301int 299int
@@ -517,17 +515,6 @@ explore_fqdn(pai, hostname, servname, res)
517 515
518 result = NULL; 516 result = NULL;
519 517
520#if 0
521 /*
522 * If AI_ADDRCONFIG is specified, check if we are expected to
523 * return the address family or not.
524 * XXX does not handle PF_UNSPEC case, should filter final result
525 */
526 if ((pai->ai_flags & AI_ADDRCONFIG) != 0 && !addrconfig(pai)) {
527 return 0;
528 }
529#endif
530
531 /* 518 /*
532 * if the servname does not match socktype/protocol, ignore it. 519 * if the servname does not match socktype/protocol, ignore it.
533 */ 520 */
@@ -914,14 +901,17 @@ get_port(ai, servname, matchonly)
914 return EAI_SOCKTYPE; 901 return EAI_SOCKTYPE;
915 } 902 }
916 903
917 if (str_isnumber(servname)) { 904 port = str2number(servname);
905 if (port >= 0) {
918 if (!allownumeric) 906 if (!allownumeric)
919 return EAI_SERVICE; 907 return EAI_SERVICE;
920 port = atoi(servname);
921 if (port < 0 || port > 65535) 908 if (port < 0 || port > 65535)
922 return EAI_SERVICE; 909 return EAI_SERVICE;
923 port = htons(port); 910 port = htons(port);
924 } else { 911 } else {
912 if (ai->ai_flags & AI_NUMERICSERV)
913 return EAI_NONAME;
914
925 switch (ai->ai_socktype) { 915 switch (ai->ai_socktype) {
926 case SOCK_DGRAM: 916 case SOCK_DGRAM:
927 proto = "udp"; 917 proto = "udp";
@@ -975,28 +965,6 @@ find_afd(af)
975 return NULL; 965 return NULL;
976} 966}
977 967
978#if 0
979/*
980 * post-2553: AI_ADDRCONFIG check. if we use getipnodeby* as backend, backend
981 * will take care of it.
982 * the semantics of AI_ADDRCONFIG is not defined well. we are not sure
983 * if the code is right or not.
984 */
985static int
986addrconfig(pai)
987 const struct addrinfo *pai;
988{
989 int s;
990
991 /* XXX errno */
992 s = socket(pai->ai_family, SOCK_DGRAM, 0);
993 if (s < 0)
994 return 0;
995 close(s);
996 return 1;
997}
998#endif
999
1000#ifdef INET6 968#ifdef INET6
1001/* convert a string to a scope identifier. XXX: IPv6 specific */ 969/* convert a string to a scope identifier. XXX: IPv6 specific */
1002static int 970static int