]> git.ipfire.org Git - thirdparty/squid.git/commitdiff
Migrate various IpAddress internal constants to private static members
authorHenrik Nordstrom <henrik@henriknordstrom.net>
Sun, 28 Feb 2010 22:04:23 +0000 (23:04 +0100)
committerHenrik Nordstrom <henrik@henriknordstrom.net>
Sun, 28 Feb 2010 22:04:23 +0000 (23:04 +0100)
src/ip/IpAddress.cc
src/ip/IpAddress.h

index 4fe2711275add4161a7d0c4d6b0999769abb4f05..02ee726419ff14db78949df5fb433d8f16661489 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)  \
@@ -283,23 +273,29 @@ void IpAddress::SetEmpty()
     memset(&m_SocketAddr, 0, sizeof(m_SocketAddr) );
 }
 
-bool IpAddress::SetIPv4()
-{
 #if USE_IPV6
-    static const struct in6_addr v4_localhost = {{{ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+const struct in6_addr IpAddress::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 }}
-    };
+};
+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
     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;
     }
 
@@ -316,10 +312,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);
@@ -363,10 +355,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;
@@ -376,10 +364,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 f3b2c6f6a26f5afcab1443f69ea101cbd3eac49f..acb74ab67d80a5e55b6022cc3e1969b8c0147402 100644 (file)
@@ -426,6 +426,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
 };