https://git.reactos.org/?p=reactos.git;a=commitdiff;h=454de56c6b8ca47b47e6e…
commit 454de56c6b8ca47b47e6ec21f7d9a8f2715673b2
Author: Baruch Rutman <peterooch(a)gmail.com>
AuthorDate: Sat Apr 20 22:30:01 2024 +0300
Commit: Hermès BÉLUSCA - MAÏTO <hermes.belusca-maito(a)reactos.org>
CommitDate: Sat Nov 2 21:57:28 2024 +0100
[WS2_32] Add inet_pton, inet_ntop
---
dll/win32/ws2_32/src/addrconv.c | 140 ++++++++++++++++++++++++++++++++++++++++
dll/win32/ws2_32/ws2_32.spec | 4 ++
sdk/include/psdk/ws2tcpip.h | 4 +-
3 files changed, 146 insertions(+), 2 deletions(-)
diff --git a/dll/win32/ws2_32/src/addrconv.c b/dll/win32/ws2_32/src/addrconv.c
index 3cfca497a47..fa459a073f3 100644
--- a/dll/win32/ws2_32/src/addrconv.c
+++ b/dll/win32/ws2_32/src/addrconv.c
@@ -492,3 +492,143 @@ WSANtohs(IN SOCKET s,
return SOCKET_ERROR;
}
+PCSTR
+WSAAPI
+inet_ntop(
+ _In_ INT Family,
+ _In_ const VOID *pAddr,
+ _Out_writes_(StringBufSize) PSTR pStringBuf,
+ _In_ size_t StringBufSize)
+{
+ NTSTATUS Status;
+ ULONG BufSize = StringBufSize;
+
+ switch (Family)
+ {
+ case AF_INET:
+ Status = RtlIpv4AddressToStringExA(pAddr, 0, pStringBuf, &BufSize);
+ break;
+ case AF_INET6:
+ Status = RtlIpv6AddressToStringExA(pAddr, 0, 0, pStringBuf, &BufSize);
+ break;
+ default:
+ SetLastError(WSAEAFNOSUPPORT);
+ return NULL;
+ }
+
+ if (!NT_SUCCESS(Status))
+ {
+ SetLastError(WSAEINVAL);
+ return NULL;
+ }
+
+ return pStringBuf;
+}
+
+PCWSTR
+WSAAPI
+InetNtopW(
+ _In_ INT Family,
+ _In_ const VOID *pAddr,
+ _Out_writes_(StringBufSize) PWSTR pStringBuf,
+ _In_ size_t StringBufSize)
+{
+ NTSTATUS Status;
+ ULONG BufSize = StringBufSize;
+
+ switch (Family)
+ {
+ case AF_INET:
+ Status = RtlIpv4AddressToStringExW(pAddr, 0, pStringBuf, &BufSize);
+ break;
+ case AF_INET6:
+ Status = RtlIpv6AddressToStringExW(pAddr, 0, 0, pStringBuf, &BufSize);
+ break;
+ default:
+ SetLastError(WSAEAFNOSUPPORT);
+ return NULL;
+ }
+
+ if (!NT_SUCCESS(Status))
+ {
+ SetLastError(WSAEINVAL);
+ return NULL;
+ }
+
+ return pStringBuf;
+}
+
+INT
+WSAAPI
+inet_pton(
+ _In_ INT Family,
+ _In_ PCSTR pszAddrString,
+ _Out_writes_bytes_(sizeof(IN_ADDR6)) PVOID pAddrBuf)
+{
+ NTSTATUS Status;
+ PCSTR ch;
+
+ if (!pszAddrString || !pAddrBuf)
+ {
+ SetLastError(WSAEFAULT);
+ return -1;
+ }
+
+ switch (Family)
+ {
+ case AF_INET:
+ Status = RtlIpv4StringToAddressA(pszAddrString, TRUE, &ch, pAddrBuf);
+ break;
+ case AF_INET6:
+ Status = RtlIpv6StringToAddressA(pszAddrString, &ch, pAddrBuf);
+ break;
+ default:
+ SetLastError(WSAEAFNOSUPPORT);
+ return -1;
+ }
+
+ if (!NT_SUCCESS(Status) || (*ch != 0))
+ {
+ return 0;
+ }
+
+ return 1;
+}
+
+INT
+WSAAPI
+InetPtonW(
+ _In_ INT Family,
+ _In_ PCWSTR pszAddrString,
+ _Out_writes_bytes_(sizeof(IN_ADDR6)) PVOID pAddrBuf)
+{
+ NTSTATUS Status;
+ PCWSTR ch;
+
+ if (!pszAddrString || !pAddrBuf)
+ {
+ SetLastError(WSAEFAULT);
+ return -1;
+ }
+
+ switch (Family)
+ {
+ case AF_INET:
+ Status = RtlIpv4StringToAddressW(pszAddrString, TRUE, &ch, pAddrBuf);
+ break;
+ case AF_INET6:
+ Status = RtlIpv6StringToAddressW(pszAddrString, &ch, pAddrBuf);
+ break;
+ default:
+ SetLastError(WSAEAFNOSUPPORT);
+ return -1;
+ }
+
+ if (!NT_SUCCESS(Status) || (*ch != 0))
+ {
+ SetLastError(WSAEINVAL); /* Only unicode version sets this error */
+ return 0;
+ }
+
+ return 1;
+}
diff --git a/dll/win32/ws2_32/ws2_32.spec b/dll/win32/ws2_32/ws2_32.spec
index e0e14b7e68e..84e5680349e 100644
--- a/dll/win32/ws2_32/ws2_32.spec
+++ b/dll/win32/ws2_32/ws2_32.spec
@@ -115,3 +115,7 @@
23 stdcall socket(long long long)
@ stdcall GetAddrInfoW(wstr wstr ptr ptr)
@ stdcall GetNameInfoW(ptr long wstr long wstr long long)
+@ stdcall -version=0x600+ inet_ntop(long ptr ptr long)
+@ stdcall -version=0x600+ InetNtopW(long ptr ptr long)
+@ stdcall -version=0x600+ inet_pton(long str ptr)
+@ stdcall -version=0x600+ InetPtonW(long wstr ptr)
diff --git a/sdk/include/psdk/ws2tcpip.h b/sdk/include/psdk/ws2tcpip.h
index 8d8aaa75add..b28e89c9bef 100644
--- a/sdk/include/psdk/ws2tcpip.h
+++ b/sdk/include/psdk/ws2tcpip.h
@@ -451,7 +451,7 @@ PCSTR
WSAAPI
inet_ntop(
_In_ INT Family,
- _In_ PVOID pAddr,
+ _In_ const VOID *pAddr,
_Out_writes_(StringBufSize) PSTR pStringBuf,
_In_ size_t StringBufSize);
@@ -459,7 +459,7 @@ PCWSTR
WSAAPI
InetNtopW(
_In_ INT Family,
- _In_ PVOID pAddr,
+ _In_ const VOID *pAddr,
_Out_writes_(StringBufSize) PWSTR pStringBuf,
_In_ size_t StringBufSize);