Merge pull request #86 from obnoxxx/getipstring1

honor result of inet_ntop in get_ip_string()
This commit is contained in:
Michael Adam 2017-03-30 00:52:43 +02:00 committed by GitHub
commit cb6f868739
2 changed files with 9 additions and 5 deletions

View File

@ -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;
}
/*

View File

@ -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