Skip to content

Commit 03b87a3

Browse files
committed
Drop Windows Socket dependency for randomenv.cpp
This change drops a dependency on the ws2_32 library for our libbitcoinkernel, which may not be desirable.
1 parent 23ba394 commit 03b87a3

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)