summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorJun-ichiro itojun Hagino <itojun@cvs.openbsd.org>2004-04-14 07:06:16 +0000
committerJun-ichiro itojun Hagino <itojun@cvs.openbsd.org>2004-04-14 07:06:16 +0000
commitd4393ea35deb3d0dfd98cc768e806300143e6d0a (patch)
tree8d91f6f72812df9a3b1798f9c8ce0c8fe539a211 /lib
parent428cbe21c8ea8d245eea9f492338ac5e6f1c6b32 (diff)
implement RFC3493 AI_NUMERICSERV. tedu ok
Diffstat (limited to 'lib')
-rw-r--r--lib/libc/net/getaddrinfo.327
-rw-r--r--lib/libc/net/getaddrinfo.c60
2 files changed, 40 insertions, 47 deletions
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