summaryrefslogtreecommitdiffstats
path: root/lib/libc/net/getnameinfo.c
diff options
context:
space:
mode:
Diffstat (limited to 'lib/libc/net/getnameinfo.c')
-rw-r--r--lib/libc/net/getnameinfo.c42
1 files changed, 23 insertions, 19 deletions
diff --git a/lib/libc/net/getnameinfo.c b/lib/libc/net/getnameinfo.c
index 005b877..d7e7971 100644
--- a/lib/libc/net/getnameinfo.c
+++ b/lib/libc/net/getnameinfo.c
@@ -78,6 +78,8 @@ getnameinfo(const struct sockaddr *sa, socklen_t salen,
char *host, size_t hostlen, char *serv, size_t servlen,
int flags)
{
+ if (sa == NULL)
+ return (EAI_FAIL);
switch (sa->sa_family) {
case AF_INET:
@@ -124,25 +126,19 @@ getnameinfo_inet(const struct sockaddr *sa, socklen_t salen,
struct servent *sp;
struct hostent *hp;
u_short port;
- int family, i;
const char *addr;
u_int32_t v4a;
int h_error;
char numserv[512];
char numaddr[512];
- if (sa == NULL)
- return EAI_FAIL;
-
- family = sa->sa_family;
- for (i = 0; afdl[i].a_af; i++)
- if (afdl[i].a_af == family) {
- afd = &afdl[i];
- goto found;
- }
- return EAI_FAMILY;
+ for (afd = &afdl[0]; afd->a_af > 0; afd++) {
+ if (afd->a_af == sa->sa_family)
+ break;
+ }
+ if (afd->a_af == 0)
+ return (EAI_FAMILY);
- found:
if (salen != afd->a_socklen)
return EAI_FAIL;
@@ -394,11 +390,22 @@ getnameinfo_link(const struct sockaddr *sa, socklen_t salen,
if (sdl->sdl_nlen == 0 && sdl->sdl_alen == 0 && sdl->sdl_slen == 0) {
n = snprintf(host, hostlen, "link#%d", sdl->sdl_index);
- if (n > hostlen) {
+ if (n >= hostlen) {
*host = '\0';
- return EAI_MEMORY;
+ return (EAI_MEMORY);
+ }
+ return (0);
+ }
+
+ if (sdl->sdl_nlen > 0 && sdl->sdl_alen == 0) {
+ n = sdl->sdl_nlen;
+ if (n >= hostlen) {
+ *host = '\0';
+ return (EAI_MEMORY);
}
- return 0;
+ memcpy(host, sdl->sdl_data, sdl->sdl_nlen);
+ host[n] = '\0';
+ return (0);
}
switch (sdl->sdl_type) {
@@ -440,10 +447,7 @@ getnameinfo_link(const struct sockaddr *sa, socklen_t salen,
}
static int
-hexname(cp, len, host, hostlen)
- const u_int8_t *cp;
- char *host;
- size_t len, hostlen;
+hexname(const u_int8_t *cp, size_t len, char *host, size_t hostlen)
{
int i, n;
char *outp = host;
OpenPOWER on IntegriCloud