network: honour result of inet_ntop in get_ip_string()

Signed-off-by: Michael Adam <obnox@samba.org>
This commit is contained in:
Michael Adam 2016-12-21 02:18:30 +01:00
parent a71cebb094
commit 46cbe5357c

View File

@ -251,6 +251,8 @@ CLEANUP:
*/ */
const char *get_ip_string (struct sockaddr *sa, char *buf, size_t buflen) const char *get_ip_string (struct sockaddr *sa, char *buf, size_t buflen)
{ {
const char *result;
assert (sa != NULL); assert (sa != NULL);
assert (buf != NULL); assert (buf != NULL);
assert (buflen != 0); assert (buflen != 0);
@ -261,7 +263,8 @@ const char *get_ip_string (struct sockaddr *sa, char *buf, size_t buflen)
{ {
struct sockaddr_in *sa_in = (struct sockaddr_in *) sa; struct sockaddr_in *sa_in = (struct sockaddr_in *) sa;
inet_ntop (AF_INET, &sa_in->sin_addr, buf, buflen); result = inet_ntop (AF_INET, &sa_in->sin_addr, buf,
buflen);
break; break;
} }
case AF_INET6: case AF_INET6:
@ -269,7 +272,8 @@ const char *get_ip_string (struct sockaddr *sa, char *buf, size_t buflen)
struct sockaddr_in6 *sa_in6 = struct sockaddr_in6 *sa_in6 =
(struct sockaddr_in6 *) sa; (struct sockaddr_in6 *) sa;
inet_ntop (AF_INET6, &sa_in6->sin6_addr, buf, buflen); result = inet_ntop (AF_INET6, &sa_in6->sin6_addr, buf,
buflen);
break; break;
} }
default: default:
@ -277,7 +281,7 @@ const char *get_ip_string (struct sockaddr *sa, char *buf, size_t buflen)
return NULL; return NULL;
} }
return buf; return result;
} }
/* /*