Use GetComputerName instead of gethostname

This commit is contained in:
Armin Novak 2022-03-15 15:19:41 +01:00 committed by akallabeth
parent 98f9aedd62
commit e5b50c550b
2 changed files with 7 additions and 2 deletions

View File

@ -29,6 +29,7 @@
#include <string.h>
#include <winpr/crt.h>
#include <winpr/sysinfo.h>
#include <winpr/assert.h>
#include <winpr/stream.h>
@ -1170,7 +1171,10 @@ static UINT rdpdr_send_client_name_request(rdpdrPlugin* rdpdr)
WINPR_ASSERT(rdpdr);
if (!rdpdr->computerName[0])
gethostname(rdpdr->computerName, sizeof(rdpdr->computerName) - 1);
{
DWORD size = sizeof(rdpdr->computerName) - 1;
GetComputerNameA(rdpdr->computerName, &size);
}
computerNameLenW = ConvertToUnicode(CP_UTF8, 0, rdpdr->computerName, -1, &computerNameW, 0) * 2;
WINPR_ASSERT(computerNameLenW >= 0);

View File

@ -431,7 +431,8 @@ rdpSettings* freerdp_settings_new(DWORD flags)
{
char ClientHostname[33] = { 0 };
gethostname(ClientHostname, 31);
DWORD size = sizeof(ClientHostname) - 2;
GetComputerNameA(ClientHostname, &size);
if (!freerdp_settings_set_string(settings, FreeRDP_ClientHostname, ClientHostname))
goto out_fail;
}