From 9bde5b906521316c7529097657486c5d8a2a6968 Mon Sep 17 00:00:00 2001 From: travisladuke Date: Thu, 14 Mar 2024 14:09:32 -0700 Subject: [PATCH] Consider ::ffff:127.0.0.1 as a loopback address cpp-httplib sets IPV6_V6ONLY to false on it's sockets. On FreeBSD, this makes all ipv4 addresses get get prefixed with ::ffff: it makes them IPv6 addresses mapped to v4. This is a partial fix for #2151. The cli will work again. Something should probably also be adjusted with the httplib. If you want to, for example, use the `allowManagementFrom` option in local.conf you will need to prefix it with "::ffff:", "::ffff:1.2.3.4" which is a little surprising and inconsistent between BSD and other OSs. --- node/InetAddress.cpp | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/node/InetAddress.cpp b/node/InetAddress.cpp index da1c7294cb..dcde34ec9c 100644 --- a/node/InetAddress.cpp +++ b/node/InetAddress.cpp @@ -132,7 +132,20 @@ InetAddress::IpScope InetAddress::ipScope() const return IP_SCOPE_PRIVATE; // fc00::/7 } } + + // :::ffff:127.0.0.1 + // 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0xff, 0xff, 0x7f, 0, 0, 1 unsigned int k = 0; + while ((!ip[k])&&(k < 9)) { + ++k; + } + if (k == 9) { + if (ip[10] == 0xff && ip[11] == 0xff && ip[12] == 0x7f) { + return IP_SCOPE_LOOPBACK; + } + } + + k = 0; while ((!ip[k])&&(k < 15)) { ++k; }