From f9058616167fb5bcbc94249feac24d45f4b349e1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marc-Andr=C3=A9=20Moreau?= Date: Wed, 8 Jun 2016 10:51:58 -0400 Subject: [PATCH] wayk-now: add missing inet_pton implementation on Windows --- winpr/include/winpr/winsock.h | 3 ++- winpr/libwinpr/winsock/winsock.c | 23 +++++++++++++++++++++++ 2 files changed, 25 insertions(+), 1 deletion(-) diff --git a/winpr/include/winpr/winsock.h b/winpr/include/winpr/winsock.h index 59a893955..22510040d 100644 --- a/winpr/include/winpr/winsock.h +++ b/winpr/include/winpr/winsock.h @@ -64,7 +64,8 @@ #if (_WIN32_WINNT < 0x0600) -PCSTR inet_ntop(INT Family, PVOID pAddr, PSTR pStringBuf, size_t StringBufSize); +WINPR_API PCSTR inet_ntop(INT Family, PVOID pAddr, PSTR pStringBuf, size_t StringBufSize); +WINPR_API INT inet_pton(INT Family, PCSTR pszAddrString, PVOID pAddrBuf); #endif /* (_WIN32_WINNT < 0x0600) */ diff --git a/winpr/libwinpr/winsock/winsock.c b/winpr/libwinpr/winsock/winsock.c index ee80082a7..53a262e0e 100644 --- a/winpr/libwinpr/winsock/winsock.c +++ b/winpr/libwinpr/winsock/winsock.c @@ -262,6 +262,29 @@ PCSTR inet_ntop(INT Family, PVOID pAddr, PSTR pStringBuf, size_t StringBufSize) return NULL; } +INT inet_pton(INT Family, PCSTR pszAddrString, PVOID pAddrBuf) +{ + SOCKADDR_STORAGE addr; + int addr_len = sizeof(addr); + + if ((Family != AF_INET) && (Family != AF_INET6)) + return -1; + + if (WSAStringToAddressA((char*) pszAddrString, Family, NULL, (struct sockaddr*) &addr, &addr_len) != 0) + return 0; + + if (Family == AF_INET) + { + memcpy(pAddrBuf, &((struct sockaddr_in*) &addr)->sin_addr, sizeof(struct in_addr)); + } + else if (Family == AF_INET6) + { + memcpy(pAddrBuf, &((struct sockaddr_in6*) &addr)->sin6_addr, sizeof(struct in6_addr)); + } + + return 1; +} + #endif /* (_WIN32_WINNT < 0x0600) */ #else /* _WIN32 */