Skip to content

Commit

Permalink
Merge bitcoin#29786: Drop Windows Socket dependency for randomenv.cpp
Browse files Browse the repository at this point in the history
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
  • Loading branch information
fanquake authored and PastaPastaPasta committed Oct 26, 2024
1 parent 1a8e805 commit 4ecb761
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions src/randomenv.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
#include <clientversion.h>
#include <compat/cpuid.h>
#include <crypto/sha512.h>
#include <span.h>
#include <support/cleanse.h>
#include <util/time.h> // for GetTime()
#ifdef WIN32
Expand Down Expand Up @@ -358,10 +359,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
Expand Down

0 comments on commit 4ecb761

Please sign in to comment.