From: Henrik Nordstrom Date: Sun, 28 Feb 2010 22:04:23 +0000 (+0100) Subject: Migrate various IpAddress internal constants to private static members X-Git-Tag: SQUID_3_2_0_1~396 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=c0248e1458e6d753522359172c8c4b975d962bda;p=thirdparty%2Fsquid.git Migrate various IpAddress internal constants to private static members --- diff --git a/src/ip/IpAddress.cc b/src/ip/IpAddress.cc index 4fe2711275..02ee726419 100644 --- a/src/ip/IpAddress.cc +++ b/src/ip/IpAddress.cc @@ -67,16 +67,6 @@ # 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 } diff --git a/src/ip/IpAddress.h b/src/ip/IpAddress.h index f3b2c6f6a2..acb74ab67d 100644 --- a/src/ip/IpAddress.h +++ b/src/ip/IpAddress.h @@ -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 };