diff --git a/lib/libwebsockets.c b/lib/libwebsockets.c index d537aa4e..588e6088 100644 --- a/lib/libwebsockets.c +++ b/lib/libwebsockets.c @@ -50,6 +50,7 @@ lws_plat_service(struct libwebsocket_context *context, int timeout_ms); int lws_plat_init_fd_tables(struct libwebsocket_context *context); void lws_plat_drop_app_privileges(struct lws_context_creation_info *info); unsigned long long time_in_microseconds(void); +const char *lws_plat_inet_ntop(int af, const void *src, char *dst, int cnt); #ifdef LWS_USE_LIBEV #define _LWS_EV_TAG " libev" @@ -503,15 +504,14 @@ libwebsockets_get_peer_addresses(struct libwebsocket_context *context, goto bail; } - if (inet_ntop(AF_INET6, &sin6.sin6_addr, rip, rip_len) == NULL) { - perror("inet_ntop"); + if (!lws_plat_inet_ntop(AF_INET6, &sin6.sin6_addr, rip, rip_len)) { + lwsl_err("inet_ntop", strerror(LWS_ERRNO)); goto bail; } // Strip off the IPv4 to IPv6 header if one exists - if (strncmp(rip, "::ffff:", 7) == 0) { + if (strncmp(rip, "::ffff:", 7) == 0) memmove(rip, rip + 7, strlen(rip) - 6); - } getnameinfo((struct sockaddr *)&sin6, sizeof(struct sockaddr_in6), name, diff --git a/lib/lws-plat-unix.c b/lib/lws-plat-unix.c index 2c8fd9d6..27758d78 100644 --- a/lib/lws-plat-unix.c +++ b/lib/lws-plat-unix.c @@ -476,4 +476,11 @@ lws_plat_open_file(const char* filename, unsigned long* filelen) fstat(ret, &stat_buf); *filelen = stat_buf.st_size; return ret; -} \ No newline at end of file +} +#ifdef LWS_USE_IPV6 +LWS_VISIBLE const char * +lws_plat_inet_ntop(int af, const void *src, char *dst, int cnt) +{ + return inet_ntop(af, src, dst, cnt); +} +#endif \ No newline at end of file diff --git a/lib/lws-plat-win.c b/lib/lws-plat-win.c index 585c6100..6c231203 100644 --- a/lib/lws-plat-win.c +++ b/lib/lws-plat-win.c @@ -310,14 +310,15 @@ lws_plat_open_file(const char* filename, unsigned long* filelen) return ret; } +#ifdef LWS_USE_IPV6 /* * Windows doesn't have an "inet_top" * This came from http://memset.wordpress.com/2010/10/09/inet_ntop-for-win32/ * suggested by Joakim Soderberg */ -LWS_VISIBLE -const char *inet_ntop(int af, const void *src, char *dst, int cnt) +LWS_VISIBLE const char * +lws_plat_inet_ntop(int af, const void *src, char *dst, int cnt) { struct sockaddr_in srcaddr; DWORD rv; @@ -334,4 +335,5 @@ const char *inet_ntop(int af, const void *src, char *dst, int cnt) lwsl_err("WSAAddressToString() : %d\n",rv); return NULL; -} \ No newline at end of file +} +#endif \ No newline at end of file