summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorMichael Adam <obnox@samba.org>2017-03-30 00:52:43 +0200
committerGitHub <noreply@github.com>2017-03-30 00:52:43 +0200
commitcb6f86873916a96bd2acfa8bf5dda0e17e1a019a (patch)
tree17ad35178ccf867280c7a4e835f45eefba506fd8
parentf149b6247538f9820be1e8c43d2600e446f8f105 (diff)
parent46cbe5357cc65e748171ea476b79c70d73976324 (diff)
Merge pull request #86 from obnoxxx/getipstring1
honor result of inet_ntop in get_ip_string()
-rw-r--r--src/network.c12
-rw-r--r--src/network.h2
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