From a71cebb094fc7f4af9b433cb444191de01003ac1 Mon Sep 17 00:00:00 2001 From: Michael Adam Date: Wed, 29 Mar 2017 23:56:48 +0200 Subject: network: let get_ip_string() return const char * instead of const char Signed-off-by: Michael Adam --- src/network.c | 2 +- src/network.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/network.c b/src/network.c index 9caef04..a0c4396 100644 --- a/src/network.c +++ b/src/network.c @@ -249,7 +249,7 @@ 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) { assert (sa != NULL); assert (buf != NULL); 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 -- cgit v1.2.3 From 46cbe5357cc65e748171ea476b79c70d73976324 Mon Sep 17 00:00:00 2001 From: Michael Adam Date: Wed, 21 Dec 2016 02:18:30 +0100 Subject: network: honour result of inet_ntop in get_ip_string() Signed-off-by: Michael Adam --- src/network.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/src/network.c b/src/network.c index a0c4396..7bae20b 100644 --- a/src/network.c +++ b/src/network.c @@ -251,6 +251,8 @@ CLEANUP: */ 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 @@ const 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 @@ const 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 @@ const char *get_ip_string (struct sockaddr *sa, char *buf, size_t buflen) return NULL; } - return buf; + return result; } /* -- cgit v1.2.3