Inside Bitcoin
Opening the selected file…
Opening the selected file…
The code behind the network, with room to understand it.
Release published 2026-10-28 · Snapshot fetched 2026-11-01. Latest stable release at fetch time; development branches and Git history are excluded. Only the selected code window and visible folders load here.
251# endif252# endif253# ifdef CTL_VM254# ifdef VM_LOADAVG255AddSysctl<CTL_VM, VM_LOADAVG>(hasher);256# endif257# ifdef VM_TOTAL258AddSysctl<CTL_VM, VM_TOTAL>(hasher);259# endif260# ifdef VM_METER261AddSysctl<CTL_VM, VM_METER>(hasher);262# endif263# endif264#endif266// Stack and heap location267void* addr = malloc(4097);268hasher << &addr << addr;269free(addr);270}272void RandAddStaticEnv(CSHA512& hasher)273{274// Some compile-time static properties275hasher << (CHAR_MIN < 0) << sizeof(void*) << sizeof(long) << sizeof(int);276#if defined(__GNUC__) && defined(__GNUC_MINOR__) && defined(__GNUC_PATCHLEVEL__)277hasher << __GNUC__ << __GNUC_MINOR__ << __GNUC_PATCHLEVEL__;278#endif279#ifdef _MSC_VER280hasher << _MSC_VER;281#endif282hasher << __cplusplus;283#ifdef _XOPEN_VERSION284hasher << _XOPEN_VERSION;285#endif286#ifdef __VERSION__287const char* COMPILER_VERSION = __VERSION__;288hasher.Write((const unsigned char*)COMPILER_VERSION, strlen(COMPILER_VERSION) + 1);289#endif291// Bitcoin client version292hasher << CLIENT_VERSION;294#if defined(HAVE_STRONG_GETAUXVAL)295// Information available through getauxval()296# ifdef AT_HWCAP297hasher << getauxval(AT_HWCAP);298# endif299# ifdef AT_HWCAP2300hasher << getauxval(AT_HWCAP2);301# endif302# ifdef AT_RANDOM303const unsigned char* random_aux = (const unsigned char*)getauxval(AT_RANDOM);304if (random_aux) hasher.Write(random_aux, 16);305# endif306# ifdef AT_PLATFORM307const char* platform_str = (const char*)getauxval(AT_PLATFORM);308if (platform_str) hasher.Write((const unsigned char*)platform_str, strlen(platform_str) + 1);309# endif310# ifdef AT_EXECFN311const char* exec_str = (const char*)getauxval(AT_EXECFN);312if (exec_str) hasher.Write((const unsigned char*)exec_str, strlen(exec_str) + 1);313# endif314#endif // HAVE_STRONG_GETAUXVAL316#ifdef HAVE_GETCPUID317AddAllCPUID(hasher);318#endif320// Memory locations321hasher << &hasher << &RandAddStaticEnv << &malloc << &errno << &environ;323// Hostname324#ifdef WIN32325constexpr DWORD max_size = MAX_COMPUTERNAME_LENGTH + 1;326char hname[max_size];327DWORD size = max_size;328if (GetComputerNameA(hname, &size) != 0) {329hasher.Write(UCharCast(hname), size);330}331#else332char hname[256];333if (gethostname(hname, 256) == 0) {334hasher.Write((const unsigned char*)hname, strnlen(hname, 256));335}336#endif338#ifdef HAVE_IFADDRS339// Network interfaces340struct ifaddrs *ifad = nullptr;341getifaddrs(&ifad);342struct ifaddrs *ifit = ifad;343while (ifit != nullptr) {344hasher.Write((const unsigned char*)&ifit, sizeof(ifit));345hasher.Write((const unsigned char*)ifit->ifa_name, strlen(ifit->ifa_name) + 1);346hasher.Write((const unsigned char*)&ifit->ifa_flags, sizeof(ifit->ifa_flags));347AddSockaddr(hasher, ifit->ifa_addr);348AddSockaddr(hasher, ifit->ifa_netmask);349AddSockaddr(hasher, ifit->ifa_dstaddr);350ifit = ifit->ifa_next;351}352freeifaddrs(ifad);353#endif355#ifndef WIN32356// UNIX kernel information357struct utsname name;358if (uname(&name) != -1) {359hasher.Write((const unsigned char*)&name.sysname, strlen(name.sysname) + 1);360hasher.Write((const unsigned char*)&name.nodename, strlen(name.nodename) + 1);361hasher.Write((const unsigned char*)&name.release, strlen(name.release) + 1);362hasher.Write((const unsigned char*)&name.version, strlen(name.version) + 1);363hasher.Write((const unsigned char*)&name.machine, strlen(name.machine) + 1);364}366/* Path and filesystem provided data */367AddPath(hasher, "/");368AddPath(hasher, ".");369AddPath(hasher, "/tmp");370AddPath(hasher, "/home");371AddPath(hasher, "/proc");372#ifdef __linux__373AddFile(hasher, "/proc/cmdline");374AddFile(hasher, "/proc/cpuinfo");375AddFile(hasher, "/proc/version");376#endif377AddFile(hasher, "/etc/passwd");378AddFile(hasher, "/etc/group");379AddFile(hasher, "/etc/hosts");380AddFile(hasher, "/etc/resolv.conf");381AddFile(hasher, "/etc/timezone");382AddFile(hasher, "/etc/localtime");383#endif385// For MacOS/BSDs, gather data through sysctl instead of /proc. Not all of these386// will exist on every system.387#ifdef HAVE_SYSCTL388# ifdef CTL_HW389# ifdef HW_MACHINE390AddSysctl<CTL_HW, HW_MACHINE>(hasher);391# endif392# ifdef HW_MODEL393AddSysctl<CTL_HW, HW_MODEL>(hasher);394# endif395# ifdef HW_NCPU396AddSysctl<CTL_HW, HW_NCPU>(hasher);397# endif398# ifdef HW_PHYSMEM399AddSysctl<CTL_HW, HW_PHYSMEM>(hasher);400# endif401# ifdef HW_USERMEM402AddSysctl<CTL_HW, HW_USERMEM>(hasher);403# endif404# ifdef HW_MACHINE_ARCH405AddSysctl<CTL_HW, HW_MACHINE_ARCH>(hasher);406# endif407# ifdef HW_REALMEM408AddSysctl<CTL_HW, HW_REALMEM>(hasher);409# endif410# ifdef HW_CPU_FREQ411AddSysctl<CTL_HW, HW_CPU_FREQ>(hasher);412# endif413# ifdef HW_BUS_FREQ414AddSysctl<CTL_HW, HW_BUS_FREQ>(hasher);415# endif416# ifdef HW_CACHELINE417AddSysctl<CTL_HW, HW_CACHELINE>(hasher);418# endif419# endif420# ifdef CTL_KERN421# ifdef KERN_BOOTFILE422AddSysctl<CTL_KERN, KERN_BOOTFILE>(hasher);423# endif424# ifdef KERN_BOOTTIME425AddSysctl<CTL_KERN, KERN_BOOTTIME>(hasher);426# endif427# ifdef KERN_CLOCKRATE428AddSysctl<CTL_KERN, KERN_CLOCKRATE>(hasher);429# endif430# ifdef KERN_HOSTID431AddSysctl<CTL_KERN, KERN_HOSTID>(hasher);432# endif433# ifdef KERN_HOSTUUID434AddSysctl<CTL_KERN, KERN_HOSTUUID>(hasher);435# endif436# ifdef KERN_HOSTNAME437AddSysctl<CTL_KERN, KERN_HOSTNAME>(hasher);438# endif439# ifdef KERN_OSRELDATE440AddSysctl<CTL_KERN, KERN_OSRELDATE>(hasher);441# endif442# ifdef KERN_OSRELEASE443AddSysctl<CTL_KERN, KERN_OSRELEASE>(hasher);444# endif445# ifdef KERN_OSREV446AddSysctl<CTL_KERN, KERN_OSREV>(hasher);447# endif448# ifdef KERN_OSTYPE449AddSysctl<CTL_KERN, KERN_OSTYPE>(hasher);450# endif451# ifdef KERN_POSIX1452AddSysctl<CTL_KERN, KERN_OSREV>(hasher);453# endif454# ifdef KERN_VERSION455AddSysctl<CTL_KERN, KERN_VERSION>(hasher);456# endif457# endif458#endif460// Env variables461if (environ) {462for (size_t i = 0; environ[i]; ++i) {463hasher.Write((const unsigned char*)environ[i], strlen(environ[i]));464}465}467// Process, thread, user, session, group, ... ids.468#ifdef WIN32469hasher << GetCurrentProcessId() << GetCurrentThreadId();470#else471hasher << getpid() << getppid() << getsid(0) << getpgid(0) << getuid() << geteuid() << getgid() << getegid();472#endif473hasher << std::this_thread::get_id();474}
Independent explanations by MyBitcoinExplorer. Not affiliated with or endorsed by Bitcoin Core. Guides are educational and do not replace the source or its tests.
Bitcoin Core source © its contributors, distributed under the MIT license. Original notices and bundled third-party licenses are retained in the source tree.