[PATCH 2/2] ws2_32: Reimplement inet_pton on top of ntdll functions
Alex Henrie
alexhenrie24 at gmail.com
Mon May 18 22:22:13 CDT 2020
And add a test to show that inet_pton does not accept hexadecimal IPv4
addresses, and another test to demonstrate that it has the same leading
double colon bug as RtlIpv6StringToAddress.
Signed-off-by: Alex Henrie <alexhenrie24 at gmail.com>
---
configure.ac | 1 -
dlls/ws2_32/socket.c | 23 ++++++++++-------------
dlls/ws2_32/tests/sock.c | 6 +++++-
3 files changed, 15 insertions(+), 15 deletions(-)
diff --git a/configure.ac b/configure.ac
index b7916fcca7..8ddeb0710a 100644
--- a/configure.ac
+++ b/configure.ac
@@ -2247,7 +2247,6 @@ AC_CHECK_FUNCS(\
inet_addr \
inet_network \
inet_ntop \
- inet_pton \
)
dnl Check for clock_gettime which may be in -lrt
diff --git a/dlls/ws2_32/socket.c b/dlls/ws2_32/socket.c
index d57fc9ecd2..95992f4906 100644
--- a/dlls/ws2_32/socket.c
+++ b/dlls/ws2_32/socket.c
@@ -8394,10 +8394,10 @@ PCSTR WINAPI WS_inet_ntop( INT family, PVOID addr, PSTR buffer, SIZE_T len )
/***********************************************************************
* inet_pton (WS2_32.@)
*/
-INT WINAPI WS_inet_pton( INT family, PCSTR addr, PVOID buffer)
+INT WINAPI WS_inet_pton(INT family, const char *addr, void *buffer)
{
-#ifdef HAVE_INET_PTON
- int unixaf, ret;
+ NTSTATUS status;
+ const char *terminator;
TRACE("family %d, addr %s, buffer (%p)\n", family, debugstr_a(addr), buffer);
@@ -8407,21 +8407,18 @@ INT WINAPI WS_inet_pton( INT family, PCSTR addr, PVOID buffer)
return SOCKET_ERROR;
}
- unixaf = convert_af_w2u(family);
- if (unixaf != AF_INET && unixaf != AF_INET6)
+ switch (family)
{
+ case WS_AF_INET:
+ status = RtlIpv4StringToAddressA(addr, TRUE, &terminator, buffer);
+ case WS_AF_INET6:
+ status = RtlIpv6StringToAddressA(addr, &terminator, buffer);
+ default:
SetLastError(WSAEAFNOSUPPORT);
return SOCKET_ERROR;
}
- ret = inet_pton(unixaf, addr, buffer);
- if (ret == -1) SetLastError(wsaErrno());
- return ret;
-#else
- FIXME( "not supported on this platform\n" );
- SetLastError( WSAEAFNOSUPPORT );
- return SOCKET_ERROR;
-#endif
+ return (status == STATUS_SUCCESS && *terminator == 0);
}
/***********************************************************************
diff --git a/dlls/ws2_32/tests/sock.c b/dlls/ws2_32/tests/sock.c
index dcbc9377d7..edf184f908 100644
--- a/dlls/ws2_32/tests/sock.c
+++ b/dlls/ws2_32/tests/sock.c
@@ -4993,7 +4993,11 @@ static void test_inet_pton(void)
"\x20\x01\xcd\xba\x00\x00\x00\x00\x00\x00\x00\x00\x32\x57\x96\x52"},
{AF_INET6, 1, 0,
"2001:cdba:0:0:0:0:3257:9652", "2001:cdba::3257:9652",
- "\x20\x01\xcd\xba\x00\x00\x00\x00\x00\x00\x00\x00\x32\x57\x96\x52"}
+ "\x20\x01\xcd\xba\x00\x00\x00\x00\x00\x00\x00\x00\x32\x57\x96\x52"},
+ {AF_INET, 0, 0,
+ "0x12345678", NULL, NULL},
+ {AF_INET6, 0, 0, /* windows bug */
+ "::1:2:3:4:5:6:7", NULL, NULL},
};
int i, ret;
DWORD err;
--
2.26.2
More information about the wine-devel
mailing list