[PATCH 2/2] ws2_32: Fix implementation of InetNtopW.
Philipp Hoppermann
plata at mailbox.org
Fri Jul 22 07:04:16 CDT 2016
Replaced call to inet_ntop by more elaborate solution.
Signed-off-by: Philipp Hoppermann <plata at mailbox.org>
---
dlls/ws2_32/socket.c | 72 +++++++++++++++++++++++++++++++++++++++++++++++++---
1 file changed, 68 insertions(+), 4 deletions(-)
diff --git a/dlls/ws2_32/socket.c b/dlls/ws2_32/socket.c
index 0622060..2045163 100644
--- a/dlls/ws2_32/socket.c
+++ b/dlls/ws2_32/socket.c
@@ -7934,11 +7934,75 @@ INT WINAPI InetPtonW(INT family, PCWSTR addr, PVOID buffer)
}
/***********************************************************************
-* InetNtopW (WS2_32.@)
-*/
-PCWSTR WINAPI InetNtopW(INT family, PVOID addr, PWSTR stringBuf, SIZE_T stringBufSize)
+ * InetNtopW (WS2_32.@)
+ *
+ * Get string representation of IP address.
+ *
+ * PARAMS
+ * family [I] AF_INET or AF_INET6
+ * addr [I] IP address in byte
+ * buffer [O] IP address as string
+ * buffer_len [O] length of the buffer in characters
+ *
+ * RETURNS
+ * Success: IP address as string
+ * Failure: NULL. Use GetLastError() to find the error cause.
+ *
+ * Error codes:
+ * WSAEAFNOSUPPORT
+ * - family is not AF_INET or AF_INET6
+ * ERROR_INVALID_PARAMETER
+ * - buffer is NULL
+ * - buffer_len is 0
+ * - buffer_len is too small
+ * (i.e. < 16 for AF_INET or < 46 for AF_INET6)
+ *
+ */
+PCWSTR WINAPI InetNtopW(INT family, PVOID addr, PWSTR buffer, SIZE_T buffer_len)
{
- return inet_ntop(family, addr, stringBuf, stringBufSize);
+ char *bufferA;
+
+ TRACE("family %d, addr %s, buffer (%p), buffer_len %lu\n", family, debugstr_w(addr), buffer, (unsigned long) buffer_len);
+
+ // check family
+ if ((family != AF_INET) && (family != AF_INET6))
+ {
+ SetLastError(WSAEAFNOSUPPORT);
+ return NULL;
+ }
+
+ // check if buffer is NULL
+ if (buffer == NULL)
+ {
+ SetLastError(ERROR_INVALID_PARAMETER);
+ return NULL;
+ }
+
+ // check buffer_len
+ if ((family == AF_INET && buffer_len < 16) || (family == AF_INET6 && buffer_len < 46))
+ {
+ SetLastError(ERROR_INVALID_PARAMETER);
+ return NULL;
+ }
+
+ // allocate memory for the string representation in char
+ if (!(bufferA = HeapAlloc(GetProcessHeap(), 0, buffer_len*sizeof(WCHAR))))
+ {
+ SetLastError(WSA_NOT_ENOUGH_MEMORY);
+ return NULL;
+ }
+
+ if (WS_inet_ntop(family, addr, bufferA, buffer_len*sizeof(WCHAR)) != NULL)
+ {
+ // convert to wchar
+ MultiByteToWideChar(CP_ACP, 0, bufferA, buffer_len*sizeof(WCHAR), buffer, buffer_len);
+
+ HeapFree(GetProcessHeap(), 0, bufferA);
+ return buffer;
+ } else
+ {
+ return NULL;
+ }
}
/***********************************************************************
--
2.7.4
More information about the wine-patches
mailing list