ws2_32: Implement GetHostNameW.

Wine-Bug: https://bugs.winehq.org/show_bug.cgi?id=49286
Signed-off-by: Hans Leidekker <hans@codeweavers.com>
Signed-off-by: Alexandre Julliard <julliard@winehq.org>
This commit is contained in:
Hans Leidekker 2021-04-11 21:55:40 +02:00 committed by Alexandre Julliard
parent 6f7d8a7315
commit 998e5eaddb
4 changed files with 61 additions and 0 deletions

View File

@ -7224,6 +7224,36 @@ int WINAPI WS_gethostname(char *name, int namelen)
return 0;
}
/***********************************************************************
* GetHostNameW (WS2_32.@)
*/
int WINAPI GetHostNameW(WCHAR *name, int namelen)
{
char buf[256];
int len;
TRACE("name %p, len %d\n", name, namelen);
if (!name)
{
SetLastError(WSAEFAULT);
return SOCKET_ERROR;
}
if (gethostname(buf, sizeof(buf)))
{
SetLastError(wsaErrno());
return SOCKET_ERROR;
}
if ((len = MultiByteToWideChar(CP_ACP, 0, buf, -1, NULL, 0)) > namelen)
{
SetLastError(WSAEFAULT);
return SOCKET_ERROR;
}
MultiByteToWideChar(CP_ACP, 0, buf, -1, name, namelen);
return 0;
}
/* ------------------------------------- Windows sockets extensions -- *
* *

View File

@ -4323,6 +4323,34 @@ static void test_gethostname(void)
ok(he != NULL, "gethostbyname(\"%s\") failed: %d\n", name, WSAGetLastError());
}
static void test_GetHostNameW(void)
{
WCHAR name[256];
int ret, len;
WSASetLastError(0xdeadbeef);
ret = GetHostNameW(NULL, 256);
ok(ret == -1, "GetHostNameW() returned %d\n", ret);
ok(WSAGetLastError() == WSAEFAULT, "GetHostNameW with null buffer "
"failed with %d, expected %d\n", WSAGetLastError(), WSAEFAULT);
ret = GetHostNameW(name, sizeof(name));
ok(ret == 0, "GetHostNameW() call failed: %d\n", WSAGetLastError());
len = wcslen(name);
WSASetLastError(0xdeadbeef);
wcscpy(name, L"deadbeef");
ret = GetHostNameW(name, len);
ok(ret == -1, "GetHostNameW() returned %d\n", ret);
ok(!wcscmp(name, L"deadbeef"), "name changed unexpected!\n");
ok(WSAGetLastError() == WSAEFAULT, "GetHostNameW with insufficient length "
"failed with %d, expected %d\n", WSAGetLastError(), WSAEFAULT);
len++;
ret = GetHostNameW(name, len);
ok(ret == 0, "GetHostNameW() call failed: %d\n", WSAGetLastError());
}
static void test_inet_addr(void)
{
u_long addr;
@ -10631,6 +10659,7 @@ START_TEST( sock )
test_gethostbyname();
test_gethostbyname_hack();
test_gethostname();
test_GetHostNameW();
test_WSASendMsg();
test_WSASendTo();

View File

@ -57,6 +57,7 @@
@ stdcall GetAddrInfoExOverlappedResult(ptr)
@ stdcall GetAddrInfoExW(wstr wstr long ptr ptr ptr ptr ptr ptr ptr)
@ stdcall GetAddrInfoW(wstr wstr ptr ptr)
@ stdcall GetHostNameW(ptr long)
@ stdcall GetNameInfoW(ptr long ptr long ptr long long)
@ stdcall InetNtopW(long ptr ptr long)
@ stdcall InetPtonW(long wstr ptr)

View File

@ -695,6 +695,7 @@ typedef SOCKET (WINAPI *LPFN_SOCKET)(int,int,int);
* "Winsock2 Function Typedefs" section below.
*/
#if WS_API_PROTOTYPES
int WINAPI GetHostNameW(WCHAR *, int);
SOCKET WINAPI WSAAccept(SOCKET,struct WS(sockaddr)*,LPINT,LPCONDITIONPROC,DWORD_PTR);
INT WINAPI WSAAddressToStringA(LPSOCKADDR,DWORD,LPWSAPROTOCOL_INFOA,LPSTR,LPDWORD);
INT WINAPI WSAAddressToStringW(LPSOCKADDR,DWORD,LPWSAPROTOCOL_INFOW,LPWSTR,LPDWORD);