]> git.ipfire.org Git - thirdparty/squid.git/commitdiff
Author: Henrik Nordstrom <henrik@henriknordstrom.net>
authorAmos Jeffries <squid3@treenet.co.nz>
Mon, 1 Mar 2010 10:17:37 +0000 (23:17 +1300)
committerAmos Jeffries <squid3@treenet.co.nz>
Mon, 1 Mar 2010 10:17:37 +0000 (23:17 +1300)
Migrate various IpAddress internal constants to private static members

src/ip/IpAddress.cc
src/ip/IpAddress.h

index 75c8d97bd24bc6953eb3596896c9a757b52938ac..58081c9f38e208657e8f8efe4543b6a2fda70874 100644 (file)
 #  define s6_addr      s_addr
 #endif
 
-static const unsigned int STRLEN_IP4A = 16;              // aaa.bbb.ccc.ddd\0
-static const unsigned int STRLEN_IP4R = 28;              // ddd.ccc.bbb.aaa.in-addr.arpa.\0
-static const unsigned int STRLEN_IP4S = 21;              // ddd.ccc.bbb.aaa:ppppp\0
-static const unsigned int MAX_IP4_STRLEN = STRLEN_IP4R;
-static const unsigned int STRLEN_IP6A = 42;           // [ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff]/0
-static const unsigned int STRLEN_IP6R = 75;           // f.f.f.f f.f.f.f f.f.f.f f.f.f.f f.f.f.f f.f.f.f f.f.f.f f.f.f.f ipv6.arpa./0
-static const unsigned int STRLEN_IP6S = 48;           // [ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff]:00000/0
-static const unsigned int MAX_IP6_STRLEN = STRLEN_IP6R;
-
-
 /* Debugging only. Dump the address content when a fatal assert is encountered. */
 #if USE_IPV6
 #define IASSERT(a,b)  \
@@ -291,23 +281,29 @@ void IpAddress::SetEmpty()
     memset(&m_SocketAddr, 0, sizeof(m_SocketAddr) );
 }
 
+#if USE_IPV6
+const struct in6_addr IpAddress::v4_localhost = {{{ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+            0x00, 0x00, 0xff, 0xff, 0x7f, 0x00, 0x00, 0x01 }}
+};
+const struct in6_addr IpAddress::v4_anyaddr = {{{ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+            0x00, 0x00, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00 }}
+};
+const struct in6_addr IpAddress::v6_noaddr = {{{ 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
+            0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff }}
+};
+#endif
+
+
 bool IpAddress::SetIPv4()
 {
 #if USE_IPV6
-    static const struct in6_addr v4_localhost = {{{ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
-                0x00, 0x00, 0xff, 0xff, 0x7f, 0x00, 0x00, 0x01 }}
-    };
-    static const struct in6_addr v4_any = {{{ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
-                0x00, 0x00, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00 }}
-    };
-
     if ( IsLocalhost() ) {
         m_SocketAddr.sin6_addr = v4_localhost;
         return true;
     }
 
     if ( IsAnyAddr() ) {
-        m_SocketAddr.sin6_addr = v4_any;
+        m_SocketAddr.sin6_addr = v4_anyaddr;
         return true;
     }
 
@@ -324,10 +320,6 @@ bool IpAddress::SetIPv4()
 bool IpAddress::IsLocalhost() const
 {
 #if USE_IPV6
-    static const struct in6_addr v4_localhost = {{{ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
-                0x00, 0x00, 0xff, 0xff, 0x7f, 0x00, 0x00, 0x01 }}
-    };
-
     return IN6_IS_ADDR_LOOPBACK( &m_SocketAddr.sin6_addr ) || IN6_ARE_ADDR_EQUAL( &m_SocketAddr.sin6_addr, &v4_localhost );
 #else
     return (htonl(0x7F000001) == m_SocketAddr.sin_addr.s_addr);
@@ -337,10 +329,8 @@ bool IpAddress::IsLocalhost() const
 void IpAddress::SetLocalhost()
 {
 #if USE_IPV6
-    SetAnyAddr();
-    m_SocketAddr.sin6_addr.s6_addr[15] = 0x1;
+    m_SocketAddr.sin6_addr = in6addr_loopback;
     m_SocketAddr.sin6_family = AF_INET6;
-
 #else
     m_SocketAddr.sin_addr.s_addr = htonl(0x7F000001);
     m_SocketAddr.sin_family = AF_INET;
@@ -351,10 +341,6 @@ bool IpAddress::IsNoAddr() const
 {
     // IFF the address == 0xff..ff (all ones)
 #if USE_IPV6
-    static const struct in6_addr v6_noaddr = {{{ 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
-                0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff }}
-    };
-
     return IN6_ARE_ADDR_EQUAL( &m_SocketAddr.sin6_addr, &v6_noaddr );
 #else
     return 0xFFFFFFFF == m_SocketAddr.sin_addr.s_addr;
@@ -364,10 +350,10 @@ bool IpAddress::IsNoAddr() const
 void IpAddress::SetNoAddr()
 {
 #if USE_IPV6
-    memset(&m_SocketAddr.sin6_addr, 0xFFFFFFFF, sizeof(struct in6_addr) );
+    memset(&m_SocketAddr.sin6_addr, 0xFF, sizeof(struct in6_addr) );
     m_SocketAddr.sin6_family = AF_INET6;
 #else
-    memset(&m_SocketAddr.sin_addr, 0xFFFFFFFF, sizeof(struct in_addr) );
+    memset(&m_SocketAddr.sin_addr, 0xFF, sizeof(struct in_addr) );
     m_SocketAddr.sin_family = AF_INET;
 #endif
 }
index 635cdad4020d624134cf291fa5276e2146452095..446effa48bd6d8d2dbaadd0d981dc1b0ab85dd4d 100644 (file)
@@ -412,6 +412,22 @@ private:
 
     struct sockaddr_in m_SocketAddr;
 #endif
+
+private:
+    /* Internally used constants */
+    static const unsigned int STRLEN_IP4A = 16;              // aaa.bbb.ccc.ddd\0
+    static const unsigned int STRLEN_IP4R = 28;              // ddd.ccc.bbb.aaa.in-addr.arpa.\0
+    static const unsigned int STRLEN_IP4S = 21;              // ddd.ccc.bbb.aaa:ppppp\0
+    static const unsigned int MAX_IP4_STRLEN = STRLEN_IP4R;
+#if USE_IPV6
+    static const unsigned int STRLEN_IP6A = 42;           // [ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff]/0
+    static const unsigned int STRLEN_IP6R = 75;           // f.f.f.f f.f.f.f f.f.f.f f.f.f.f f.f.f.f f.f.f.f f.f.f.f f.f.f.f ipv6.arpa./0
+    static const unsigned int STRLEN_IP6S = 48;           // [ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff]:00000/0
+    static const unsigned int MAX_IP6_STRLEN = STRLEN_IP6R;
+    static const struct in6_addr v4_localhost;
+    static const struct in6_addr v4_anyaddr;
+    static const struct in6_addr v6_noaddr;
+#endif
 };