From e5f26443afc24ea6eee1d60c8bc1f689c34283b7 Mon Sep 17 00:00:00 2001 From: Con Kolivas Date: Fri, 28 Nov 2014 00:31:57 +1100 Subject: [PATCH] Make url from sockaddr take port as a char --- src/libckpool.c | 11 +++++++---- src/libckpool.h | 2 +- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/src/libckpool.c b/src/libckpool.c index 499e66be..7f3f350f 100644 --- a/src/libckpool.c +++ b/src/libckpool.c @@ -408,9 +408,11 @@ bool extract_sockaddr(char *url, char **sockaddr_url, char **sockaddr_port) } /* Convert a sockaddr structure into a url and port. URL should be a string of - * INET6_ADDRSTRLEN size */ -bool url_from_sockaddr(const struct sockaddr *addr, char *url, int *port_no) + * INET6_ADDRSTRLEN size, port at least a string of 6 bytes */ +bool url_from_sockaddr(const struct sockaddr *addr, char *url, char *port) { + int port_no = 0; + switch(addr->sa_family) { const struct sockaddr_in *inet4_in; const struct sockaddr_in6 *inet6_in; @@ -418,16 +420,17 @@ bool url_from_sockaddr(const struct sockaddr *addr, char *url, int *port_no) case AF_INET: inet4_in = (struct sockaddr_in *)url; inet_ntop(AF_INET, &inet4_in->sin_addr, url, INET6_ADDRSTRLEN); - *port_no = htons(inet4_in->sin_port); + port_no = htons(inet4_in->sin_port); break; case AF_INET6: inet6_in = (struct sockaddr_in6 *)url; inet_ntop(AF_INET6, &inet6_in->sin6_addr, url, INET6_ADDRSTRLEN); - *port_no = htons(inet6_in->sin6_port); + port_no = htons(inet6_in->sin6_port); break; default: return false; } + sprintf(port, "%d", port_no); return true; } diff --git a/src/libckpool.h b/src/libckpool.h index fba59562..ecd9465d 100644 --- a/src/libckpool.h +++ b/src/libckpool.h @@ -422,7 +422,7 @@ static inline bool sock_timeout(void) } bool extract_sockaddr(char *url, char **sockaddr_url, char **sockaddr_port); -bool url_from_sockaddr(const struct sockaddr *addr, char *url, int *port_no); +bool url_from_sockaddr(const struct sockaddr *addr, char *url, char *port); void keep_sockalive(int fd); void nolinger_socket(int fd); void noblock_socket(int fd);