]> git.lizzy.rs Git - minetest.git/blobdiff - src/network/address.cpp
Translated using Weblate (Chinese (Simplified))
[minetest.git] / src / network / address.cpp
index 0ecface37f4776e9ab01111b4c73ac49370e85f4..05678aa62cc865a2fb8c46a623a5b5b857e1cc84 100644 (file)
@@ -272,18 +272,19 @@ void Address::print(std::ostream *s) const
                *s << serializeString() << ":" << m_port;
 }
 
-bool Address::isLocalhost() const {
+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};
+                               0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0xff, 0xff, 0x7f, 0, 0, 0};
 
                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;
+                       memcmp(addr, mapped_ipv4_localhost, 13) == 0;
        }
+
+       return (m_address.ipv4.sin_addr.s_addr & 0xFF) == 0x7f;
 }