From 7796a3118d7b4f58752fad0ca5f676dcafd7a76c Mon Sep 17 00:00:00 2001 From: rubenwardy Date: Sun, 3 Feb 2019 12:31:55 +0000 Subject: Disable confirmation dialog on localhost --- src/network/address.cpp | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) (limited to 'src/network/address.cpp') diff --git a/src/network/address.cpp b/src/network/address.cpp index f698a2e91..0ecface37 100644 --- a/src/network/address.cpp +++ b/src/network/address.cpp @@ -271,3 +271,19 @@ void Address::print(std::ostream *s) const else *s << serializeString() << ":" << m_port; } + +bool Address::isLocalhost() const { + if (isIPv6()) { + static const unsigned char localhost_bytes[] = { + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1}; + static const unsigned char mapped_ipv4_localhost[] = { + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0xff, 0xff, 0x7f, 0, 0, 1}; + + auto addr = m_address.ipv6.sin6_addr.s6_addr; + + return memcmp(addr, localhost_bytes, 16) == 0 || + memcmp(addr, mapped_ipv4_localhost, 16) == 0; + } else { + return m_address.ipv4.sin_addr.s_addr == 0x0100007F; + } +} -- cgit v1.2.3