win32 inet_top
authorAndy Green <andy.green@linaro.org>
Wed, 2 Apr 2014 13:31:07 +0000 (21:31 +0800)
committerAndy Green <andy.green@linaro.org>
Wed, 2 Apr 2014 13:31:07 +0000 (21:31 +0800)
Signed-off-by: Andy Green <andy.green@linaro.org>
lib/lws-plat-win.c
lib/private-libwebsockets.h

index c9d7b4b..585c610 100644 (file)
@@ -308,4 +308,30 @@ lws_plat_open_file(const char* filename, unsigned long* filelen)
                *filelen = GetFileSize(ret, NULL);
 
        return ret;
+}
+
+/* 
+ * 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)
+{ 
+       struct sockaddr_in srcaddr;
+       DWORD rv;
+
+       memset(&srcaddr, 0, sizeof(struct sockaddr_in));
+       memcpy(&(srcaddr.sin_addr), src, sizeof(srcaddr.sin_addr));
+
+       srcaddr.sin_family = af;
+       if (!WSAAddressToString((struct sockaddr*) &srcaddr,
+                           sizeof(struct sockaddr_in), 0, dst, (LPDWORD) &cnt))
+               return dst;
+
+       rv = WSAGetLastError();
+       lwsl_err("WSAAddressToString() : %d\n",rv);
+
+       return NULL;
 }
\ No newline at end of file
index 1a58dd8..cfc61c0 100644 (file)
@@ -83,6 +83,7 @@
 #include <winsock2.h>
 #include <windows.h>
 #define LWS_INVALID_FILE INVALID_HANDLE_VALUE
+const char *inet_ntop(int af, const void *src, char *dst, int cnt);
 #else /* not windows --> */
 #include <errno.h>
 #include <fcntl.h>