--------------------- PatchSet 4131 Date: 2007/03/30 12:40:50 Author: amosjeffries Branch: squid3-ipv6 Tag: (none) Log: Better support for storage of special-case IP addresses. Members: lib/IPAddress.cc:1.1.2.10->1.1.2.11 Index: squid3/lib/IPAddress.cc =================================================================== RCS file: /cvsroot/squid-sf//squid3/lib/Attic/IPAddress.cc,v retrieving revision 1.1.2.10 retrieving revision 1.1.2.11 diff -u -r1.1.2.10 -r1.1.2.11 --- squid3/lib/IPAddress.cc 28 Mar 2007 10:39:15 -0000 1.1.2.10 +++ squid3/lib/IPAddress.cc 30 Mar 2007 12:40:50 -0000 1.1.2.11 @@ -1,5 +1,5 @@ /* - * $Id: IPAddress.cc,v 1.1.2.10 2007/03/28 10:39:15 amosjeffries Exp $ + * $Id: IPAddress.cc,v 1.1.2.11 2007/03/30 12:40:50 amosjeffries Exp $ */ #include "IPAddress.h" @@ -291,7 +291,7 @@ #ifdef USE_IPV6 void IPAddress::check4Mapped() { - /* check for ::ffff:0.0.0.0 IPv4-mapped addresses */ + /* check for ::ffff:x.x.x.x IPv4-mapped addresses */ if( 0 == memcmp(&m_SocketAddr.sin6_addr, &"\0x00000000\0x00000000\0x00000000\0xFFFF", (96 + 16) ) ) { m_Type = (IPAddressType)(m_Type | IPv4); @@ -474,11 +474,14 @@ // Ensure we have a buffer. if(buf == NULL) { - fprintf(stderr,"IPAddress::ToURL : Buffer received has no allocated space.\n"); + fprintf(stderr,"IPAddress::NtoA : Buffer received has no allocated space.\n"); return NULL; } - inet_ntop((m_Type&IPv6?AF_INET6:AF_INET), &m_SocketAddr.sin6_addr, buf, (m_Type&IPv6?STRLEN_IP6A:STRLEN_IP4A)); + if(m_Type & IPv6 ) + inet_ntop(AF_INET6, &m_SocketAddr.sin6_addr, buf, blen); + else + inet_ntop(AF_INET, &m_SocketAddr.sin6_addr, buf, blen); return buf; } @@ -535,9 +538,9 @@ { buf.sin_family = AF_INET; buf.sin_port = m_SocketAddr.sin6_port; - memcpy(&buf.sin_addr, &m_SocketAddr.sin6_addr.s6_addr32[3], sizeof(uint32_t) ); + Map6to4( m_SocketAddr.sin6_addr, buf.sin_addr); } - else // no conversion. set it to NO_ADDRESS instead + else // no conversion. set it to invalid content. { memset(&buf, 0, sizeof(struct sockaddr_in)); } @@ -556,12 +559,29 @@ #ifdef USE_IPV6 void IPAddress::Map4to6(const struct in_addr &in, struct in6_addr &out) const { + /* check for special cases */ + if( in.s_addr == 0x00000000) + { + memset(&out, 0, sizeof(struct in6_addr)); + return; + } + if( in.s_addr == 0xFFFFFFFF) + { + out.s6_addr32[0] = 0xFFFFFFFF; + out.s6_addr32[1] = 0xFFFFFFFF; + out.s6_addr32[2] = 0xFFFFFFFF; + out.s6_addr32[3] = 0xFFFFFFFF; + return; + } + /* FIXME TODO : handle special case of localhost (IPv4 127.0.0.1, IPv6 ::1 ) */ + memset(&out, 0, sizeof(struct in6_addr)); out.s6_addr32[3] = in.s_addr; out.s6_addr16[5] = (unsigned short)0xFFFF; } void IPAddress::Map6to4(const struct in6_addr &in, struct in_addr &out) const { + /* FIXME TODO : handle special case of localhost (IPv4 127.0.0.1, IPv6 ::1 ) */ memset(&out, 0, sizeof(struct in_addr)); out.s_addr = in.s6_addr32[3]; }