diff options
author | Michael Adam <obnox@samba.org> | 2017-03-30 00:52:43 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-03-30 00:52:43 +0200 |
commit | cb6f86873916a96bd2acfa8bf5dda0e17e1a019a (patch) | |
tree | 17ad35178ccf867280c7a4e835f45eefba506fd8 | |
parent | f149b6247538f9820be1e8c43d2600e446f8f105 (diff) | |
parent | 46cbe5357cc65e748171ea476b79c70d73976324 (diff) |
Merge pull request #86 from obnoxxx/getipstring1
honor result of inet_ntop in get_ip_string()
-rw-r--r-- | src/network.c | 12 | ||||
-rw-r--r-- | src/network.h | 2 |
2 files changed, 9 insertions, 5 deletions
diff --git a/src/network.c b/src/network.c index 9caef04..7bae20b 100644 --- a/src/network.c +++ b/src/network.c @@ -249,8 +249,10 @@ CLEANUP: * Convert the network address into either a dotted-decimal or an IPv6 * hex string. */ -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 (buf != NULL); assert (buflen != 0); @@ -261,7 +263,8 @@ char *get_ip_string (struct sockaddr *sa, char *buf, size_t buflen) { 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; } case AF_INET6: @@ -269,7 +272,8 @@ char *get_ip_string (struct sockaddr *sa, char *buf, size_t buflen) struct sockaddr_in6 *sa_in6 = (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; } default: @@ -277,7 +281,7 @@ char *get_ip_string (struct sockaddr *sa, char *buf, size_t buflen) return NULL; } - return buf; + return result; } /* diff --git a/src/network.h b/src/network.h index b6ddaa6..15af481 100644 --- a/src/network.h +++ b/src/network.h @@ -27,7 +27,7 @@ extern ssize_t safe_read (int fd, char *buffer, size_t count); extern int write_message (int fd, const char *fmt, ...); extern ssize_t readline (int fd, char **whole_buffer); -extern char *get_ip_string (struct sockaddr *sa, char *buf, size_t len); +extern const char *get_ip_string (struct sockaddr *sa, char *buf, size_t len); extern int full_inet_pton (const char *ip, void *dst); #endif |