aboutsummaryrefslogtreecommitdiff
path: root/src/netbase.cpp
diff options
context:
space:
mode:
authorMatthew Zipkin <pinheadmz@gmail.com>2023-05-26 14:21:43 -0400
committerMatthew Zipkin <pinheadmz@gmail.com>2024-03-01 14:47:28 -0500
commita89c3f59dc44eaf4f59912c1accfc0ce5d61933a (patch)
tree5817d50b52af28681ce91187d18d76e021e45c27 /src/netbase.cpp
parent3a7d6548effa6cd9a4a5413b690c2fd85da4ef65 (diff)
downloadbitcoin-a89c3f59dc44eaf4f59912c1accfc0ce5d61933a.tar.xz
netbase: extend Proxy class to wrap UNIX socket as well as TCP
Diffstat (limited to 'src/netbase.cpp')
-rw-r--r--src/netbase.cpp18
1 files changed, 18 insertions, 0 deletions
diff --git a/src/netbase.cpp b/src/netbase.cpp
index 93a84a73b0..d3c3c36b37 100644
--- a/src/netbase.cpp
+++ b/src/netbase.cpp
@@ -216,6 +216,24 @@ CService LookupNumeric(const std::string& name, uint16_t portDefault, DNSLookupF
return Lookup(name, portDefault, /*fAllowLookup=*/false, dns_lookup_function).value_or(CService{});
}
+bool IsUnixSocketPath(const std::string& name)
+{
+#if HAVE_SOCKADDR_UN
+ if (name.find(ADDR_PREFIX_UNIX) != 0) return false;
+
+ // Split off "unix:" prefix
+ std::string str{name.substr(ADDR_PREFIX_UNIX.length())};
+
+ // Path size limit is platform-dependent
+ // see https://manpages.ubuntu.com/manpages/xenial/en/man7/unix.7.html
+ if (str.size() + 1 > sizeof(((sockaddr_un*)nullptr)->sun_path)) return false;
+
+ return true;
+#else
+ return false;
+#endif
+}
+
/** SOCKS version */
enum SOCKSVersion: uint8_t {
SOCKS4 = 0x04,