Merge bitcoin/bitcoin#35667: refactor: Use NetworkErrorString for macOS code in netif.cpp

eccb04a321 refactor: Use `NetworkErrorString` for macOS code in `netif.cpp` (Hennadii Stepanov)

Pull request description:

  Although these `sysctl` calls report generic system errors rather than network errors, `NetworkErrorString()` is identical to `SysErrorString()` on POSIX systems, so this does not change behavior. It allows removing `#include <util/syserror.h>`, which was only needed by `__APPLE__` code and would otherwise require an `#ifdef` guard to silence an IWYU unused-include warning on other platforms.

  Related to https://github.com/bitcoin/bitcoin/pull/34995.

ACKs for top commit:
  sedited:
    ACK eccb04a321

Tree-SHA512: 25838dcf206f728fb0968a9ff336863870b69f857436a47b9916269e624d0f157bd566b461911dfea69716de482bbde6903d51bb97e6f70631dfcd274390ac3d
This commit is contained in:
merge-script
2026-07-07 09:51:58 +01:00

View File

@@ -10,7 +10,6 @@
#include <util/check.h>
#include <util/log.h>
#include <util/sock.h>
#include <util/syserror.h>
#if defined(__linux__)
#include <linux/rtnetlink.h>
@@ -238,12 +237,12 @@ std::optional<CNetAddr> QueryDefaultGatewayImpl(sa_family_t family)
// The size of the available data is determined by calling sysctl() with oldp=nullptr. See sysctl(3).
size_t l = 0;
if (sysctl(/*name=*/mib, /*namelen=*/sizeof(mib) / sizeof(int), /*oldp=*/nullptr, /*oldlenp=*/&l, /*newp=*/nullptr, /*newlen=*/0) < 0) {
LogError("Could not get sysctl length of routing table: %s\n", SysErrorString(errno));
LogError("Could not get sysctl length of routing table: %s\n", NetworkErrorString(errno));
return std::nullopt;
}
std::vector<std::byte> buf(l);
if (sysctl(/*name=*/mib, /*namelen=*/sizeof(mib) / sizeof(int), /*oldp=*/buf.data(), /*oldlenp=*/&l, /*newp=*/nullptr, /*newlen=*/0) < 0) {
LogError("Could not get sysctl data of routing table: %s\n", SysErrorString(errno));
LogError("Could not get sysctl data of routing table: %s\n", NetworkErrorString(errno));
return std::nullopt;
}
// Iterate over messages (each message is a routing table entry).