diff options
author | fanquake <fanquake@gmail.com> | 2024-04-09 10:17:58 +0200 |
---|---|---|
committer | fanquake <fanquake@gmail.com> | 2024-04-09 10:21:27 +0200 |
commit | 71f96c274f52786eb2d95f0f5e837113014c8360 (patch) | |
tree | bc4c02894dd59d14d39e6230d738dd655e3b4d38 | |
parent | a160a6a08103ed2dbb42ad92c03a6f3de33add1d (diff) | |
parent | 03b87a3e64305ba651e22a730e35271dea8fea64 (diff) |
Merge bitcoin/bitcoin#29786: Drop Windows Socket dependency for `randomenv.cpp`
03b87a3e64305ba651e22a730e35271dea8fea64 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 03b87a3e64305ba651e22a730e35271dea8fea64.
laanwj:
Code review ACK 03b87a3e64305ba651e22a730e35271dea8fea64.
fanquake:
ACK 03b87a3e64305ba651e22a730e35271dea8fea64
Tree-SHA512: a4abd5499176634d5f3fbf4e794a7504c40232fb73bd7f41955fbfb2cc7c44bc7ea4518c5203836e52f552c30414c6c3e1b24f0922641dbf1c8377981c0ffaf0
-rw-r--r-- | src/randomenv.cpp | 10 |
1 files changed, 10 insertions, 0 deletions
diff --git a/src/randomenv.cpp b/src/randomenv.cpp index da81a61651..123b5cc06c 100644 --- a/src/randomenv.cpp +++ b/src/randomenv.cpp @@ -13,6 +13,7 @@ #include <compat/compat.h> #include <compat/cpuid.h> #include <crypto/sha512.h> +#include <span.h> #include <support/cleanse.h> #include <util/time.h> @@ -357,10 +358,19 @@ void RandAddStaticEnv(CSHA512& hasher) hasher << &hasher << &RandAddStaticEnv << &malloc << &errno << &environ; // Hostname +#ifdef WIN32 + constexpr DWORD max_size = MAX_COMPUTERNAME_LENGTH + 1; + char hname[max_size]; + DWORD size = max_size; + if (GetComputerNameA(hname, &size) != 0) { + hasher.Write(UCharCast(hname), size); + } +#else char hname[256]; if (gethostname(hname, 256) == 0) { hasher.Write((const unsigned char*)hname, strnlen(hname, 256)); } +#endif #if HAVE_DECL_GETIFADDRS && HAVE_DECL_FREEIFADDRS // Network interfaces |