Skip to content

Commit 71f96c2

Browse files
committed
Merge bitcoin/bitcoin#29786: Drop Windows Socket dependency for randomenv.cpp
03b87a3 Drop Windows Socket dependency for `randomenv.cpp` (Hennadii Stepanov) Pull request description: This change drops a dependency on the ws2_32 library for our libbitcoinkernel by switching to [`GetComputerName`](https://learn.microsoft.com/en-us/windows/win32/api/winbase/nf-winbase-getcomputernamew) function. ACKs for top commit: sipsorcery: utACK 03b87a3. laanwj: Code review ACK 03b87a3. fanquake: ACK 03b87a3 Tree-SHA512: a4abd5499176634d5f3fbf4e794a7504c40232fb73bd7f41955fbfb2cc7c44bc7ea4518c5203836e52f552c30414c6c3e1b24f0922641dbf1c8377981c0ffaf0
2 parents a160a6a + 03b87a3 commit 71f96c2

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

src/randomenv.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
#include <compat/compat.h>
1414
#include <compat/cpuid.h>
1515
#include <crypto/sha512.h>
16+
#include <span.h>
1617
#include <support/cleanse.h>
1718
#include <util/time.h>
1819

@@ -357,10 +358,19 @@ void RandAddStaticEnv(CSHA512& hasher)
357358
hasher << &hasher << &RandAddStaticEnv << &malloc << &errno << &environ;
358359

359360
// Hostname
361+
#ifdef WIN32
362+
constexpr DWORD max_size = MAX_COMPUTERNAME_LENGTH + 1;
363+
char hname[max_size];
364+
DWORD size = max_size;
365+
if (GetComputerNameA(hname, &size) != 0) {
366+
hasher.Write(UCharCast(hname), size);
367+
}
368+
#else
360369
char hname[256];
361370
if (gethostname(hname, 256) == 0) {
362371
hasher.Write((const unsigned char*)hname, strnlen(hname, 256));
363372
}
373+
#endif
364374

365375
#if HAVE_DECL_GETIFADDRS && HAVE_DECL_FREEIFADDRS
366376
// Network interfaces

0 commit comments

Comments
 (0)