Commit a70c568b authored by Jiri Popelka's avatar Jiri Popelka

lib/inet6.c:INET6_rresolve() - various fixes

1) Fall-back to numeric address if getnameinfo fails.
   Reverse lookup is not mandatory, therefore its fail
   is not an error. Just return numeric address in that case.
   This makes netstat/route show IPv6 address instead of
   [UNKNOWN] in case of DNS problems.

2) Pass length of 'name' buffer into function.
   'name' is a pointer and therefore sizeof(name)
   returns size of pointer and not size of the buffer.
   see http://stackoverflow.com/questions/14298710/c-pointers-and-arrays-sizeof-operator
   The sizeof() usage was added with commit 604785ad,
   so I checked all the other changes in that commit
   and they seem to be OK.

3) remove unused 's' variable
parent a753a904
......@@ -84,10 +84,9 @@ static int INET6_resolve(char *name, struct sockaddr_in6 *sin6)
#endif
static int INET6_rresolve(char *name, struct sockaddr_in6 *sin6, int numeric)
static int INET6_rresolve(char *name, size_t namelen,
struct sockaddr_in6 *sin6, int numeric)
{
int s;
/* Grmpf. -FvK */
if (sin6->sin6_family != AF_INET6) {
#ifdef DEBUG
......@@ -98,21 +97,20 @@ static int INET6_rresolve(char *name, struct sockaddr_in6 *sin6, int numeric)
return (-1);
}
if (numeric & 0x7FFF) {
inet_ntop( AF_INET6, &sin6->sin6_addr, name, 80);
inet_ntop( AF_INET6, &sin6->sin6_addr, name, namelen);
return (0);
}
if (IN6_IS_ADDR_UNSPECIFIED(&sin6->sin6_addr)) {
if (numeric & 0x8000)
safe_strncpy(name, "default", sizeof(name));
safe_strncpy(name, "default", namelen);
else
safe_strncpy(name, "[::]", sizeof(name));
safe_strncpy(name, "[::]", namelen);
return (0);
}
if ((s = getnameinfo((struct sockaddr *) sin6, sizeof(struct sockaddr_in6),
name, 255 /* !! */ , NULL, 0, 0))) {
fputs("getnameinfo failed\n", stderr);
return -1;
if (getnameinfo((struct sockaddr *) sin6, sizeof(struct sockaddr_in6),
name, namelen , NULL, 0, 0)) {
inet_ntop( AF_INET6, &sin6->sin6_addr, name, namelen);
}
return (0);
}
......@@ -143,7 +141,8 @@ static const char *INET6_sprint(struct sockaddr *sap, int numeric)
if (sap->sa_family == 0xFFFF || sap->sa_family == 0)
return safe_strncpy(buff, _("[NONE SET]"), sizeof(buff));
if (INET6_rresolve(buff, (struct sockaddr_in6 *) sap, numeric) != 0)
if (INET6_rresolve(buff, sizeof(buff),
(struct sockaddr_in6 *) sap, numeric) != 0)
return safe_strncpy(buff, _("[UNKNOWN]"), sizeof(buff));
return (fix_v4_address(buff, &((struct sockaddr_in6 *)sap)->sin6_addr));
}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment