diff options
author | 2004-04-14 07:06:15 +0000 | |
---|---|---|
committer | 2004-04-14 07:06:15 +0000 | |
commit | 70595f11fa9e4f2d2ebbba19e5420d79843472a6 (patch) | |
tree | 3548848ba35c19bf721df4ac8099da774e436de8 | |
parent | with IPv6, udp checksum is mandatory. henning ok (diff) | |
download | wireguard-openbsd-70595f11fa9e4f2d2ebbba19e5420d79843472a6.tar.xz wireguard-openbsd-70595f11fa9e4f2d2ebbba19e5420d79843472a6.zip |
implement RFC3493 AI_NUMERICSERV. tedu ok
-rw-r--r-- | include/netdb.h | 8 | ||||
-rw-r--r-- | lib/libc/net/getaddrinfo.3 | 27 | ||||
-rw-r--r-- | lib/libc/net/getaddrinfo.c | 60 |
3 files changed, 45 insertions, 50 deletions
diff --git a/include/netdb.h b/include/netdb.h index b1b89183de5..78cadbefff0 100644 --- a/include/netdb.h +++ b/include/netdb.h @@ -1,4 +1,4 @@ -/* $OpenBSD: netdb.h,v 1.18 2003/06/02 19:34:12 millert Exp $ */ +/* $OpenBSD: netdb.h,v 1.19 2004/04/14 07:06:15 itojun Exp $ */ /* * ++Copyright++ 1980, 1983, 1988, 1993 @@ -155,10 +155,12 @@ struct protoent { /* Values for getaddrinfo() and getnameinfo() */ #define AI_PASSIVE 1 /* socket address is intended for bind() */ #define AI_CANONNAME 2 /* request for canonical name */ -#define AI_NUMERICHOST 4 /* don't ever try nameservice */ +#define AI_NUMERICHOST 4 /* don't ever try hostname lookup */ #define AI_EXT 8 /* enable non-portable extensions */ +#define AI_NUMERICSERV 16 /* don't ever try servname lookup */ /* valid flags for addrinfo */ -#define AI_MASK (AI_PASSIVE | AI_CANONNAME | AI_NUMERICHOST) +#define AI_MASK \ + (AI_PASSIVE | AI_CANONNAME | AI_NUMERICHOST | AI_NUMERICSERV) #define NI_NUMERICHOST 1 /* return the host address, not the name */ #define NI_NUMERICSERV 2 /* return the service address, not the name */ diff --git a/lib/libc/net/getaddrinfo.3 b/lib/libc/net/getaddrinfo.3 index 8c86748990c..7c4bae07a19 100644 --- a/lib/libc/net/getaddrinfo.3 +++ b/lib/libc/net/getaddrinfo.3 @@ -1,4 +1,4 @@ -.\" $OpenBSD: getaddrinfo.3,v 1.26 2004/03/01 20:25:44 deraadt Exp $ +.\" $OpenBSD: getaddrinfo.3,v 1.27 2004/04/14 07:06:15 itojun Exp $ .\" $KAME: getaddrinfo.3,v 1.29 2001/02/12 09:24:45 itojun Exp $ .\" .\" Copyright (c) 1983, 1987, 1991, 1993 @@ -247,6 +247,21 @@ is returned. This flag prevents any type of name resolution service (e.g., the DNS) from being called. .Pp +If the +.Dv AI_NUMERICSERV +bit is set in the +.Fa ai_flags +member of the +.Fa hints +structure, then a non-null +.Fa servname +string must be a numeric port string. +Otherwise an error of +.Dv EAI_NONAME +is returned. +This flag prevents any type of name resolution service (e.g., the NIS) +from being called. +.Pp The arguments to .Fn getaddrinfo must sufficiently be consistent and unambiguous. @@ -546,6 +561,16 @@ indicate an unknown error. .%D March 1999 .Re .Rs +.%A R. Gilligan +.%A S. Thomson +.%A J. Bound +.%A J. McCann +.%A W. Stevens +.%T Basic Socket Interface Extensions for IPv6 +.%R RFC 3493 +.%D February 2003 +.Re +.Rs .%A Tatsuya Jinmei .%A Atsushi Onoe .%T "An Extension of Format for IPv6 Scoped Addresses" diff --git a/lib/libc/net/getaddrinfo.c b/lib/libc/net/getaddrinfo.c index eb7bd7b3b18..8fb8975ad83 100644 --- a/lib/libc/net/getaddrinfo.c +++ b/lib/libc/net/getaddrinfo.c @@ -1,4 +1,4 @@ -/* $OpenBSD: getaddrinfo.c,v 1.48 2003/07/21 23:17:53 marc Exp $ */ +/* $OpenBSD: getaddrinfo.c,v 1.49 2004/04/14 07:06:15 itojun Exp $ */ /* $KAME: getaddrinfo.c,v 1.31 2000/08/31 17:36:43 itojun Exp $ */ /* @@ -197,7 +197,7 @@ struct res_target { int n; /* result length */ }; -static int str_isnumber(const char *); +static int str2number(const char *); static int explore_fqdn(const struct addrinfo *, const char *, const char *, struct addrinfo **); static int explore_null(const struct addrinfo *, @@ -213,9 +213,6 @@ static struct addrinfo *get_ai(const struct addrinfo *, static int get_portmatch(const struct addrinfo *, const char *); static int get_port(struct addrinfo *, const char *, int); static const struct afd *find_afd(int); -#if 0 -static int addrconfig(const struct addrinfo *); -#endif #ifdef INET6 static int ip6_str2scopeid(char *, struct sockaddr_in6 *, u_int32_t *); #endif @@ -282,20 +279,21 @@ do { \ ((x) == (y) || (/*CONSTCOND*/(w) && ((x) == ANY || (y) == ANY))) static int -str_isnumber(p) +str2number(p) const char *p; { char *ep; + unsigned long v; if (*p == '\0') - return NO; + return -1; ep = NULL; errno = 0; - (void)strtoul(p, &ep, 10); - if (errno == 0 && ep && *ep == '\0') - return YES; + v = strtoul(p, &ep, 10); + if (errno == 0 && ep && *ep == '\0' && v <= UINT_MAX) + return v; else - return NO; + return -1; } int @@ -517,17 +515,6 @@ explore_fqdn(pai, hostname, servname, res) result = NULL; -#if 0 - /* - * If AI_ADDRCONFIG is specified, check if we are expected to - * return the address family or not. - * XXX does not handle PF_UNSPEC case, should filter final result - */ - if ((pai->ai_flags & AI_ADDRCONFIG) != 0 && !addrconfig(pai)) { - return 0; - } -#endif - /* * if the servname does not match socktype/protocol, ignore it. */ @@ -914,14 +901,17 @@ get_port(ai, servname, matchonly) return EAI_SOCKTYPE; } - if (str_isnumber(servname)) { + port = str2number(servname); + if (port >= 0) { if (!allownumeric) return EAI_SERVICE; - port = atoi(servname); if (port < 0 || port > 65535) return EAI_SERVICE; port = htons(port); } else { + if (ai->ai_flags & AI_NUMERICSERV) + return EAI_NONAME; + switch (ai->ai_socktype) { case SOCK_DGRAM: proto = "udp"; @@ -975,28 +965,6 @@ find_afd(af) return NULL; } -#if 0 -/* - * post-2553: AI_ADDRCONFIG check. if we use getipnodeby* as backend, backend - * will take care of it. - * the semantics of AI_ADDRCONFIG is not defined well. we are not sure - * if the code is right or not. - */ -static int -addrconfig(pai) - const struct addrinfo *pai; -{ - int s; - - /* XXX errno */ - s = socket(pai->ai_family, SOCK_DGRAM, 0); - if (s < 0) - return 0; - close(s); - return 1; -} -#endif - #ifdef INET6 /* convert a string to a scope identifier. XXX: IPv6 specific */ static int |