5#include <bitcoin-build-config.h>
24#include <linux/netlink.h>
25#include <linux/rtnetlink.h>
26#elif defined(__FreeBSD__)
27#include <netlink/netlink.h>
28#include <netlink/netlink_route.h>
31#elif defined(__APPLE__)
33#include <sys/sysctl.h>
51 switch (addr->sa_family) {
67#if defined(__linux__) || defined(__FreeBSD__)
101 request.hdr.nlmsg_seq = 0;
102 request.data.rtm_family =
family;
103 request.data.rtm_dst_len = 0;
110 request.dst_hdr.nla_type =
RTA_DST;
113 if (sock->Send(&request, request.hdr.nlmsg_len, 0) !=
static_cast<ssize_t>(request.hdr.nlmsg_len)) {
158 if (r->rtm_dst_len != 0) {
214 LogError(
"Could not get best route for default route for interface index %d: %s\n",
228#elif defined(__APPLE__)
230#define ROUNDUP32(a) \
231 ((a) > 0 ? (1 + (((a) - 1) | (sizeof(uint32_t) - 1))) : sizeof(uint32_t))
240 if (
sysctl(
mib,
sizeof(
mib) /
sizeof(
int),
nullptr, &
l,
nullptr, 0) < 0) {
244 std::vector<std::byte> buf(
l);
245 if (
sysctl(
mib,
sizeof(
mib) /
sizeof(
int), buf.data(), &
l,
nullptr, 0) < 0) {
259 for (
int i = 0; i <
RTAX_MAX; i++) {
260 if (
rt->rtm_addrs & (1 << i)) {
314 if (
ret && !
ret->IsBindAny()) {
327 std::vector<std::byte>
out_buf(15000, {});
367#elif defined(HAVE_IFADDRS)
372 if (
ifa->ifa_addr ==
nullptr)
continue;
373 if ((
ifa->ifa_flags &
IFF_UP) == 0)
continue;
376 if (std::optional<CNetAddr> addr =
FromSockAddr(
ifa->ifa_addr, std::nullopt)) {
#define Assume(val)
Assume is the identity function.
A combination of a network address (CNetAddr) and a (TCP) port.
static const PrecomputedData data
Precomputed COutPoint and CCoins values.
std::function< std::unique_ptr< Sock >(int, int, int)> CreateSock
Socket factory.
std::vector< CNetAddr > GetLocalAddresses()
Return all local non-loopback IPv4 and IPv6 network addresses.
std::optional< CNetAddr > QueryDefaultGateway(Network network)
Query the OS for the default gateway for network.
std::string NetworkErrorString(int err)
Return readable error string for a network error code.
constexpr auto Ticks(Dur2 d)
Helper to count the seconds of a duration/time_point.