diff options
author | itojun <> | 2004-04-14 07:06:15 +0000 |
---|---|---|
committer | itojun <> | 2004-04-14 07:06:15 +0000 |
commit | cdd1fcebca0f946b8d5c2fd099475580f661130f (patch) | |
tree | b6315ef94f7e61f6de8f02621b41f5163794c496 /src/lib | |
parent | 3db28b80413b56d75da4c94abc75f78d453ede77 (diff) | |
download | openbsd-cdd1fcebca0f946b8d5c2fd099475580f661130f.tar.gz openbsd-cdd1fcebca0f946b8d5c2fd099475580f661130f.tar.bz2 openbsd-cdd1fcebca0f946b8d5c2fd099475580f661130f.zip |
implement RFC3493 AI_NUMERICSERV. tedu ok
Diffstat (limited to 'src/lib')
-rw-r--r-- | src/lib/libc/net/getaddrinfo.3 | 27 | ||||
-rw-r--r-- | src/lib/libc/net/getaddrinfo.c | 60 |
2 files changed, 40 insertions, 47 deletions
diff --git a/src/lib/libc/net/getaddrinfo.3 b/src/lib/libc/net/getaddrinfo.3 index 8c86748990..7c4bae07a1 100644 --- a/src/lib/libc/net/getaddrinfo.3 +++ b/src/lib/libc/net/getaddrinfo.3 | |||
@@ -1,4 +1,4 @@ | |||
1 | .\" $OpenBSD: getaddrinfo.3,v 1.26 2004/03/01 20:25:44 deraadt Exp $ | 1 | .\" $OpenBSD: getaddrinfo.3,v 1.27 2004/04/14 07:06:15 itojun Exp $ |
2 | .\" $KAME: getaddrinfo.3,v 1.29 2001/02/12 09:24:45 itojun Exp $ | 2 | .\" $KAME: getaddrinfo.3,v 1.29 2001/02/12 09:24:45 itojun Exp $ |
3 | .\" | 3 | .\" |
4 | .\" Copyright (c) 1983, 1987, 1991, 1993 | 4 | .\" Copyright (c) 1983, 1987, 1991, 1993 |
@@ -247,6 +247,21 @@ is returned. | |||
247 | This flag prevents any type of name resolution service (e.g., the DNS) | 247 | This flag prevents any type of name resolution service (e.g., the DNS) |
248 | from being called. | 248 | from being called. |
249 | .Pp | 249 | .Pp |
250 | If the | ||
251 | .Dv AI_NUMERICSERV | ||
252 | bit is set in the | ||
253 | .Fa ai_flags | ||
254 | member of the | ||
255 | .Fa hints | ||
256 | structure, then a non-null | ||
257 | .Fa servname | ||
258 | string must be a numeric port string. | ||
259 | Otherwise an error of | ||
260 | .Dv EAI_NONAME | ||
261 | is returned. | ||
262 | This flag prevents any type of name resolution service (e.g., the NIS) | ||
263 | from being called. | ||
264 | .Pp | ||
250 | The arguments to | 265 | The arguments to |
251 | .Fn getaddrinfo | 266 | .Fn getaddrinfo |
252 | must sufficiently be consistent and unambiguous. | 267 | must sufficiently be consistent and unambiguous. |
@@ -546,6 +561,16 @@ indicate an unknown error. | |||
546 | .%D March 1999 | 561 | .%D March 1999 |
547 | .Re | 562 | .Re |
548 | .Rs | 563 | .Rs |
564 | .%A R. Gilligan | ||
565 | .%A S. Thomson | ||
566 | .%A J. Bound | ||
567 | .%A J. McCann | ||
568 | .%A W. Stevens | ||
569 | .%T Basic Socket Interface Extensions for IPv6 | ||
570 | .%R RFC 3493 | ||
571 | .%D February 2003 | ||
572 | .Re | ||
573 | .Rs | ||
549 | .%A Tatsuya Jinmei | 574 | .%A Tatsuya Jinmei |
550 | .%A Atsushi Onoe | 575 | .%A Atsushi Onoe |
551 | .%T "An Extension of Format for IPv6 Scoped Addresses" | 576 | .%T "An Extension of Format for IPv6 Scoped Addresses" |
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 | ||
200 | static int str_isnumber(const char *); | 200 | static int str2number(const char *); |
201 | static int explore_fqdn(const struct addrinfo *, const char *, | 201 | static int explore_fqdn(const struct addrinfo *, const char *, |
202 | const char *, struct addrinfo **); | 202 | const char *, struct addrinfo **); |
203 | static int explore_null(const struct addrinfo *, | 203 | static int explore_null(const struct addrinfo *, |
@@ -213,9 +213,6 @@ static struct addrinfo *get_ai(const struct addrinfo *, | |||
213 | static int get_portmatch(const struct addrinfo *, const char *); | 213 | static int get_portmatch(const struct addrinfo *, const char *); |
214 | static int get_port(struct addrinfo *, const char *, int); | 214 | static int get_port(struct addrinfo *, const char *, int); |
215 | static const struct afd *find_afd(int); | 215 | static const struct afd *find_afd(int); |
216 | #if 0 | ||
217 | static int addrconfig(const struct addrinfo *); | ||
218 | #endif | ||
219 | #ifdef INET6 | 216 | #ifdef INET6 |
220 | static int ip6_str2scopeid(char *, struct sockaddr_in6 *, u_int32_t *); | 217 | static 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 | ||
284 | static int | 281 | static int |
285 | str_isnumber(p) | 282 | str2number(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 | ||
301 | int | 299 | int |
@@ -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 | */ | ||
985 | static int | ||
986 | addrconfig(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 */ |
1002 | static int | 970 | static int |