synchronize with kame better. get rid of #defines for ENI_xx.

This commit is contained in:
itojun 2001-11-15 04:38:32 +00:00
parent 9f77222197
commit 72a8eddd96
1 changed files with 27 additions and 42 deletions

View File

@ -1,4 +1,4 @@
/* $NetBSD: getnameinfo.c,v 1.32 2001/10/06 13:59:41 bjh21 Exp $ */
/* $NetBSD: getnameinfo.c,v 1.33 2001/11/15 04:38:32 itojun Exp $ */
/* $KAME: getnameinfo.c,v 1.45 2000/09/25 22:43:56 itojun Exp $ */
/*
@ -45,7 +45,7 @@
#include <sys/cdefs.h>
#if defined(LIBC_SCCS) && !defined(lint)
__RCSID("$NetBSD: getnameinfo.c,v 1.32 2001/10/06 13:59:41 bjh21 Exp $");
__RCSID("$NetBSD: getnameinfo.c,v 1.33 2001/11/15 04:38:32 itojun Exp $");
#endif /* LIBC_SCCS and not lint */
#include "namespace.h"
@ -69,11 +69,6 @@ __RCSID("$NetBSD: getnameinfo.c,v 1.32 2001/10/06 13:59:41 bjh21 Exp $");
__weak_alias(getnameinfo,_getnameinfo)
#endif
#define SUCCESS 0
#define ANY 0
#define YES 1
#define NO 0
static const struct afd {
int a_af;
socklen_t a_addrlen;
@ -106,15 +101,6 @@ static int getnameinfo_link __P((const struct sockaddr *, socklen_t, char *,
size_t, char *, size_t, int));
static int hexname __P((const u_int8_t *, size_t, char *, size_t));
/* 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
/*
* Top-level getnameinfo() code. Look at the address family, and pick an
* appropriate function to call.
@ -171,25 +157,25 @@ getnameinfo_inet(sa, salen, host, hostlen, serv, servlen, flags)
/* serv may be NULL */
if (sa == NULL)
return ENI_NOSOCKET;
return EAI_FAIL;
#ifdef BSD4_4
if (sa->sa_len != salen)
return ENI_SALEN;
return EAI_FAIL;
#endif
family = sa->sa_family;
for (i = 0; afdl[i].a_af; i++)
if (afdl[i].a_af == family) {
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 *)(const void *)sa)->si_port;
addr = (const char *)(const void *)sa + afd->a_off;
@ -198,8 +184,8 @@ getnameinfo_inet(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)
@ -210,12 +196,12 @@ getnameinfo_inet(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);
}
}
@ -261,15 +247,15 @@ getnameinfo_inet(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
@ -286,10 +272,10 @@ getnameinfo_inet(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;
}
@ -310,12 +296,12 @@ getnameinfo_inet(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:
@ -332,12 +318,12 @@ getnameinfo_inet(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
@ -356,13 +342,12 @@ ip6_parsenumeric(sa, addr, host, hostlen, flags)
_DIAGASSERT(addr != NULL);
_DIAGASSERT(host != NULL);
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
@ -376,9 +361,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>
*/