1
0
Fork 0
mirror of https://github.com/warmcat/libwebsockets.git synced 2025-03-16 00:00:07 +01:00

win32 inet_top

Signed-off-by: Andy Green <andy.green@linaro.org>
This commit is contained in:
Andy Green 2014-04-02 21:31:07 +08:00
parent 0651e500d4
commit 5266f66f50
2 changed files with 27 additions and 0 deletions

View 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;
}

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