]> git.ipfire.org Git - thirdparty/squid.git/blobdiff - src/ip/Address.cc
SourceFormat Enforcement
[thirdparty/squid.git] / src / ip / Address.cc
index 0dce34d28f49fee11a86bb6ec76911bfd16fb7f1..774e21431d5affec24af6afed5ea16fcd2e52afd 100644 (file)
@@ -1,44 +1,14 @@
 /*
  * DEBUG: section 14    IP Storage and Handling
  * AUTHOR: Amos Jeffries
- *
- * SQUID Internet Object Cache  http://squid.nlanr.net/Squid/
- * ----------------------------------------------------------
- *
- *  Squid is the result of efforts by numerous individuals from the
- *  Internet community.  Development is led by Duane Wessels of the
- *  National Laboratory for Applied Network Research and funded by the
- *  National Science Foundation.  Squid is Copyrighted (C) 1998 by
- *  the Regents of the University of California.  Please see the
- *  COPYRIGHT file for full details.  Squid incorporates software
- *  developed and/or copyrighted by other sources.  Please see the
- *  CREDITS file for full details.
- *
- *  This Ip::Address code is copyright (C) 2007 by Treehouse Networks Ltd
- *  of New Zealand. It is published and Lisenced as an extension of
- *  squid under the same conditions as the main squid application.
- *
- *  This program is free software; you can redistribute it and/or modify
- *  it under the terms of the GNU General Public License as published by
- *  the Free Software Foundation; either version 2 of the License, or
- *  (at your option) any later version.
- *
- *  This program is distributed in the hope that it will be useful,
- *  but WITHOUT ANY WARRANTY; without even the implied warranty of
- *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- *  GNU General Public License for more details.
- *
- *  You should have received a copy of the GNU General Public License
- *  along with this program; if not, write to the Free Software
- *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111, USA.
- *
+ * COPYRIGHT: GPL version 2, (C)2007-2013 Treehouse Networks Ltd.
  */
-
-#include "config.h"
-#include "compat/inet_ntop.h"
+#include "squid.h"
 #include "compat/getaddrinfo.h"
+#include "compat/inet_ntop.h"
 #include "Debug.h"
 #include "ip/Address.h"
+#include "ip/tools.h"
 #include "util.h"
 
 #if HAVE_ASSERT_H
 #include <arpa/inet.h>
 #endif
 
-#ifdef INET6
-#error "INET6 defined but has been deprecated! Try running bootstrap and configure again."
-#endif
-
-#if !USE_IPV6
-//  So there are some places where I will drop to using Macros too.
-//  At least I can restrict them to this file so they don't corrupt the app with C code.
-#  define sin6_addr    sin_addr
-#  define sin6_port    sin_port
-#  define sin6_family  sin_family
-#undef s6_addr
-#  define s6_addr      s_addr
-#endif
-
 /* Debugging only. Dump the address content when a fatal assert is encountered. */
-#if USE_IPV6
 #define IASSERT(a,b)  \
        if(!(b)){       printf("assert \"%s\" at line %d\n", a, __LINE__); \
-               printf("Ip::Address invalid? with IsIPv4()=%c, IsIPv6()=%c\n",(IsIPv4()?'T':'F'),(IsIPv6()?'T':'F')); \
+               printf("Ip::Address invalid? with isIPv4()=%c, isIPv6()=%c\n",(isIPv4()?'T':'F'),(isIPv6()?'T':'F')); \
                printf("ADDRESS:"); \
-               for(unsigned int i = 0; i < sizeof(m_SocketAddr.sin6_addr); i++) { \
-                       printf(" %x", m_SocketAddr.sin6_addr.s6_addr[i]); \
+               for(unsigned int i = 0; i < sizeof(mSocketAddr_.sin6_addr); ++i) { \
+                       printf(" %x", mSocketAddr_.sin6_addr.s6_addr[i]); \
                } printf("\n"); assert(b); \
        }
-#else
-#define IASSERT(a,b)  \
-       if(!(b)){       printf("assert \"%s\" at line %d\n", a, __LINE__); \
-               printf("Ip::Address invalid? with IsIPv4()=%c, IsIPv6()=%c\n",(IsIPv4()?'T':'F'),(IsIPv6()?'T':'F')); \
-               printf("ADDRESS: %x\n", (unsigned int)m_SocketAddr.sin_addr.s_addr); \
-               assert(b); \
-       }
-#endif
-
-Ip::Address::Address()
-{
-    SetEmpty();
-}
-
-Ip::Address::~Address()
-{
-    memset(this,0,sizeof(Ip::Address));
-}
 
 int
-Ip::Address::GetCIDR() const
+Ip::Address::cidr() const
 {
     uint8_t shift,byte;
     uint8_t bit,caught;
     int len = 0;
-#if USE_IPV6
-    const uint8_t *ptr= m_SocketAddr.sin6_addr.s6_addr;
-#else
-    const uint8_t *ptr= (uint8_t *)&m_SocketAddr.sin_addr.s_addr;
-#endif
+    const uint8_t *ptr= mSocketAddr_.sin6_addr.s6_addr;
 
     /* Let's scan all the bits from Most Significant to Least */
     /* Until we find an "0" bit. Then, we return */
     shift=0;
 
-#if USE_IPV6
     /* return IPv4 CIDR for any Mapped address */
     /* Thus only check the mapped bit */
 
-    if ( !IsIPv6() ) {
+    if ( !isIPv6() ) {
         shift = 12;
     }
 
-#endif
-
-    for (; shift<sizeof(m_SocketAddr.sin6_addr) ; shift++) {
+    for (; shift<sizeof(mSocketAddr_.sin6_addr) ; ++shift) {
         byte= *(ptr+shift);
 
         if (byte == 0xFF) {
@@ -129,11 +59,11 @@ Ip::Address::GetCIDR() const
             continue ;  /* A short-cut */
         }
 
-        for (caught = 0 , bit= 7 ; !caught && (bit <= 7); bit--) {
+        for (caught = 0 , bit= 7 ; !caught && (bit <= 7); --bit) {
             caught = ((byte & 0x80) == 0x00);  /* Found a '0' at 'bit' ? */
 
             if (!caught)
-                len++;
+                ++len;
 
             byte <<= 1;
         }
@@ -145,17 +75,17 @@ Ip::Address::GetCIDR() const
     return len;
 }
 
-const int
-Ip::Address::ApplyMask(Ip::Address const &mask_addr)
+int
+Ip::Address::applyMask(Ip::Address const &mask_addr)
 {
-    uint32_t *p1 = (uint32_t*)(&m_SocketAddr.sin6_addr);
-    uint32_t const *p2 = (uint32_t const *)(&mask_addr.m_SocketAddr.sin6_addr);
-    unsigned int blen = sizeof(m_SocketAddr.sin6_addr)/sizeof(uint32_t);
+    uint32_t *p1 = (uint32_t*)(&mSocketAddr_.sin6_addr);
+    uint32_t const *p2 = (uint32_t const *)(&mask_addr.mSocketAddr_.sin6_addr);
+    unsigned int blen = sizeof(mSocketAddr_.sin6_addr)/sizeof(uint32_t);
     unsigned int changes = 0;
 
-    for (unsigned int i = 0; i < blen; i++) {
+    for (unsigned int i = 0; i < blen; ++i) {
         if ((p1[i] & p2[i]) != p1[i])
-            changes++;
+            ++changes;
 
         p1[i] &= p2[i];
     }
@@ -164,53 +94,33 @@ Ip::Address::ApplyMask(Ip::Address const &mask_addr)
 }
 
 bool
-Ip::Address::ApplyMask(const unsigned int cidr, int mtype)
+Ip::Address::applyMask(const unsigned int cidrMask, int mtype)
 {
     uint8_t clearbits = 0;
     uint8_t* p = NULL;
 
-#if !USE_IPV6
-    IASSERT("mtype != AF_INET6", mtype != AF_INET6); /* using IPv6 in IPv4 is invalid. */
-
-    if (mtype == AF_UNSPEC)
-        mtype = AF_INET;
-
-#else
-    if (mtype == AF_UNSPEC)
-        mtype = AF_INET6;
-
-#endif
-
     // validation and short-cuts.
-    if (cidr > 128)
+    if (cidrMask > 128)
         return false;
 
-    if (cidr > 32 && mtype == AF_INET)
+    if (cidrMask > 32 && mtype == AF_INET)
         return false;
 
-    if (cidr == 0) {
+    if (cidrMask == 0) {
         /* CIDR /0 is NoAddr regardless of the IPv4/IPv6 protocol */
-        SetNoAddr();
+        setNoAddr();
         return true;
     }
 
-    clearbits = (uint8_t)( (mtype==AF_INET6?128:32) -cidr);
+    clearbits = (uint8_t)( (mtype==AF_INET6?128:32) - cidrMask);
 
     // short-cut
     if (clearbits == 0)
         return true;
 
-#if USE_IPV6
-
-    p = (uint8_t*)(&m_SocketAddr.sin6_addr) + 15;
-
-#else
+    p = (uint8_t*)(&mSocketAddr_.sin6_addr) + 15;
 
-    p = (uint8_t*)(&m_SocketAddr.sin_addr) + 3;
-
-#endif
-
-    for (; clearbits>0 && p >= (uint8_t*)&m_SocketAddr.sin6_addr ; p-- ) {
+    for (; clearbits>0 && p >= (uint8_t*)&mSocketAddr_.sin6_addr ; --p ) {
         if (clearbits < 8) {
             *p &= ((0xFF << clearbits) & 0xFF);
             clearbits = 0;
@@ -224,60 +134,51 @@ Ip::Address::ApplyMask(const unsigned int cidr, int mtype)
 }
 
 bool
-Ip::Address::IsSockAddr() const
+Ip::Address::isSockAddr() const
 {
-    return (m_SocketAddr.sin6_port != 0);
+    return (mSocketAddr_.sin6_port != 0);
 }
 
 bool
-Ip::Address::IsIPv4() const
+Ip::Address::isIPv4() const
 {
-#if USE_IPV6
-    return IsAnyAddr() || IsNoAddr() || IN6_IS_ADDR_V4MAPPED( &m_SocketAddr.sin6_addr );
-#else
-    return true; // enforce IPv4 in IPv4-only mode.
-#endif
+    return IN6_IS_ADDR_V4MAPPED( &mSocketAddr_.sin6_addr );
 }
 
 bool
-Ip::Address::IsIPv6() const
+Ip::Address::isIPv6() const
 {
-#if USE_IPV6
-    return IsAnyAddr() || IsNoAddr() || !IN6_IS_ADDR_V4MAPPED( &m_SocketAddr.sin6_addr );
-#else
-    return false; // enforce IPv4 in IPv4-only mode.
-#endif
+    return !isIPv4();
 }
 
 bool
-Ip::Address::IsAnyAddr() const
+Ip::Address::isAnyAddr() const
 {
-#if USE_IPV6
-    return IN6_IS_ADDR_UNSPECIFIED( &m_SocketAddr.sin6_addr );
-#else
-    return (INADDR_ANY == m_SocketAddr.sin_addr.s_addr);
-#endif
+    return IN6_IS_ADDR_UNSPECIFIED(&mSocketAddr_.sin6_addr) || IN6_ARE_ADDR_EQUAL(&mSocketAddr_.sin6_addr, &v4_anyaddr);
 }
 
 /// NOTE: Does NOT clear the Port stored. Ony the Address and Type.
 void
-Ip::Address::SetAnyAddr()
+Ip::Address::setAnyAddr()
 {
-#if USE_IPV6
-    memset(&m_SocketAddr.sin6_addr, 0, sizeof(struct in6_addr) );
-#else
-    memset(&m_SocketAddr.sin_addr, 0, sizeof(struct in_addr) );
-#endif
+    memset(&mSocketAddr_.sin6_addr, 0, sizeof(struct in6_addr) );
 }
 
 /// NOTE: completely empties the Ip::Address structure. Address, Port, Type, everything.
 void
-Ip::Address::SetEmpty()
+Ip::Address::setEmpty()
 {
-    memset(&m_SocketAddr, 0, sizeof(m_SocketAddr) );
+    memset(&mSocketAddr_, 0, sizeof(mSocketAddr_) );
 }
 
-#if USE_IPV6
+#if _SQUID_AIX_
+// Bug 2885 comment 78 explains.
+// In short AIX has a different netinet/in.h union definition
+const struct in6_addr Ip::Address::v4_localhost = {{{ 0x00000000, 0x00000000, 0x0000ffff, 0x7f000001 }}};
+const struct in6_addr Ip::Address::v4_anyaddr = {{{ 0x00000000, 0x00000000, 0x0000ffff, 0x00000000 }}};
+const struct in6_addr Ip::Address::v4_noaddr = {{{ 0x00000000, 0x00000000, 0x0000ffff, 0xffffffff }}};
+const struct in6_addr Ip::Address::v6_noaddr = {{{ 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff }}};
+#else
 const struct in6_addr Ip::Address::v4_localhost = {{{ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
             0x00, 0x00, 0xff, 0xff, 0x7f, 0x00, 0x00, 0x01 }}
 };
@@ -292,100 +193,83 @@ const struct in6_addr Ip::Address::v6_noaddr = {{{ 0xff, 0xff, 0xff, 0xff, 0xff,
 };
 #endif
 
-
 bool
-Ip::Address::SetIPv4()
+Ip::Address::setIPv4()
 {
-#if USE_IPV6
-    if ( IsLocalhost() ) {
-        m_SocketAddr.sin6_addr = v4_localhost;
+    if ( isLocalhost() ) {
+        mSocketAddr_.sin6_addr = v4_localhost;
         return true;
     }
 
-    if ( IsAnyAddr() ) {
-        m_SocketAddr.sin6_addr = v4_anyaddr;
+    if ( isAnyAddr() ) {
+        mSocketAddr_.sin6_addr = v4_anyaddr;
         return true;
     }
 
-    if ( IsIPv4())
+    if ( isNoAddr() ) {
+        mSocketAddr_.sin6_addr = v4_noaddr;
+        return true;
+    }
+
+    if ( isIPv4())
         return true;
 
     // anything non-IPv4 and non-convertable is BAD.
     return false;
-#else
-    return true; // Always IPv4 in IPv4-only builds.
-#endif
 }
 
 bool
-Ip::Address::IsLocalhost() const
+Ip::Address::isLocalhost() const
 {
-#if USE_IPV6
-    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);
-#endif
+    return IN6_IS_ADDR_LOOPBACK( &mSocketAddr_.sin6_addr ) || IN6_ARE_ADDR_EQUAL( &mSocketAddr_.sin6_addr, &v4_localhost );
 }
 
 void
-Ip::Address::SetLocalhost()
+Ip::Address::setLocalhost()
 {
-#if USE_IPV6
-    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;
-#endif
+    if (Ip::EnableIpv6) {
+        mSocketAddr_.sin6_addr = in6addr_loopback;
+        mSocketAddr_.sin6_family = AF_INET6;
+    } else {
+        mSocketAddr_.sin6_addr = v4_localhost;
+        mSocketAddr_.sin6_family = AF_INET;
+    }
 }
 
 bool
-Ip::Address::IsSiteLocal6() const
+Ip::Address::isSiteLocal6() const
 {
-#if USE_IPV6
-    return IN6_IS_ADDR_SITELOCAL( &m_SocketAddr.sin6_addr );
-#else
-    return false;
-#endif
+    // RFC 4193 the site-local allocated range is fc00::/7
+    // with fd00::/8 as the only currently allocated range (so we test it first).
+    // BUG: as of 2010-02 Linux and BSD define IN6_IS_ADDR_SITELOCAL() to check for fec::/10
+    return mSocketAddr_.sin6_addr.s6_addr[0] == static_cast<uint8_t>(0xfd) ||
+           mSocketAddr_.sin6_addr.s6_addr[0] == static_cast<uint8_t>(0xfc);
 }
 
 bool
-Ip::Address::IsSlaac() const
+Ip::Address::isSiteLocalAuto() const
 {
-#if USE_IPV6
-    return m_SocketAddr.sin6_addr.s6_addr[10] == htons(0xff) &&
-           m_SocketAddr.sin6_addr.s6_addr[11] == htons(0xfe);
-#else
-    return false;
-#endif
+    return mSocketAddr_.sin6_addr.s6_addr[10] == static_cast<uint8_t>(0xff) &&
+           mSocketAddr_.sin6_addr.s6_addr[11] == static_cast<uint8_t>(0xfe);
 }
 
 bool
-Ip::Address::IsNoAddr() const
+Ip::Address::isNoAddr() const
 {
     // IFF the address == 0xff..ff (all ones)
-#if USE_IPV6
-    return IN6_ARE_ADDR_EQUAL( &m_SocketAddr.sin6_addr, &v6_noaddr );
-#else
-    return 0xFFFFFFFF == m_SocketAddr.sin_addr.s_addr;
-#endif
+    return IN6_ARE_ADDR_EQUAL( &mSocketAddr_.sin6_addr, &v6_noaddr )
+           || IN6_ARE_ADDR_EQUAL( &mSocketAddr_.sin6_addr, &v4_noaddr );
 }
 
 void
-Ip::Address::SetNoAddr()
+Ip::Address::setNoAddr()
 {
-#if USE_IPV6
-    memset(&m_SocketAddr.sin6_addr, 0xFF, sizeof(struct in6_addr) );
-    m_SocketAddr.sin6_family = AF_INET6;
-#else
-    memset(&m_SocketAddr.sin_addr, 0xFF, sizeof(struct in_addr) );
-    m_SocketAddr.sin_family = AF_INET;
-#endif
+    memset(&mSocketAddr_.sin6_addr, 0xFF, sizeof(struct in6_addr) );
+    mSocketAddr_.sin6_family = AF_INET6;
 }
 
-#if USE_IPV6
 bool
-Ip::Address::GetReverseString6(char buf[MAX_IPSTRLEN], const struct in6_addr &dat) const
+Ip::Address::getReverseString6(char buf[MAX_IPSTRLEN], const struct in6_addr &dat) const
 {
     char *p = buf;
     unsigned char const *r = dat.s6_addr;
@@ -400,7 +284,7 @@ Ip::Address::GetReverseString6(char buf[MAX_IPSTRLEN], const struct in6_addr &da
 
     /* Compile Err: 'Too many arguments for format. */
 
-    for (int i = 15; i >= 0; i--, p+=4) {
+    for (int i = 15; i >= 0; --i, p+=4) {
         snprintf(p, 5, "%x.%x.", ((r[i])&0xf), (((r[i])>>4)&0xf) );
     }
 
@@ -410,10 +294,9 @@ Ip::Address::GetReverseString6(char buf[MAX_IPSTRLEN], const struct in6_addr &da
 
     return true;
 }
-#endif
 
 bool
-Ip::Address::GetReverseString4(char buf[MAX_IPSTRLEN], const struct in_addr &dat) const
+Ip::Address::getReverseString4(char buf[MAX_IPSTRLEN], const struct in_addr &dat) const
 {
     unsigned int i = (unsigned int) ntohl(dat.s_addr);
     snprintf(buf, 32, "%u.%u.%u.%u.in-addr.arpa.",
@@ -425,29 +308,21 @@ Ip::Address::GetReverseString4(char buf[MAX_IPSTRLEN], const struct in_addr &dat
 }
 
 bool
-Ip::Address::GetReverseString(char buf[MAX_IPSTRLEN], int show_type) const
+Ip::Address::getReverseString(char buf[MAX_IPSTRLEN], int show_type) const
 {
 
     if (show_type == AF_UNSPEC) {
-#if USE_IPV6
-        show_type = IsIPv6() ? AF_INET6 : AF_INET ;
-#else
-        show_type = AF_INET;
-#endif
+        show_type = isIPv6() ? AF_INET6 : AF_INET ;
     }
 
-    if (show_type == AF_INET && IsIPv4()) {
-#if USE_IPV6
-        struct in_addr* tmp = (struct in_addr*)&m_SocketAddr.sin6_addr.s6_addr[12];
-        return GetReverseString4(buf, *tmp);
-    } else if ( show_type == AF_INET6 && IsIPv6() ) {
-        return GetReverseString6(buf, m_SocketAddr.sin6_addr);
-#else
-        return GetReverseString4(buf, m_SocketAddr.sin_addr);
-#endif
+    if (show_type == AF_INET && isIPv4()) {
+        struct in_addr* tmp = (struct in_addr*)&mSocketAddr_.sin6_addr.s6_addr[12];
+        return getReverseString4(buf, *tmp);
+    } else if ( show_type == AF_INET6 && isIPv6() ) {
+        return getReverseString6(buf, mSocketAddr_.sin6_addr);
     }
 
-    debugs(14,0, "Unable to convert '" << NtoA(buf,MAX_IPSTRLEN) << "' to the rDNS type requested.");
+    debugs(14, DBG_CRITICAL, "Unable to convert '" << toStr(buf,MAX_IPSTRLEN) << "' to the rDNS type requested.");
 
     buf[0] = '\0';
 
@@ -463,48 +338,38 @@ Ip::Address::operator =(const Ip::Address &s)
 
 Ip::Address::Address(const char*s)
 {
-    SetEmpty();
-    operator=(s);
+    setEmpty();
+    lookupHostIP(s, true);
 }
 
 bool
 Ip::Address::operator =(const char* s)
 {
-    return LookupHostIP(s, true);
+    return lookupHostIP(s, true);
 }
 
 bool
 Ip::Address::GetHostByName(const char* s)
 {
-    return LookupHostIP(s, false);
+    return lookupHostIP(s, false);
 }
 
 bool
-Ip::Address::LookupHostIP(const char *s, bool nodns)
+Ip::Address::lookupHostIP(const char *s, bool nodns)
 {
-    int err = 0;
-
-    short port = 0;
-
-    struct addrinfo *res = NULL;
-
     struct addrinfo want;
-
     memset(&want, 0, sizeof(struct addrinfo));
     if (nodns) {
         want.ai_flags = AI_NUMERICHOST; // prevent actual DNS lookups!
     }
-#if !USE_IPV6
-    want.ai_family = AF_INET;
-#endif
 
+    int err = 0;
+    struct addrinfo *res = NULL;
     if ( (err = getaddrinfo(s, NULL, &want, &res)) != 0) {
-        debugs(14,3, HERE << "Given Bad IP '" << s << "': " << gai_strerror(err) );
+        debugs(14,3, HERE << "Given Non-IP '" << s << "': " << gai_strerror(err) );
         /* free the memory getaddrinfo() dynamically allocated. */
-        if (res) {
+        if (res)
             freeaddrinfo(res);
-            res = NULL;
-        }
         return false;
     }
 
@@ -512,98 +377,75 @@ Ip::Address::LookupHostIP(const char *s, bool nodns)
      *  NP: =(sockaddr_*) may alter the port. we don't want that.
      *      all we have been given as input was an IPA.
      */
-    port = GetPort();
+    short portSaved = port();
     operator=(*res);
-    SetPort(port);
+    port(portSaved);
 
     /* free the memory getaddrinfo() dynamically allocated. */
     freeaddrinfo(res);
-
-    res = NULL;
-
     return true;
 }
 
 Ip::Address::Address(struct sockaddr_in const &s)
 {
-    SetEmpty();
+    setEmpty();
     operator=(s);
 };
 
 Ip::Address &
 Ip::Address::operator =(struct sockaddr_in const &s)
 {
-#if USE_IPV6
-    Map4to6((const in_addr)s.sin_addr, m_SocketAddr.sin6_addr);
-    m_SocketAddr.sin6_port = s.sin_port;
-    m_SocketAddr.sin6_family = AF_INET6;
-#else
-
-    memcpy(&m_SocketAddr, &s, sizeof(struct sockaddr_in));
-#endif
-
+    map4to6((const in_addr)s.sin_addr, mSocketAddr_.sin6_addr);
+    mSocketAddr_.sin6_port = s.sin_port;
+    mSocketAddr_.sin6_family = AF_INET6;
     return *this;
 };
 
 Ip::Address &
 Ip::Address::operator =(const struct sockaddr_storage &s)
 {
-#if USE_IPV6
     /* some AF_* magic to tell socket types apart and what we need to do */
     if (s.ss_family == AF_INET6) {
-        memcpy(&m_SocketAddr, &s, sizeof(struct sockaddr_in));
+        memcpy(&mSocketAddr_, &s, sizeof(struct sockaddr_in6));
     } else { // convert it to our storage mapping.
         struct sockaddr_in *sin = (struct sockaddr_in*)&s;
-        m_SocketAddr.sin6_port = sin->sin_port;
-        Map4to6( sin->sin_addr, m_SocketAddr.sin6_addr);
+        mSocketAddr_.sin6_port = sin->sin_port;
+        map4to6( sin->sin_addr, mSocketAddr_.sin6_addr);
     }
-#else
-    memcpy(&m_SocketAddr, &s, sizeof(struct sockaddr_in));
-#endif
     return *this;
 };
 
-#if USE_IPV6
 Ip::Address::Address(struct sockaddr_in6 const &s)
 {
-    SetEmpty();
+    setEmpty();
     operator=(s);
 };
 
 Ip::Address &
 Ip::Address::operator =(struct sockaddr_in6 const &s)
 {
-    memcpy(&m_SocketAddr, &s, sizeof(struct sockaddr_in6));
+    memcpy(&mSocketAddr_, &s, sizeof(struct sockaddr_in6));
 
     return *this;
 };
-#endif
 
 Ip::Address::Address(struct in_addr const &s)
 {
-    SetEmpty();
+    setEmpty();
     operator=(s);
 };
 
 Ip::Address &
 Ip::Address::operator =(struct in_addr const &s)
 {
-#if USE_IPV6
-    Map4to6((const in_addr)s, m_SocketAddr.sin6_addr);
-    m_SocketAddr.sin6_family = AF_INET6;
-
-#else
-
-    memcpy(&m_SocketAddr.sin_addr, &s, sizeof(struct in_addr));
-
-#endif
+    map4to6((const in_addr)s, mSocketAddr_.sin6_addr);
+    mSocketAddr_.sin6_family = AF_INET6;
     return *this;
 };
 
-#if USE_IPV6
 Ip::Address::Address(struct in6_addr const &s)
 {
-    SetEmpty();
+    setEmpty();
     operator=(s);
 };
 
@@ -611,29 +453,21 @@ Ip::Address &
 Ip::Address::operator =(struct in6_addr const &s)
 {
 
-    memcpy(&m_SocketAddr.sin6_addr, &s, sizeof(struct in6_addr));
-    m_SocketAddr.sin6_family = AF_INET6;
+    memcpy(&mSocketAddr_.sin6_addr, &s, sizeof(struct in6_addr));
+    mSocketAddr_.sin6_family = AF_INET6;
 
     return *this;
 };
-#endif
 
 Ip::Address::Address(const Ip::Address &s)
 {
-    SetEmpty();
+    setEmpty();
     operator=(s);
 }
 
-Ip::Address::Address(Ip::Address *s)
-{
-    SetEmpty();
-    if (s)
-        memcpy(this, s, sizeof(Ip::Address));
-}
-
 Ip::Address::Address(const struct hostent &s)
 {
-    SetEmpty();
+    setEmpty();
     operator=(s);
 }
 
@@ -663,17 +497,8 @@ Ip::Address::operator =(const struct hostent &s)
 
     case AF_INET6:
         ipv6 = (in6_addr*)(s.h_addr_list[0]);
-#if USE_IPV6
         /* this */
         operator=(*ipv6);
-#else
-
-        debugs(14,1, HERE << "Discarded IPv6 Address. Protocol disabled.");
-
-        // FIXME see if there is another address in the list that might be usable ??
-        return false;
-#endif
-
         break;
 
     default:
@@ -686,7 +511,7 @@ Ip::Address::operator =(const struct hostent &s)
 
 Ip::Address::Address(const struct addrinfo &s)
 {
-    SetEmpty();
+    setEmpty();
     operator=(s);
 }
 
@@ -720,22 +545,9 @@ Ip::Address::operator =(const struct addrinfo &s)
 
     case AF_INET6:
         ipv6 = (sockaddr_in6*)(s.ai_addr);
-#if USE_IPV6
         /* this */
         assert(ipv6);
         operator=(*ipv6);
-#else
-
-        debugs(14,1, HERE << "Discarded IPv6 Address. Protocol disabled.");
-
-        // see if there is another address in the list that might be usable ??
-
-        if (s.ai_next)
-            return operator=(*s.ai_next);
-        else
-            return false;
-
-#endif
         break;
 
     case AF_UNSPEC:
@@ -743,16 +555,13 @@ Ip::Address::operator =(const struct addrinfo &s)
         // attempt to handle partially initialised addrinfo.
         // such as those where data only comes from getsockopt()
         if (s.ai_addr != NULL) {
-#if USE_IPV6
             if (s.ai_addrlen == sizeof(struct sockaddr_in6)) {
                 operator=(*((struct sockaddr_in6*)s.ai_addr));
                 return true;
-            } else
-#endif
-                if (s.ai_addrlen == sizeof(struct sockaddr_in)) {
-                    operator=(*((struct sockaddr_in*)s.ai_addr));
-                    return true;
-                }
+            } else if (s.ai_addrlen == sizeof(struct sockaddr_in)) {
+                operator=(*((struct sockaddr_in*)s.ai_addr));
+                return true;
+            }
         }
         return false;
     }
@@ -761,7 +570,7 @@ Ip::Address::operator =(const struct addrinfo &s)
 }
 
 void
-Ip::Address::GetAddrInfo(struct addrinfo *&dst, int force) const
+Ip::Address::getAddrInfo(struct addrinfo *&dst, int force) const
 {
     if (dst == NULL) {
         dst = new addrinfo;
@@ -770,7 +579,12 @@ Ip::Address::GetAddrInfo(struct addrinfo *&dst, int force) const
     memset(dst, 0, sizeof(struct addrinfo));
 
     // set defaults
+    // Mac OS X does not emit a flag indicating the output is numeric (IP address)
+#if _SQUID_APPLE_
+    dst->ai_flags = 0;
+#else
     dst->ai_flags = AI_NUMERICHOST;
+#endif
 
     if (dst->ai_socktype == 0)
         dst->ai_socktype = SOCK_STREAM;
@@ -783,13 +597,12 @@ Ip::Address::GetAddrInfo(struct addrinfo *&dst, int force) const
             && dst->ai_protocol == 0)
         dst->ai_protocol = IPPROTO_UDP;
 
-#if USE_IPV6
-    if ( force == AF_INET6 || (force == AF_UNSPEC && IsIPv6()) ) {
+    if (force == AF_INET6 || (force == AF_UNSPEC && Ip::EnableIpv6 && isIPv6()) ) {
         dst->ai_addr = (struct sockaddr*)new sockaddr_in6;
 
         memset(dst->ai_addr,0,sizeof(struct sockaddr_in6));
 
-        GetSockAddr(*((struct sockaddr_in6*)dst->ai_addr));
+        getSockAddr(*((struct sockaddr_in6*)dst->ai_addr));
 
         dst->ai_addrlen = sizeof(struct sockaddr_in6);
 
@@ -809,22 +622,20 @@ Ip::Address::GetAddrInfo(struct addrinfo *&dst, int force) const
         dst->ai_protocol = IPPROTO_IPV6;
 #endif
 
-    } else
-#endif
-        if ( force == AF_INET || (force == AF_UNSPEC && IsIPv4()) ) {
+    } else if ( force == AF_INET || (force == AF_UNSPEC && isIPv4()) ) {
 
-            dst->ai_addr = (struct sockaddr*)new sockaddr_in;
+        dst->ai_addr = (struct sockaddr*)new sockaddr_in;
 
-            memset(dst->ai_addr,0,sizeof(struct sockaddr_in));
+        memset(dst->ai_addr,0,sizeof(struct sockaddr_in));
 
-            GetSockAddr(*((struct sockaddr_in*)dst->ai_addr));
+        getSockAddr(*((struct sockaddr_in*)dst->ai_addr));
 
-            dst->ai_addrlen = sizeof(struct sockaddr_in);
+        dst->ai_addrlen = sizeof(struct sockaddr_in);
 
-            dst->ai_family = ((struct sockaddr_in*)dst->ai_addr)->sin_family;
-        } else {
-            IASSERT("false",false);
-        }
+        dst->ai_family = ((struct sockaddr_in*)dst->ai_addr)->sin_family;
+    } else {
+        IASSERT("false",false);
+    }
 }
 
 void
@@ -865,18 +676,13 @@ Ip::Address::FreeAddrInfo(struct addrinfo *&ai)
 int
 Ip::Address::matchIPAddr(const Ip::Address &rhs) const
 {
-#if USE_IPV6
-    uint8_t *l = (uint8_t*)m_SocketAddr.sin6_addr.s6_addr;
-    uint8_t *r = (uint8_t*)rhs.m_SocketAddr.sin6_addr.s6_addr;
-#else
-    uint8_t *l = (uint8_t*)&m_SocketAddr.sin_addr.s_addr;
-    uint8_t *r = (uint8_t*)&rhs.m_SocketAddr.sin_addr.s_addr;
-#endif
+    uint8_t *l = (uint8_t*)mSocketAddr_.sin6_addr.s6_addr;
+    uint8_t *r = (uint8_t*)rhs.mSocketAddr_.sin6_addr.s6_addr;
 
     // loop a byte-wise compare
     // NP: match MUST be R-to-L : L-to-R produces inconsistent gt/lt results at varying CIDR
     //     expected difference on CIDR is gt/eq or lt/eq ONLY.
-    for (unsigned int i = 0 ; i < sizeof(m_SocketAddr.sin6_addr) ; i++) {
+    for (unsigned int i = 0 ; i < sizeof(mSocketAddr_.sin6_addr) ; ++i) {
 
         if (l[i] < r[i])
             return -1;
@@ -909,7 +715,7 @@ Ip::Address::operator !=(const Ip::Address &s) const
 bool
 Ip::Address::operator <=(const Ip::Address &rhs) const
 {
-    if (IsAnyAddr() && !rhs.IsAnyAddr())
+    if (isAnyAddr() && !rhs.isAnyAddr())
         return true;
 
     return (matchIPAddr(rhs) <= 0);
@@ -918,7 +724,7 @@ Ip::Address::operator <=(const Ip::Address &rhs) const
 bool
 Ip::Address::operator >=(const Ip::Address &rhs) const
 {
-    if (IsNoAddr() && !rhs.IsNoAddr())
+    if (isNoAddr() && !rhs.isNoAddr())
         return true;
 
     return ( matchIPAddr(rhs) >= 0);
@@ -927,7 +733,7 @@ Ip::Address::operator >=(const Ip::Address &rhs) const
 bool
 Ip::Address::operator >(const Ip::Address &rhs) const
 {
-    if (IsNoAddr() && !rhs.IsNoAddr())
+    if (isNoAddr() && !rhs.isNoAddr())
         return true;
 
     return ( matchIPAddr(rhs) > 0);
@@ -936,28 +742,28 @@ Ip::Address::operator >(const Ip::Address &rhs) const
 bool
 Ip::Address::operator <(const Ip::Address &rhs) const
 {
-    if (IsAnyAddr() && !rhs.IsAnyAddr())
+    if (isAnyAddr() && !rhs.isAnyAddr())
         return true;
 
     return ( matchIPAddr(rhs) < 0);
 }
 
-u_short
-Ip::Address::GetPort() const
+unsigned short
+Ip::Address::port() const
 {
-    return ntohs( m_SocketAddr.sin6_port );
+    return ntohs( mSocketAddr_.sin6_port );
 }
 
-u_short
-Ip::Address::SetPort(u_short prt)
+unsigned short
+Ip::Address::port(unsigned short prt)
 {
-    m_SocketAddr.sin6_port = htons(prt);
+    mSocketAddr_.sin6_port = htons(prt);
 
     return prt;
 }
 
 /**
- * NtoA Given a buffer writes a readable ascii version of the IPA and/or port stored
+ * toStr Given a buffer writes a readable ascii version of the IPA and/or port stored
  *
  * Buffer must be of a size large enough to hold the converted address.
  * This size is provided in the form of a global defined variable MAX_IPSTRLEN
@@ -967,7 +773,7 @@ Ip::Address::SetPort(u_short prt)
  * A copy of the buffer is also returned for simple immediate display.
  */
 char *
-Ip::Address::NtoA(char* buf, const unsigned int blen, int force) const
+Ip::Address::toStr(char* buf, const unsigned int blen, int force) const
 {
     // Ensure we have a buffer.
     if (buf == NULL) {
@@ -976,12 +782,11 @@ Ip::Address::NtoA(char* buf, const unsigned int blen, int force) const
 
     /* some external code may have blindly memset a parent. */
     /* thats okay, our default is known */
-    if ( IsAnyAddr() ) {
-#if USE_IPV6
-        memcpy(buf,"::\0", min((const unsigned int)3,blen));
-#else
-        memcpy(buf,"0.0.0.0\0", min((const unsigned int)8,blen));
-#endif
+    if ( isAnyAddr() ) {
+        if (isIPv6())
+            memcpy(buf,"::\0", min(static_cast<unsigned int>(3),blen));
+        else if (isIPv4())
+            memcpy(buf,"0.0.0.0\0", min(static_cast<unsigned int>(8),blen));
         return buf;
     }
 
@@ -989,33 +794,28 @@ Ip::Address::NtoA(char* buf, const unsigned int blen, int force) const
 
     /* Pure-IPv6 CANNOT be displayed in IPv4 format. */
     /* However IPv4 CAN. */
-    if ( force == AF_INET && !IsIPv4() ) {
-        if ( IsIPv6() ) {
-            memcpy(buf, "{!IPv4}\0", min((const unsigned int)8,blen));
+    if ( force == AF_INET && !isIPv4() ) {
+        if ( isIPv6() ) {
+            memcpy(buf, "{!IPv4}\0", min(static_cast<unsigned int>(8),blen));
         }
         return buf;
     }
 
-#if USE_IPV6
-    if ( force == AF_INET6 || (force == AF_UNSPEC && IsIPv6()) ) {
+    if ( force == AF_INET6 || (force == AF_UNSPEC && isIPv6()) ) {
 
-        inet_ntop(AF_INET6, &m_SocketAddr.sin6_addr, buf, blen);
+        inet_ntop(AF_INET6, &mSocketAddr_.sin6_addr, buf, blen);
 
-    } else  if ( force == AF_INET || (force == AF_UNSPEC && IsIPv4()) ) {
+    } else  if ( force == AF_INET || (force == AF_UNSPEC && isIPv4()) ) {
 
         struct in_addr tmp;
-        GetInAddr(tmp);
+        getInAddr(tmp);
         inet_ntop(AF_INET, &tmp, buf, blen);
-#else
-    if ( force == AF_UNSPEC || (force == AF_INET && IsIPv4()) ) {
-        inet_ntop(AF_INET, &m_SocketAddr.sin_addr, buf, blen);
-#endif
     } else {
-        debugs(14,0,"WARNING: Corrupt IP Address details OR required to display in unknown format (" <<
+        debugs(14, DBG_CRITICAL, "WARNING: Corrupt IP Address details OR required to display in unknown format (" <<
                force << "). accepted={" << AF_UNSPEC << "," << AF_INET << "," << AF_INET6 << "}");
         fprintf(stderr,"WARNING: Corrupt IP Address details OR required to display in unknown format (%d). accepted={%d,%d,%d} ",
                 force, AF_UNSPEC, AF_INET, AF_INET6);
-        memcpy(buf,"dead:beef::\0", min((const unsigned int)13,blen));
+        memcpy(buf,"dead:beef::\0", min(static_cast<unsigned int>(13),blen));
         assert(false);
     }
 
@@ -1023,28 +823,28 @@ Ip::Address::NtoA(char* buf, const unsigned int blen, int force) const
 }
 
 unsigned int
-Ip::Address::ToHostname(char *buf, const unsigned int blen) const
+Ip::Address::toHostStr(char *buf, const unsigned int blen) const
 {
     char *p = buf;
 
-    if (IsIPv6() && blen > 0) {
+    if (isIPv6() && blen > 0) {
         *p = '[';
-        p++;
+        ++p;
     }
 
     /* 8 being space for [ ] : and port digits */
-    if ( IsIPv6() )
-        NtoA(p, blen-8, AF_INET6);
+    if ( isIPv6() )
+        toStr(p, blen-8, AF_INET6);
     else
-        NtoA(p, blen-8, AF_INET);
+        toStr(p, blen-8, AF_INET);
 
     // find the end of the new string
     while (*p != '\0' && p < buf+blen)
-        p++;
+        ++p;
 
-    if (IsIPv6() && p < (buf+blen-1) ) {
+    if (isIPv6() && p < (buf+blen-1) ) {
         *p = ']';
-        p++;
+        ++p;
     }
 
     /* terminate just in case. */
@@ -1055,7 +855,7 @@ Ip::Address::ToHostname(char *buf, const unsigned int blen) const
 }
 
 char *
-Ip::Address::ToURL(char* buf, unsigned int blen) const
+Ip::Address::toUrl(char* buf, unsigned int blen) const
 {
     char *p = buf;
 
@@ -1065,11 +865,11 @@ Ip::Address::ToURL(char* buf, unsigned int blen) const
         return NULL;
     }
 
-    p += ToHostname(p, blen);
+    p += toHostStr(p, blen);
 
-    if (m_SocketAddr.sin6_port > 0 && p <= (buf+blen-7) ) {
+    if (mSocketAddr_.sin6_port > 0 && p <= (buf+blen-7) ) {
         // ':port' (short int) needs at most 6 bytes plus 1 for 0-terminator
-        snprintf(p, 7, ":%d", GetPort() );
+        snprintf(p, 7, ":%d", port() );
     }
 
     // force a null-terminated string
@@ -1079,70 +879,51 @@ Ip::Address::ToURL(char* buf, unsigned int blen) const
 }
 
 void
-Ip::Address::GetSockAddr(struct sockaddr_storage &addr, const int family) const
+Ip::Address::getSockAddr(struct sockaddr_storage &addr, const int family) const
 {
     struct sockaddr_in *sin = NULL;
 
-    if ( family == AF_INET && !IsIPv4()) {
+    if ( family == AF_INET && !isIPv4()) {
         // FIXME INET6: caller using the wrong socket type!
-        debugs(14, DBG_CRITICAL, HERE << "Ip::Address::GetSockAddr : Cannot convert non-IPv4 to IPv4. from " << *this);
+        debugs(14, DBG_CRITICAL, HERE << "Ip::Address::getSockAddr : Cannot convert non-IPv4 to IPv4. from " << *this);
         assert(false);
     }
 
-#if USE_IPV6
-    if ( family == AF_INET6 || (family == AF_UNSPEC && IsIPv6()) ) {
+    if ( family == AF_INET6 || (family == AF_UNSPEC && isIPv6()) ) {
         struct sockaddr_in6 *ss6 = (struct sockaddr_in6*)&addr;
-        GetSockAddr(*ss6);
-    } else if ( family == AF_INET || (family == AF_UNSPEC && IsIPv4()) ) {
+        getSockAddr(*ss6);
+    } else if ( family == AF_INET || (family == AF_UNSPEC && isIPv4()) ) {
         sin = (struct sockaddr_in*)&addr;
-        GetSockAddr(*sin);
+        getSockAddr(*sin);
     } else {
         IASSERT("false",false);
     }
-#else /* not USE_IPV6 */
-    sin = (struct sockaddr_in*)&addr;
-    GetSockAddr(*sin);
-#endif /* USE_IPV6 */
 }
 
 void
-Ip::Address::GetSockAddr(struct sockaddr_in &buf) const
+Ip::Address::getSockAddr(struct sockaddr_in &buf) const
 {
-#if USE_IPV6
-
-    if ( IsIPv4() ) {
+    if ( isIPv4() ) {
         buf.sin_family = AF_INET;
-        buf.sin_port = m_SocketAddr.sin6_port;
-        Map6to4( m_SocketAddr.sin6_addr, buf.sin_addr);
+        buf.sin_port = mSocketAddr_.sin6_port;
+        map6to4( mSocketAddr_.sin6_addr, buf.sin_addr);
     } else {
-        debugs(14, DBG_CRITICAL, HERE << "Ip::Address::GetSockAddr : Cannot convert non-IPv4 to IPv4. from " << *this );
+        debugs(14, DBG_CRITICAL, HERE << "Ip::Address::getSockAddr : Cannot convert non-IPv4 to IPv4. from " << *this );
 
         memset(&buf,0xFFFFFFFF,sizeof(struct sockaddr_in));
         assert(false);
     }
 
-#else
-
-    memcpy(&buf, &m_SocketAddr, sizeof(struct sockaddr_in));
-
-    if (buf.sin_family == 0) {
-        buf.sin_family = AF_INET;
-    }
-
-#endif
-
 #if HAVE_SIN_LEN_IN_SAI
     /* not all OS have this field, BUT when they do it can be a problem if set wrong */
     buf.sin_len = sizeof(struct sockaddr_in);
 #endif
-
 }
 
-#if USE_IPV6
 void
-Ip::Address::GetSockAddr(struct sockaddr_in6 &buf) const
+Ip::Address::getSockAddr(struct sockaddr_in6 &buf) const
 {
-    memcpy(&buf, &m_SocketAddr, sizeof(struct sockaddr_in6));
+    memcpy(&buf, &mSocketAddr_, sizeof(struct sockaddr_in6));
     /* maintain address family. It may have changed inside us. */
     buf.sin6_family = AF_INET6;
 
@@ -1151,11 +932,9 @@ Ip::Address::GetSockAddr(struct sockaddr_in6 &buf) const
     buf.sin6_len = sizeof(struct sockaddr_in6);
 #endif
 }
-#endif
 
-#if USE_IPV6
 void
-Ip::Address::Map4to6(const struct in_addr &in, struct in6_addr &out) const
+Ip::Address::map4to6(const struct in_addr &in, struct in6_addr &out) const
 {
     /* check for special cases */
 
@@ -1176,7 +955,7 @@ Ip::Address::Map4to6(const struct in_addr &in, struct in6_addr &out) const
 }
 
 void
-Ip::Address::Map6to4(const struct in6_addr &in, struct in_addr &out) const
+Ip::Address::map6to4(const struct in6_addr &in, struct in_addr &out) const
 {
     /* ANYADDR */
     /* NOADDR */
@@ -1190,33 +969,23 @@ Ip::Address::Map6to4(const struct in6_addr &in, struct in_addr &out) const
 }
 
 void
-Ip::Address::GetInAddr(in6_addr &buf) const
+Ip::Address::getInAddr(struct in6_addr &buf) const
 {
-    memcpy(&buf, &m_SocketAddr.sin6_addr, sizeof(struct in6_addr));
+    memcpy(&buf, &mSocketAddr_.sin6_addr, sizeof(struct in6_addr));
 }
-#endif
 
 bool
-Ip::Address::GetInAddr(struct in_addr &buf) const
+Ip::Address::getInAddr(struct in_addr &buf) const
 {
-
-#if USE_IPV6
-    if ( IsIPv4() ) {
-        Map6to4((const in6_addr)m_SocketAddr.sin6_addr, buf);
+    if ( isIPv4() ) {
+        map6to4(mSocketAddr_.sin6_addr, buf);
         return true;
     }
-#else
-
-    if ( IsIPv4() ) {
-        memcpy(&buf, &m_SocketAddr.sin_addr, sizeof(struct in_addr));
-        return true;
-    }
-#endif
 
     // default:
     // non-compatible IPv6 Pure Address
 
-    debugs(14,1, HERE << "Ip::Address::GetInAddr : Cannot convert non-IPv4 to IPv4. IPA=" << *this);
+    debugs(14, DBG_IMPORTANT, HERE << "Ip::Address::getInAddr : Cannot convert non-IPv4 to IPv4. IPA=" << *this);
     memset(&buf,0xFFFFFFFF,sizeof(struct in_addr));
     assert(false);
     return false;