diff options
author | Jun-ichiro itojun Hagino <itojun@cvs.openbsd.org> | 2001-11-14 02:31:58 +0000 |
---|---|---|
committer | Jun-ichiro itojun Hagino <itojun@cvs.openbsd.org> | 2001-11-14 02:31:58 +0000 |
commit | eb8d6c12af21998e318f8f99c2a9fbd3e6e11af3 (patch) | |
tree | 388c614c3d6bcad6ae544e15d5362aff5b223d7f /lib | |
parent | eec12e21c7a23e2cdc0d16b39611c7d27a9ba3cb (diff) |
sync with kame better. open some renaming #defines (ENI_xx).
Diffstat (limited to 'lib')
-rw-r--r-- | lib/libc/net/getnameinfo.c | 69 |
1 files changed, 27 insertions, 42 deletions
diff --git a/lib/libc/net/getnameinfo.c b/lib/libc/net/getnameinfo.c index 0dee5a6c4cc..9f2da6720c1 100644 --- a/lib/libc/net/getnameinfo.c +++ b/lib/libc/net/getnameinfo.c @@ -1,4 +1,4 @@ -/* $OpenBSD: getnameinfo.c,v 1.19 2001/08/20 02:23:33 itojun Exp $ */ +/* $OpenBSD: getnameinfo.c,v 1.20 2001/11/14 02:31:57 itojun Exp $ */ /* $KAME: getnameinfo.c,v 1.45 2000/09/25 22:43:56 itojun Exp $ */ /* @@ -57,12 +57,7 @@ #include <string.h> #include <stddef.h> -#define SUCCESS 0 -#define ANY 0 -#define YES 1 -#define NO 0 - -static struct afd { +static const struct afd { int a_af; int a_addrlen; int a_socklen; @@ -89,15 +84,6 @@ static int ip6_parsenumeric __P((const struct sockaddr *, const char *, char *, static int ip6_sa2str __P((const struct sockaddr_in6 *, char *, size_t, int)); #endif -/* 2553bis: use EAI_xx for getnameinfo */ -#define ENI_NOSOCKET EAI_FAIL /*XXX*/ -#define ENI_NOSERVNAME EAI_NONAME -#define ENI_NOHOSTNAME EAI_NONAME -#define ENI_MEMORY EAI_MEMORY -#define ENI_SYSTEM EAI_SYSTEM -#define ENI_FAMILY EAI_FAMILY -#define ENI_SALEN EAI_FAMILY - int getnameinfo(sa, salen, host, hostlen, serv, servlen, flags) const struct sockaddr *sa; @@ -108,7 +94,7 @@ getnameinfo(sa, salen, host, hostlen, serv, servlen, flags) size_t servlen; int flags; { - struct afd *afd; + const struct afd *afd; struct servent *sp; struct hostent *hp; u_short port; @@ -120,10 +106,10 @@ getnameinfo(sa, salen, host, hostlen, serv, servlen, flags) char numaddr[512]; if (sa == NULL) - return ENI_NOSOCKET; + return EAI_FAIL; if (sa->sa_len != salen) - return ENI_SALEN; + return EAI_FAIL; family = sa->sa_family; for (i = 0; afdl[i].a_af; i++) @@ -131,12 +117,12 @@ getnameinfo(sa, salen, host, hostlen, serv, servlen, flags) afd = &afdl[i]; goto found; } - return ENI_FAMILY; - + return EAI_FAMILY; + found: if (salen != afd->a_socklen) - return ENI_SALEN; - + return EAI_FAIL; + /* network byte order */ port = ((const struct sockinet *)sa)->si_port; addr = (const char *)sa + afd->a_off; @@ -145,8 +131,8 @@ getnameinfo(sa, salen, host, hostlen, serv, servlen, flags) /* * do nothing in this case. * in case you are wondering if "&&" is more correct than - * "||" here: RFC2553 says that serv == NULL OR servlen == 0 - * means that the caller does not want the result. + * "||" here: rfc2553bis-03 says that serv == NULL OR + * servlen == 0 means that the caller does not want the result. */ } else { if (flags & NI_NUMERICSERV) @@ -157,12 +143,12 @@ getnameinfo(sa, salen, host, hostlen, serv, servlen, flags) } if (sp) { if (strlen(sp->s_name) + 1 > servlen) - return ENI_MEMORY; + return EAI_MEMORY; strcpy(serv, sp->s_name); } else { snprintf(numserv, sizeof(numserv), "%d", ntohs(port)); if (strlen(numserv) + 1 > servlen) - return ENI_MEMORY; + return EAI_MEMORY; strcpy(serv, numserv); } } @@ -207,15 +193,15 @@ getnameinfo(sa, salen, host, hostlen, serv, servlen, flags) /* * do nothing in this case. * in case you are wondering if "&&" is more correct than - * "||" here: RFC2553 says that host == NULL OR hostlen == 0 - * means that the caller does not want the result. + * "||" here: rfc2553bis-03 says that host == NULL or + * hostlen == 0 means that the caller does not want the result. */ } else if (flags & NI_NUMERICHOST) { int numaddrlen; /* NUMERICHOST and NAMEREQD conflicts with each other */ if (flags & NI_NAMEREQD) - return ENI_NOHOSTNAME; + return EAI_NONAME; switch(afd->a_af) { #ifdef INET6 @@ -232,10 +218,10 @@ getnameinfo(sa, salen, host, hostlen, serv, servlen, flags) default: if (inet_ntop(afd->a_af, addr, numaddr, sizeof(numaddr)) == NULL) - return ENI_SYSTEM; + return EAI_SYSTEM; numaddrlen = strlen(numaddr); if (numaddrlen + 1 > hostlen) /* don't forget terminator */ - return ENI_MEMORY; + return EAI_MEMORY; strcpy(host, numaddr); break; } @@ -257,12 +243,12 @@ getnameinfo(sa, salen, host, hostlen, serv, servlen, flags) } #endif if (strlen(hp->h_name) + 1 > hostlen) { - return ENI_MEMORY; + return EAI_MEMORY; } strcpy(host, hp->h_name); } else { if (flags & NI_NAMEREQD) - return ENI_NOHOSTNAME; + return EAI_NONAME; switch(afd->a_af) { #ifdef INET6 case AF_INET6: @@ -279,12 +265,12 @@ getnameinfo(sa, salen, host, hostlen, serv, servlen, flags) default: if (inet_ntop(afd->a_af, addr, host, hostlen) == NULL) - return ENI_SYSTEM; + return EAI_SYSTEM; break; } } } - return SUCCESS; + return(0); } #ifdef INET6 @@ -299,13 +285,12 @@ ip6_parsenumeric(sa, addr, host, hostlen, flags) int numaddrlen; char numaddr[512]; - if (inet_ntop(AF_INET6, addr, numaddr, sizeof(numaddr)) - == NULL) - return ENI_SYSTEM; + if (inet_ntop(AF_INET6, addr, numaddr, sizeof(numaddr)) == NULL) + return EAI_SYSTEM; numaddrlen = strlen(numaddr); if (numaddrlen + 1 > hostlen) /* don't forget terminator */ - return ENI_MEMORY; + return EAI_MEMORY; strcpy(host, numaddr); #ifdef NI_WITHSCOPEID @@ -319,9 +304,9 @@ ip6_parsenumeric(sa, addr, host, hostlen, flags) (const struct sockaddr_in6 *)(const void *)sa, scopebuf, sizeof(scopebuf), 0); if (scopelen < 0) - return ENI_MEMORY; + return EAI_MEMORY; if (scopelen + 1 + numaddrlen + 1 > hostlen) - return ENI_MEMORY; + return EAI_MEMORY; /* * construct <numeric-addr><delim><scopeid> */ |