--------------------- PatchSet 4102 Date: 2007/03/18 09:07:00 Author: amosjeffries Branch: squid3-ipv6 Tag: (none) Log: Relocated IPAddress source files for better use in library code Members: include/IPAddress.h:1.1->1.1.2.1 lib/IPAddress.cc:1.1->1.1.2.1 lib/Makefile.am:1.12.4.1->1.12.4.2 lib/rfc1035.c:1.5.2.10->1.5.2.11 src/IPAddress.cc:1.1.2.11->1.1.2.12(DEAD) src/IPAddress.h:1.1.2.10->1.1.2.11(DEAD) src/Makefile.am:1.58.2.5->1.58.2.6 --- /dev/null Mon Mar 19 01:19:14 2007 +++ squid3/include/IPAddress.h Mon Mar 19 01:19:14 2007 @@ -0,0 +1,123 @@ +/* + * $Id: IPAddress.h,v 1.1.2.1 2007/03/18 09:07:00 amosjeffries Exp $ + */ +#ifndef _INC_IPADDRESS_H +#define _INC_IPADDRESS_H + +#include +#include +#include +#include + +/// Specify the type of Address being or to be handled. +enum IPAddressType { + None =0, /// Nothing Secial. Equates to default if used as a parameter. + SockAddr =1, /// Full SocketAddr Details Stored. + IPv4 =2, /// Pure IPv4 address stored (conversion up must be done explicitly) + IPv6 =4, /// Pure IPv6 address Stored (no conversion to IPv4 possible) + IPv64 =6 /// Dual-Address stored (can return either IPv6 OR IPv4) +}; + +/// Length of buffer that needs to be allocated to old a null-terminated IP-string +extern const unsigned int MAX_IPSTRLEN; + +/** + * Holds and manipulates IPv4, IPv6, and Socket Addresses. + */ +class IPAddress +{ +public: + IPAddress(); + IPAddress(const IPAddress &); + IPAddress(const hostent *); + IPAddress(const char*); + IPAddress(const struct in_addr &); + IPAddress(const struct sockaddr_in &); +#ifdef INET6 + IPAddress(const struct in6_addr &); + IPAddress(const struct sockaddr_in6 &); +#endif + ~IPAddress(); + + /** Assignment Operators **/ + IPAddress& operator =(const IPAddress &s); + IPAddress& operator =(const struct hostent *s); + IPAddress& operator =(const char *s); + IPAddress& operator =(struct sockaddr_in const &s); + IPAddress& operator =(struct in_addr const &s); +#ifdef INET6 + IPAddress& operator =(struct in6_addr const &s); + IPAddress& operator =(struct sockaddr_in6 const &s); +#endif + + /* Boolean Operators */ + bool operator ==(IPAddress const &s) const; + bool operator >=(IPAddress const &rhs) const; + bool operator <=(IPAddress const &rhs) const; + +public: + /* methods */ + inline bool IsIPv4() const { return (m_Type & IPv4); }; /// test whether content can be used as an IPv4. + inline bool IsIPv6() const { return (m_Type & IPv6); }; /// test whether content can be used as an IPv6. + inline bool IsSockAddr() const { return (m_Type & SockAddr); }; /// test whether content can be used as a sockaddr (Address and Port combo). + bool IsNoAddr() const; /// Content-neutral test for whether specific IP case ANY_ADDR is stored. + bool IsAnyAddr() const; /// Content-neutral test for whether specific IP case NO_ADDR is stored. + +#ifdef INET6 + bool GetReverseString(char buf[], IPAddressType show_format = IPv6) const; +#else + bool GetReverseString(char buf[], IPAddressType show_format = IPv4) const; +#endif + u_short GetPort() const; + u_short SetPort(u_short port); + void SetAnyAddr(); /// Set object to contain the specific IP case ANY_ADDR (format-neutral). + void SetNoAddr(); /// Set object to contain the specific IP case NO_ADDR (format-neutral). + void SetEmpty(); /// Fast reset of the stored content to what would be after default constructor. + + std::ostream& operator<<(std::ostream& os) const; + char* NtoA(char *buf, unsigned int len) const; + + bool ApplyMask(const IPAddress &); + bool ApplyMask(const unsigned int cidr, IPAddressType mtype = None); + + /* variables */ + + +public: + /* FIXME: When C => C++ conversion is done will be fully private. */ + /* Legacy Transition Methods */ + /* These are here solely to simplify the transition */ + /* when moving from converted code to unconverted */ + /* these functions can be used to convert this object */ + /* and pull out the data needed by the unconverted code */ + /* they are intentionaly hard to use, to encourage less use. */ + + void GetSockAddr(struct sockaddr_in &) const; + bool GetInAddr(struct in_addr &) const; /* false if could not convert IPv6 down to IPv4 */ +#ifdef INET6 + void GetSockAddr(struct sockaddr_in6 &) const; + void GetInAddr(struct in6_addr &) const; +#endif + +private: + /* methods */ + int matchIPAddr(const IPAddress &rhs) const; + /* Conversion for dual-type internals */ + bool GetReverseString4(char buf[], struct in_addr &) const; +#ifdef INET6 + void check4Mapped() const; + bool GetReverseString6(char buf[], struct in6_addr &) const; + void Map4to6(const struct in_addr &src, struct in6_addr &dest); + void Map6to4(const struct in6_addr &src, struct in_addr &dest); +#endif + + /* variables */ + IPAddressType m_Type; +#ifdef INET6 + struct sockaddr_in6 m_SocketAddr; +#else + struct sockaddr_in m_SocketAddr; +#endif +}; + +#endif /* _INC_IPADDRESS_H */ --- /dev/null Mon Mar 19 01:19:14 2007 +++ squid3/lib/IPAddress.cc Mon Mar 19 01:19:14 2007 @@ -0,0 +1,582 @@ +/* + * $Id: IPAddress.cc,v 1.1.2.1 2007/03/18 09:07:02 amosjeffries Exp $ + */ +#include "IPAddress.h" + +#include +#include +#include +#include /* inet Macros */ +#include /* inet_ntoa() */ +#include + +#include "util.h" +//#include "Debug.h" + +/* + enum IPAddressType { + NONE=0, + SockAddr =1, // Full SocketAddr Details Stored. + IPv4 =2, // Pure IPv4 address stored (conversion up must be done explicitly) + IPv6 =4, // Pure IPv6 Address Stored (no conversion to IPv4 possible) + IPv64 =6 // Dual-Address Stored (can return either IPv6 OR IPv4) + } m_Type; + struct sockaddr m_SocketAddr; +*/ + +#ifndef INET6 +// AYJ: 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 +#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; +#ifdef INET6 +const unsigned int MAX_IPSTRLEN = MAX_IP6_STRLEN; +#else +const unsigned int MAX_IPSTRLEN = MAX_IP4_STRLEN; +#endif + +IPAddress::IPAddress() +{ + memset(this,0,sizeof(IPAddress)); +#ifdef INET6 + m_Type = IPv64; +#else + m_Type = IPv4; +#endif +} +IPAddress::~IPAddress() +{ + memset(this,0,sizeof(IPAddress)); +} + +bool IPAddress::ApplyMask(IPAddress 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); + + for (unsigned int i = 0; i < blen; i++) { + p1[i] &= p2[i]; + } + return true; +} +bool IPAddress::ApplyMask(const unsigned int icidr, IPAddressType mtype) +{ + uint8_t clearbits = 0; + uint8_t* p = NULL; + unsigned int cidr = icidr; + +#ifdef INET6 /* IPv6 has IPv4 as Mapped-address */ + if (cidr > 128) return false; +#else + if (cidr > 32) return false; +#endif + if(cidr < 0) return true; // any err like this can be assumed /0 + + clearbits = (uint8_t)((m_Type&IPv6?128:32)-cidr); + +#ifdef INET6 + p = (uint8_t*)(&m_SocketAddr.sin6_addr) + 15; +#else + p = (uint8_t*)(&m_SocketAddr.sin6_addr) + 3; +#endif + + for (; clearbits>0 && p >= (uint8_t*)&m_SocketAddr.sin6_addr ; clearbits-=8, p-- ) { + *p &= ((0xFF << clearbits) & 0xFF); + } + + return true; +} + +bool IPAddress::IsAnyAddr() const +{ +#ifdef INET6 + return (0 == memcmp(&(m_SocketAddr.sin6_addr), &in6addr_any, sizeof(in6addr_any)) ); +#else + return (INADDR_ANY == m_SocketAddr.sin_addr.s_addr); +#endif +} +void IPAddress::SetAnyAddr() +{ + memset(&(m_SocketAddr.sin6_addr),0, sizeof(m_SocketAddr.sin6_addr)); +#ifdef INET6 + m_Type = IPv64; +#else + m_Type=IPv4; +#endif +} +void IPAddress::SetEmpty() +{ + memset(&(m_SocketAddr.sin6_addr),0x0, sizeof(m_SocketAddr.sin6_addr)); +} + +bool IPAddress::IsNoAddr() const +{ + // IFF the address == 0xff..ff (all ones) + return (0 == memcmp(&m_SocketAddr.sin6_addr, &"\0xFFFFFFFF\0xFFFFFFFF\0xFFFFFFFF\0xFFFFFFFF", sizeof(m_SocketAddr.sin6_addr) ) ); +} +void IPAddress::SetNoAddr() +{ + memset(&(m_SocketAddr.sin6_addr),0xFFFFFFFF,sizeof(m_SocketAddr.sin6_addr)); +#ifdef INET6 + m_Type = IPv64; +#else + m_Type=IPv4; +#endif +} + +#ifdef INET6 +bool IPAddress::GetReverseString6(char buf[MAX_IPSTRLEN], struct in6_addr &dat) const +{ + char *p = buf; + unsigned char *r = dat.s6_addr; + + /* RFC1886 says: */ + /* 4321:0:1:2:3:4:567:89ab */ + /* must be sent */ + /* b.a.9.8.7.6.5.0.4.0.0.0.3.0.0.0.2.0.0.0.1.0.0.0.0.0.0.0.1.2.3.4.ip6.int. */ + + /* Work from the binary field. Anything else may have representation changes. */ + /* The sin6_port and sin6_addr members shall be in network byte order. */ + + /* Compile Err: 'Too many arguments for format. */ + for(int i = 15; i >= 0; i--, p+=4) + { + snprintf(p, 5, "%x.%x.", (((r[i])>>4)&0xf), ((r[i])&0xf) ); + } + + /* RFC3152 says: */ + /* ip6.int is now deprecated TLD, use ip6.arpa instead. */ + snprintf(p,10,"ip6.arpa."); + + return true; +} +#endif + +bool IPAddress::GetReverseString4(char buf[MAX_IPSTRLEN], struct in_addr &dat) const +{ + unsigned int i = (unsigned int) ntohl(dat.s_addr); + snprintf(buf, 32, "%u.%u.%u.%u.in-addr.arpa.", + i & 255, + (i >> 8) & 255, + (i >> 16) & 255, + (i >> 24) & 255); + return false; +} + +bool IPAddress::GetReverseString(char buf[MAX_IPSTRLEN], IPAddressType show_type) const +{ + in_addr* ip4_ptr = NULL; +#ifdef INET6 + in6_addr* ip6_ptr = NULL; + in6_addr tmp_buf; +#endif + + if(m_Type == None) return false; +#ifdef INET6 + if(show_type == None) show_type = IPv6; +#else + if(show_type == None) show_type = IPv4; +#endif + + switch(m_Type & IPv64) // What we do depends on how we stored it. + { + case IPv4: +#ifndef INET6 + ip4_ptr = (in_addr*)&m_SocketAddr.sin_addr; +#else /* INET6 */ + ip4_ptr = (in_addr*)&m_SocketAddr.sin6_addr.s6_addr[12]; + ip6_ptr = &tmp_buf; + Map4to6(*ip4_ptr, *ip6_ptr); +#endif + break; + + case IPv64: +#ifndef INET6 + ip4_ptr = (in_addr*)&m_SocketAddr.sin_addr; +#else + ip4_ptr = (in_addr*)&m_SocketAddr.sin6_addr.s6_addr32[3]; + // Fall through to setup IPv6 output ptr + + case IPv6: + ip6_ptr = &m_SocketAddr.sin6_addr; +#endif + break; + } + + if(show_type == IPv4 && ip4_ptr != NULL) + { + return GetReverseString4(buf, *(in_addr*)ip4_ptr); + } +#ifdef INET6 + if(show_type == IPv6 && ip6_ptr != NULL) + { + return GetReverseString6(buf, *(in6_addr*)ip6_ptr); + } +#endif + + /* FIXME: an error occured. invalid address type */ + // return an empty string for the buffer, and log an error + buf[0] = '\0'; + +// TODO debug output a warning. + + return false; +} + +IPAddress& IPAddress::operator =(const IPAddress &s) { + memcpy(this, &s, sizeof(IPAddress)); + return *this; +}; + +IPAddress::IPAddress(const char*s) +{ + memset(this,0,sizeof(IPAddress)); + operator=(s); +} + +IPAddress& IPAddress::operator =(const char* s) +{ + struct hostent *hp; + +/* FIXME TODO : check that the input is actually an IP Address */ + + if ((hp = gethostbyname(s)) == NULL) { +// debug(28, 0)("IPAddress: Bad IP: '%s'\n",s ); +// FIXME enable this call somehow : self_destruct(); + } + + return operator=(hp->h_addr_list[0]); +} + + +IPAddress::IPAddress(struct sockaddr_in const &s) { + memset(this,0,sizeof(IPAddress)); +/* +#ifdef INET6 + Map4to6((const in_addr)s.sin_addr, m_SocketAddr.sin6_addr); + m_SocketAddr.sin6_port = s.sin_port; + m_SocketAddr.sin6_family = AF_INET6; + m_Type=(IPAddressType)(IPv64 | SockAddr); +#else + memcpy(&m_SocketAddr, &s, sizeof(struct sockaddr_in)); + m_Type=(IPAddressType)(IPv4 | SockAddr); +#endif +*/ + operator=(s); +}; +IPAddress& IPAddress::operator =(struct sockaddr_in const &s) { +#ifdef INET6 + Map4to6((const in_addr)s.sin_addr, m_SocketAddr.sin6_addr); + m_SocketAddr.sin6_port = s.sin_port; + m_SocketAddr.sin6_family = AF_INET6; + m_Type=(IPAddressType)(IPv64 | SockAddr); +#else + memcpy(&m_SocketAddr, &s, sizeof(struct sockaddr_in)); + m_Type=(IPAddressType)(IPv4 | SockAddr); +#endif + return *this; +}; + +#ifdef INET6 +void IPAddress::check4Mapped() +{ + /* check for ::ffff:0.0.0.0 IPv4-mapped addresses */ + if( 0 == memcmp(&m_SocketAddress.sin6_addr, &"\0x00000000\0x00000000\0x00000000\0xFFFF", (96 + 16) ) ) + { + m_Type |= IPv4; + } + /* FIXME: maybe other tests thay can apply if the IPA was mapped in other ways */ + /* I know of 2002:0.0.0.0:: mappings and possibly fe80::???? mappings */ + +} + +IPAddress::IPAddress(sockaddr_in6 const &s) { + memset(this,0,sizeof(IPAddress)); +/* + memcpy(&m_SocketAddr, &s, sizeof(struct sockaddr_in6)); + m_Type = (IPAddressType)(SockAddr | IPv6); + + check4Mapped(); +*/ + operator=(s); +}; +IPAddress& IPAddress::operator =(sockaddr_in6 const &s) { + memcpy(&m_SocketAddr, &s, sizeof(struct sockaddr_in6)); + m_Type = (IPAddressType)(SockAddr | IPv6); + + check4Mapped(); + return *this; +}; +#endif + +IPAddress::IPAddress(in_addr const &s) { + memset(this,0,sizeof(IPAddress)); + operator=(s); +/* +#ifdef INET6 + Map4to6((const in_addr)s, m_SocketAddr.sin6_addr); + m_SocketAddr.sin6_port = 0; + m_SocketAddr.sin6_family = AF_INET6; + m_Type=IPv64; +#else + memcpy(&m_SocketAddr.sin_addr, &s, sizeof(struct in_addr)); + m_SocketAddr.sin_port = 0; + m_SocketAddr.sin_family = AF_INET; + m_Type=IPv4; +#endif +*/ +}; +IPAddress& IPAddress::operator =(in_addr const &s) { +#ifdef INET6 + Map4to6((const in_addr)s, m_SocketAddr.sin6_addr); + m_SocketAddr.sin6_port = 0; + m_SocketAddr.sin6_family = AF_INET6; + m_Type=IPv64; +#else + memcpy(&m_SocketAddr.sin_addr, &s, sizeof(struct in_addr)); + m_SocketAddr.sin_port = 0; + m_SocketAddr.sin_family = AF_INET; + m_Type=IPv4; +#endif + return *this; +}; + +#ifdef INET6 +IPAddress::IPAddress(struct in6_addr const &s) { + memset(this,0,sizeof(IPAddress)); +/* + memcpy(&m_SocketAddr.sin6_addr, &s, sizeof(struct in6_addr)); + m_SocketAddr.sin6_port = 0; + m_SocketAddr.sin6_family = AF_INET6; + m_Type=IPv6; + check4Mapped(); +*/ + operator=(s); +}; +IPAddress& IPAddress::operator =(struct in6_addr const &s) { + // FIXME: convert properly from in6_addr to the storage method. + memcpy(&m_SocketAddr.sin6_addr, &s, sizeof(struct in6_addr)); + m_SocketAddr.sin6_port = 0; + m_SocketAddr.sin6_family = AF_INET6; + m_Type=IPv6; + check4Mapped(); + return *this; +}; +#endif + +IPAddress::IPAddress(const IPAddress &s) { + memset(this,0,sizeof(IPAddress)); +/* + memcpy(this,&s,sizeof(IPAddress)); + // Special Drop of the duplicated m_cacheStringValue ptr + // and rebuild of a new string in new memory for this copy of the object. +*/ + operator=(s); +} + +IPAddress::IPAddress(const struct hostent *s) { + memset(this,0,sizeof(IPAddress)); + operator=(s); +} + +IPAddress& IPAddress::operator =(const struct hostent *s) +{ + struct in_addr* ipv4 = NULL; + struct in6_addr* ipv6 = NULL; + +//struct hostent { +// char *h_name; /* official name of host */ +// char **h_aliases; /* alias list */ +// int h_addrtype; /* host address type */ +// int h_length; /* length of address */ +// char **h_addr_list; /* list of addresses */ +//} + + switch(s->h_addrtype) + { + case AF_INET: + ipv4 = (in_addr*)s->h_addr_list[0]; + /* this */ operator=(*ipv4); + break; + case AF_INET6: + ipv6 = (in6_addr*)s->h_addr_list[0]; +#ifdef INET6 + /* this */ operator=(*ipv6); +#else + // FIXME : Log the discarded address. + // TODO see if there is another address in the list that might be usable ?? +#endif + break; + } + + return *this; +} + +// Operatior to output +std::ostream& IPAddress::operator<<(std::ostream& os) const +{ + char buf[MAX_IPSTRLEN+1]; + // Dump the Current [Address]:Port to the debug stream. +#ifdef INET6 + os << "[" << NtoA(buf,MAX_IPSTRLEN+1) << "]:" << m_SocketAddr.sin6_port; +#else + os << NtoA(buf,MAX_IPSTRLEN+1) << ":" << m_SocketAddr.sin_port; +#endif + return os; +} + +int IPAddress::matchIPAddr(const IPAddress &rhs) const +{ + unsigned int slen = sizeof(m_SocketAddr.sin6_addr); + uint8_t *l = (uint8_t*)&m_SocketAddr.sin6_addr; + uint8_t *r = (uint8_t*)&rhs.m_SocketAddr.sin6_addr; + uint8_t *end = l+slen; + + // loop a bit-wise compare + for( ; l <= end ; r++, l++) + { + if(*l < *r) return -1; + if(*l > *r) return 1; + } + + // finally if addr are equal the port determines equality. + return (m_SocketAddr.sin6_port - rhs.m_SocketAddr.sin6_port); +} + +bool IPAddress::operator ==(const IPAddress &s) const +{ + if(m_Type != s.m_Type) return false; + return (0 == matchIPAddr(s)); +} +bool IPAddress::operator <=(const IPAddress &rhs) const +{ + if(IsAnyAddr() && !rhs.IsAnyAddr()) return true; + return (matchIPAddr(rhs) <= 0); +} + +bool IPAddress::operator >=(const IPAddress &rhs) const +{ + if(IsNoAddr() && !rhs.IsNoAddr()) return true; + return ( matchIPAddr(rhs) >= 0); +} + +u_short IPAddress::GetPort() const +{ + return ntohs( m_SocketAddr.sin6_port ); +} + +u_short IPAddress::SetPort(u_short prt) +{ + m_SocketAddr.sin6_port = htons(prt); + if(m_Type != None) m_Type = (IPAddressType)(m_Type | SockAddr); + return prt; +} + +char* IPAddress::NtoA(char* buf, unsigned int blen) const +{ + char t[MAX_IPSTRLEN]; + + // Ensure we have a buffer. + if(buf == NULL) + { + // TODO debug output a warning. + return NULL; + } + + memset(t,0,MAX_IPSTRLEN); + + if(m_SocketAddr.sin6_port > 0) + { + if(inet_ntop((m_Type&IPv6?AF_INET6:AF_INET), &m_SocketAddr.sin6_addr, t, MAX_IPSTRLEN )) +#ifdef INET6 + snprintf(buf,blen,"[%s]:%d",t, ntohs(m_SocketAddr.sin6_port) ); +#else + snprintf(buf,blen,"%s:%d",t, ntohs(m_SocketAddr.sin_port) ); +#endif + } else { + inet_ntop((m_Type&IPv6?AF_INET6:AF_INET), &m_SocketAddr.sin6_addr, buf, (m_Type&IPv6?STRLEN_IP6A:STRLEN_IP4A)); + } + + return buf; +} + +void IPAddress::GetSockAddr(struct sockaddr_in &buf) const +{ +#ifdef INET6 + if(m_Type & IPv4) // if can be converted down. + { + 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) ); + } + else // no conversion. set it to NO_ADDRESS instead + { + memset(&buf, 0, sizeof(struct sockaddr_in)); + } +#else + memcpy(&buf, &m_SocketAddr, sizeof(struct sockaddr_in)); +#endif +} + +#ifdef INET6 +void IPAddress::GetSockAddr(struct sockaddr_in6 &buf) const +{ + memcpy(&buf, &m_SocketAddr, sizeof(struct sockaddr_in6)); +} +#endif + +#ifdef INET6 +void IPAddress::Map4to6(const struct in_addr &in, struct in6_addr &out) +{ + 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) +{ + memset(&out, 0, sizeof(struct in_addr)); + out.s_addr = in.s6_addr32[3]; +} +#endif + +#ifdef INET6 +void IPAddress::GetInAddr(in6_addr &buf) const +{ + assert(m_Type & IPv6); + memcpy(&buf, &m_SocketAddr.sin6_addr, sizeof(struct in6_addr)); +} +#endif + +bool IPAddress::GetInAddr(struct in_addr &buf) const +{ + switch(m_Type & IPv64) + { +#ifdef INET6 + case IPv64: // IPv4-Compatible IPv6 Address + Map6to4((const in6_addr)m_SocketAddr.sin6_addr, buf); + return true; +#else + case IPv4: // Pure IPv4 Address. + memcpy(&buf, &m_SocketAddr.sin_addr, sizeof(struct in_addr)); + return true; +#endif + + case IPv6: // non-compatible IPv6 Pure Address + default: + // flow through to error case. + // FIXME: debug Log the call to this function ?? + // FIXME: Or return the IPv4 version of 'no address' and let the ACL deal with it?? + return false; + } +} Index: squid3/lib/Makefile.am =================================================================== RCS file: /cvsroot/squid-sf//squid3/lib/Makefile.am,v retrieving revision 1.12.4.1 retrieving revision 1.12.4.2 diff -u -r1.12.4.1 -r1.12.4.2 --- squid3/lib/Makefile.am 5 Jan 2007 16:57:39 -0000 1.12.4.1 +++ squid3/lib/Makefile.am 18 Mar 2007 09:07:02 -0000 1.12.4.2 @@ -1,6 +1,6 @@ ## Process this file with automake to produce Makefile.in # -# $Id: Makefile.am,v 1.12.4.1 2007/01/05 16:57:39 hno Exp $ +# $Id: Makefile.am,v 1.12.4.2 2007/03/18 09:07:02 amosjeffries Exp $ # DIST_SUBDIRS = libTrie cppunit-1.10.0 @@ -65,6 +65,7 @@ hash.c \ heap.c \ html_quote.c \ + IPAddress.cc \ iso3307.c \ $(MD5SOURCE) \ radix.c \ Index: squid3/lib/rfc1035.c =================================================================== RCS file: /cvsroot/squid-sf//squid3/lib/rfc1035.c,v retrieving revision 1.5.2.10 retrieving revision 1.5.2.11 diff -u -r1.5.2.10 -r1.5.2.11 --- squid3/lib/rfc1035.c 4 Feb 2007 07:26:20 -0000 1.5.2.10 +++ squid3/lib/rfc1035.c 18 Mar 2007 09:07:02 -0000 1.5.2.11 @@ -1,6 +1,6 @@ /* - * $Id: rfc1035.c,v 1.5.2.10 2007/02/04 07:26:20 amosjeffries Exp $ + * $Id: rfc1035.c,v 1.5.2.11 2007/03/18 09:07:02 amosjeffries Exp $ * * Low level DNS protocol routines * AUTHOR: Duane Wessels @@ -63,9 +63,6 @@ #if HAVE_NETINET_IN_H #include #endif -//#if HAVE_ARPA_INET_H -//#include -//#endif #if HAVE_STRINGS_H #include #endif --- squid3/src/IPAddress.cc Mon Mar 19 01:19:14 2007 +++ /dev/null Mon Mar 19 01:19:14 2007 @@ -1,582 +0,0 @@ -/* - * $Id: IPAddress.cc,v 1.1.2.11 2007/03/18 02:56:32 amosjeffries Exp $ - */ -#include "IPAddress.h" - -#include -#include -#include -#include /* inet Macros */ -#include /* inet_ntoa() */ -#include - -#include "util.h" -#include "Debug.h" - -/* - enum IPAddressType { - NONE=0, - SockAddr =1, // Full SocketAddr Details Stored. - IPv4 =2, // Pure IPv4 address stored (conversion up must be done explicitly) - IPv6 =4, // Pure IPv6 Address Stored (no conversion to IPv4 possible) - IPv64 =6 // Dual-Address Stored (can return either IPv6 OR IPv4) - } m_Type; - struct sockaddr m_SocketAddr; -*/ - -#ifndef INET6 -// AYJ: 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 -#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; -#ifdef INET6 -const unsigned int MAX_IPSTRLEN = MAX_IP6_STRLEN; -#else -const unsigned int MAX_IPSTRLEN = MAX_IP4_STRLEN; -#endif - -IPAddress::IPAddress() -{ - memset(this,0,sizeof(IPAddress)); -#ifdef INET6 - m_Type = IPv64; -#else - m_Type = IPv4; -#endif -} -IPAddress::~IPAddress() -{ - memset(this,0,sizeof(IPAddress)); -} - -bool IPAddress::ApplyMask(IPAddress 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); - - for (unsigned int i = 0; i < blen; i++) { - p1[i] &= p2[i]; - } - return true; -} -bool IPAddress::ApplyMask(const unsigned int icidr, IPAddressType mtype) -{ - uint8_t clearbits = 0; - uint8_t* p = NULL; - unsigned int cidr = icidr; - -#ifdef INET6 /* IPv6 has IPv4 as Mapped-address */ - if (cidr > 128) return false; -#else - if (cidr > 32) return false; -#endif - if(cidr < 0) return true; // any err like this can be assumed /0 - - clearbits = (uint8_t)((m_Type&IPv6?128:32)-cidr); - -#ifdef INET6 - p = (uint8_t*)(&m_SocketAddr.sin6_addr) + 15; -#else - p = (uint8_t*)(&m_SocketAddr.sin6_addr) + 3; -#endif - - for (; clearbits>0 && p >= (uint8_t*)&m_SocketAddr.sin6_addr ; clearbits-=8, p-- ) { - *p &= ((0xFF << clearbits) & 0xFF); - } - - return true; -} - -bool IPAddress::IsAnyAddr() const -{ -#ifdef INET6 - return (0 == memcmp(&(m_SocketAddr.sin6_addr), &in6addr_any, sizeof(in6addr_any)) ); -#else - return (INADDR_ANY == m_SocketAddr.sin_addr.s_addr); -#endif -} -void IPAddress::SetAnyAddr() -{ - memset(&(m_SocketAddr.sin6_addr),0, sizeof(m_SocketAddr.sin6_addr)); -#ifdef INET6 - m_Type = IPv64; -#else - m_Type=IPv4; -#endif -} -void IPAddress::SetEmpty() -{ - memset(&(m_SocketAddr.sin6_addr),0x0, sizeof(m_SocketAddr.sin6_addr)); -} - -bool IPAddress::IsNoAddr() const -{ - // IFF the address == 0xff..ff (all ones) - return (0 == memcmp(&m_SocketAddr.sin6_addr, &"\0xFFFFFFFF\0xFFFFFFFF\0xFFFFFFFF\0xFFFFFFFF", sizeof(m_SocketAddr.sin6_addr) ) ); -} -void IPAddress::SetNoAddr() -{ - memset(&(m_SocketAddr.sin6_addr),0xFFFFFFFF,sizeof(m_SocketAddr.sin6_addr)); -#ifdef INET6 - m_Type = IPv64; -#else - m_Type=IPv4; -#endif -} - -#ifdef INET6 -bool IPAddress::GetReverseString6(char buf[MAX_IPSTRLEN], struct in6_addr &dat) const -{ - char *p = buf; - unsigned char *r = dat.s6_addr; - - /* RFC1886 says: */ - /* 4321:0:1:2:3:4:567:89ab */ - /* must be sent */ - /* b.a.9.8.7.6.5.0.4.0.0.0.3.0.0.0.2.0.0.0.1.0.0.0.0.0.0.0.1.2.3.4.ip6.int. */ - - /* Work from the binary field. Anything else may have representation changes. */ - /* The sin6_port and sin6_addr members shall be in network byte order. */ - - /* Compile Err: 'Too many arguments for format. */ - for(int i = 15; i >= 0; i--, p+=4) - { - snprintf(p, 5, "%x.%x.", (((r[i])>>4)&0xf), ((r[i])&0xf) ); - } - - /* RFC3152 says: */ - /* ip6.int is now deprecated TLD, use ip6.arpa instead. */ - snprintf(p,10,"ip6.arpa."); - - return true; -} -#endif - -bool IPAddress::GetReverseString4(char buf[MAX_IPSTRLEN], struct in_addr &dat) const -{ - unsigned int i = (unsigned int) ntohl(dat.s_addr); - snprintf(buf, 32, "%u.%u.%u.%u.in-addr.arpa.", - i & 255, - (i >> 8) & 255, - (i >> 16) & 255, - (i >> 24) & 255); - return false; -} - -bool IPAddress::GetReverseString(char buf[MAX_IPSTRLEN], IPAddressType show_type) const -{ - in_addr* ip4_ptr = NULL; -#ifdef INET6 - in6_addr* ip6_ptr = NULL; - in6_addr tmp_buf; -#endif - - if(m_Type == None) return false; -#ifdef INET6 - if(show_type == None) show_type = IPv6; -#else - if(show_type == None) show_type = IPv4; -#endif - - switch(m_Type & IPv64) // What we do depends on how we stored it. - { - case IPv4: -#ifndef INET6 - ip4_ptr = (in_addr*)&m_SocketAddr.sin_addr; -#else /* INET6 */ - ip4_ptr = (in_addr*)&m_SocketAddr.sin6_addr.s6_addr[12]; - ip6_ptr = &tmp_buf; - Map4to6(*ip4_ptr, *ip6_ptr); -#endif - break; - - case IPv64: -#ifndef INET6 - ip4_ptr = (in_addr*)&m_SocketAddr.sin_addr; -#else - ip4_ptr = (in_addr*)&m_SocketAddr.sin6_addr.s6_addr32[3]; - // Fall through to setup IPv6 output ptr - - case IPv6: - ip6_ptr = &m_SocketAddr.sin6_addr; -#endif - break; - } - - if(show_type == IPv4 && ip4_ptr != NULL) - { - return GetReverseString4(buf, *(in_addr*)ip4_ptr); - } -#ifdef INET6 - if(show_type == IPv6 && ip6_ptr != NULL) - { - return GetReverseString6(buf, *(in6_addr*)ip6_ptr); - } -#endif - - /* FIXME: an error occured. invalid address type */ - // return an empty string for the buffer, and log an error - buf[0] = '\0'; - -// TODO debug output a warning. - - return false; -} - -IPAddress& IPAddress::operator =(const IPAddress &s) { - memcpy(this, &s, sizeof(IPAddress)); - return *this; -}; - -IPAddress::IPAddress(const char*s) -{ - memset(this,0,sizeof(IPAddress)); - operator=(s); -} - -IPAddress& IPAddress::operator =(const char* s) -{ - struct hostent *hp; - -/* FIXME TODO : check that the input is actually an IP Address */ - - if ((hp = gethostbyname(s)) == NULL) { - debugs(28, 0, HERE << "IPAddress: Bad IP: '" << s << "'\n" ); -// FIXME enable this call somehow : self_destruct(); - } - - return operator=(hp->h_addr_list[0]); -} - - -IPAddress::IPAddress(struct sockaddr_in const &s) { - memset(this,0,sizeof(IPAddress)); -/* -#ifdef INET6 - Map4to6((const in_addr)s.sin_addr, m_SocketAddr.sin6_addr); - m_SocketAddr.sin6_port = s.sin_port; - m_SocketAddr.sin6_family = AF_INET6; - m_Type=(IPAddressType)(IPv64 | SockAddr); -#else - memcpy(&m_SocketAddr, &s, sizeof(struct sockaddr_in)); - m_Type=(IPAddressType)(IPv4 | SockAddr); -#endif -*/ - operator=(s); -}; -IPAddress& IPAddress::operator =(struct sockaddr_in const &s) { -#ifdef INET6 - Map4to6((const in_addr)s.sin_addr, m_SocketAddr.sin6_addr); - m_SocketAddr.sin6_port = s.sin_port; - m_SocketAddr.sin6_family = AF_INET6; - m_Type=(IPAddressType)(IPv64 | SockAddr); -#else - memcpy(&m_SocketAddr, &s, sizeof(struct sockaddr_in)); - m_Type=(IPAddressType)(IPv4 | SockAddr); -#endif - return *this; -}; - -#ifdef INET6 -void IPAddress::check4Mapped() -{ - /* check for ::ffff:0.0.0.0 IPv4-mapped addresses */ - if( 0 == memcmp(&m_SocketAddress.sin6_addr, &"\0x00000000\0x00000000\0x00000000\0xFFFF", (96 + 16) ) ) - { - m_Type |= IPv4; - } - /* FIXME: maybe other tests thay can apply if the IPA was mapped in other ways */ - /* I know of 2002:0.0.0.0:: mappings and possibly fe80::???? mappings */ - -} - -IPAddress::IPAddress(sockaddr_in6 const &s) { - memset(this,0,sizeof(IPAddress)); -/* - memcpy(&m_SocketAddr, &s, sizeof(struct sockaddr_in6)); - m_Type = (IPAddressType)(SockAddr | IPv6); - - check4Mapped(); -*/ - operator=(s); -}; -IPAddress& IPAddress::operator =(sockaddr_in6 const &s) { - memcpy(&m_SocketAddr, &s, sizeof(struct sockaddr_in6)); - m_Type = (IPAddressType)(SockAddr | IPv6); - - check4Mapped(); - return *this; -}; -#endif - -IPAddress::IPAddress(in_addr const &s) { - memset(this,0,sizeof(IPAddress)); - operator=(s); -/* -#ifdef INET6 - Map4to6((const in_addr)s, m_SocketAddr.sin6_addr); - m_SocketAddr.sin6_port = 0; - m_SocketAddr.sin6_family = AF_INET6; - m_Type=IPv64; -#else - memcpy(&m_SocketAddr.sin_addr, &s, sizeof(struct in_addr)); - m_SocketAddr.sin_port = 0; - m_SocketAddr.sin_family = AF_INET; - m_Type=IPv4; -#endif -*/ -}; -IPAddress& IPAddress::operator =(in_addr const &s) { -#ifdef INET6 - Map4to6((const in_addr)s, m_SocketAddr.sin6_addr); - m_SocketAddr.sin6_port = 0; - m_SocketAddr.sin6_family = AF_INET6; - m_Type=IPv64; -#else - memcpy(&m_SocketAddr.sin_addr, &s, sizeof(struct in_addr)); - m_SocketAddr.sin_port = 0; - m_SocketAddr.sin_family = AF_INET; - m_Type=IPv4; -#endif - return *this; -}; - -#ifdef INET6 -IPAddress::IPAddress(struct in6_addr const &s) { - memset(this,0,sizeof(IPAddress)); -/* - memcpy(&m_SocketAddr.sin6_addr, &s, sizeof(struct in6_addr)); - m_SocketAddr.sin6_port = 0; - m_SocketAddr.sin6_family = AF_INET6; - m_Type=IPv6; - check4Mapped(); -*/ - operator=(s); -}; -IPAddress& IPAddress::operator =(struct in6_addr const &s) { - // FIXME: convert properly from in6_addr to the storage method. - memcpy(&m_SocketAddr.sin6_addr, &s, sizeof(struct in6_addr)); - m_SocketAddr.sin6_port = 0; - m_SocketAddr.sin6_family = AF_INET6; - m_Type=IPv6; - check4Mapped(); - return *this; -}; -#endif - -IPAddress::IPAddress(const IPAddress &s) { - memset(this,0,sizeof(IPAddress)); -/* - memcpy(this,&s,sizeof(IPAddress)); - // Special Drop of the duplicated m_cacheStringValue ptr - // and rebuild of a new string in new memory for this copy of the object. -*/ - operator=(s); -} - -IPAddress::IPAddress(const struct hostent *s) { - memset(this,0,sizeof(IPAddress)); - operator=(s); -} - -IPAddress& IPAddress::operator =(const struct hostent *s) -{ - struct in_addr* ipv4 = NULL; - struct in6_addr* ipv6 = NULL; - -//struct hostent { -// char *h_name; /* official name of host */ -// char **h_aliases; /* alias list */ -// int h_addrtype; /* host address type */ -// int h_length; /* length of address */ -// char **h_addr_list; /* list of addresses */ -//} - - switch(s->h_addrtype) - { - case AF_INET: - ipv4 = (in_addr*)s->h_addr_list[0]; - /* this */ operator=(*ipv4); - break; - case AF_INET6: - ipv6 = (in6_addr*)s->h_addr_list[0]; -#ifdef INET6 - /* this */ operator=(*ipv6); -#else - // FIXME : Log the discarded address. - // TODO see if there is another address in the list that might be usable ?? -#endif - break; - } - - return *this; -} - -// Operatior to output -std::ostream& IPAddress::operator<<(std::ostream& os) const -{ - char buf[MAX_IPSTRLEN+1]; - // Dump the Current [Address]:Port to the debug stream. -#ifdef INET6 - os << "[" << NtoA(buf,MAX_IPSTRLEN+1) << "]:" << m_SocketAddr.sin6_port; -#else - os << NtoA(buf,MAX_IPSTRLEN+1) << ":" << m_SocketAddr.sin_port; -#endif - return os; -} - -int IPAddress::matchIPAddr(const IPAddress &rhs) const -{ - unsigned int slen = sizeof(m_SocketAddr.sin6_addr); - uint8_t *l = (uint8_t*)&m_SocketAddr.sin6_addr; - uint8_t *r = (uint8_t*)&rhs.m_SocketAddr.sin6_addr; - uint8_t *end = l+slen; - - // loop a bit-wise compare - for( ; l <= end ; r++, l++) - { - if(*l < *r) return -1; - if(*l > *r) return 1; - } - - // finally if addr are equal the port determines equality. - return (m_SocketAddr.sin6_port - rhs.m_SocketAddr.sin6_port); -} - -bool IPAddress::operator ==(const IPAddress &s) const -{ - if(m_Type != s.m_Type) return false; - return (0 == matchIPAddr(s)); -} -bool IPAddress::operator <=(const IPAddress &rhs) const -{ - if(IsAnyAddr() && !rhs.IsAnyAddr()) return true; - return (matchIPAddr(rhs) <= 0); -} - -bool IPAddress::operator >=(const IPAddress &rhs) const -{ - if(IsNoAddr() && !rhs.IsNoAddr()) return true; - return ( matchIPAddr(rhs) >= 0); -} - -u_short IPAddress::GetPort() const -{ - return ntohs( m_SocketAddr.sin6_port ); -} - -u_short IPAddress::SetPort(u_short prt) -{ - m_SocketAddr.sin6_port = htons(prt); - if(m_Type != None) m_Type = (IPAddressType)(m_Type | SockAddr); - return prt; -} - -char* IPAddress::NtoA(char* buf, unsigned int blen) const -{ - char t[MAX_IPSTRLEN]; - - // Ensure we have a buffer. - if(buf == NULL) - { - // TODO debug output a warning. - return NULL; - } - - memset(t,0,MAX_IPSTRLEN); - - if(m_SocketAddr.sin6_port > 0) - { - if(inet_ntop((m_Type&IPv6?AF_INET6:AF_INET), &m_SocketAddr.sin6_addr, t, MAX_IPSTRLEN )) -#ifdef INET6 - snprintf(buf,blen,"[%s]:%d",t, ntohs(m_SocketAddr.sin6_port) ); -#else - snprintf(buf,blen,"%s:%d",t, ntohs(m_SocketAddr.sin_port) ); -#endif - } else { - inet_ntop((m_Type&IPv6?AF_INET6:AF_INET), &m_SocketAddr.sin6_addr, buf, (m_Type&IPv6?STRLEN_IP6A:STRLEN_IP4A)); - } - - return buf; -} - -void IPAddress::GetSockAddr(struct sockaddr_in &buf) const -{ -#ifdef INET6 - if(m_Type & IPv4) // if can be converted down. - { - 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) ); - } - else // no conversion. set it to NO_ADDRESS instead - { - memset(&buf, 0, sizeof(struct sockaddr_in)); - } -#else - memcpy(&buf, &m_SocketAddr, sizeof(struct sockaddr_in)); -#endif -} - -#ifdef INET6 -void IPAddress::GetSockAddr(struct sockaddr_in6 &buf) const -{ - memcpy(&buf, &m_SocketAddr, sizeof(struct sockaddr_in6)); -} -#endif - -#ifdef INET6 -void IPAddress::Map4to6(const struct in_addr &in, struct in6_addr &out) -{ - 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) -{ - memset(&out, 0, sizeof(struct in_addr)); - out.s_addr = in.s6_addr32[3]; -} -#endif - -#ifdef INET6 -void IPAddress::GetInAddr(in6_addr &buf) const -{ - assert(m_Type & IPv6); - memcpy(&buf, &m_SocketAddr.sin6_addr, sizeof(struct in6_addr)); -} -#endif - -bool IPAddress::GetInAddr(struct in_addr &buf) const -{ - switch(m_Type & IPv64) - { -#ifdef INET6 - case IPv64: // IPv4-Compatible IPv6 Address - Map6to4((const in6_addr)m_SocketAddr.sin6_addr, buf); - return true; -#else - case IPv4: // Pure IPv4 Address. - memcpy(&buf, &m_SocketAddr.sin_addr, sizeof(struct in_addr)); - return true; -#endif - - case IPv6: // non-compatible IPv6 Pure Address - default: - // flow through to error case. - // FIXME: debug Log the call to this function ?? - // FIXME: Or return the IPv4 version of 'no address' and let the ACL deal with it?? - return false; - } -} --- squid3/src/IPAddress.h Mon Mar 19 01:19:14 2007 +++ /dev/null Mon Mar 19 01:19:14 2007 @@ -1,123 +0,0 @@ -/* - * $Id: IPAddress.h,v 1.1.2.10 2007/03/18 02:42:45 amosjeffries Exp $ - */ -#ifndef _INC_IPADDRESS_H -#define _INC_IPADDRESS_H - -#include -#include -#include -#include - -/// Specify the type of Address being or to be handled. -enum IPAddressType { - None =0, /// Nothing Secial. Equates to default if used as a parameter. - SockAddr =1, /// Full SocketAddr Details Stored. - IPv4 =2, /// Pure IPv4 address stored (conversion up must be done explicitly) - IPv6 =4, /// Pure IPv6 address Stored (no conversion to IPv4 possible) - IPv64 =6 /// Dual-Address stored (can return either IPv6 OR IPv4) -}; - -/// Length of buffer that needs to be allocated to old a null-terminated IP-string -extern const unsigned int MAX_IPSTRLEN; - -/** - * Holds and manipulates IPv4, IPv6, and Socket Addresses. - */ -class IPAddress -{ -public: - IPAddress(); - IPAddress(const IPAddress &); - IPAddress(const hostent *); - IPAddress(const char*); - IPAddress(const struct in_addr &); - IPAddress(const struct sockaddr_in &); -#ifdef INET6 - IPAddress(const struct in6_addr &); - IPAddress(const struct sockaddr_in6 &); -#endif - ~IPAddress(); - - /** Assignment Operators **/ - IPAddress& operator =(const IPAddress &s); - IPAddress& operator =(const struct hostent *s); - IPAddress& operator =(const char *s); - IPAddress& operator =(struct sockaddr_in const &s); - IPAddress& operator =(struct in_addr const &s); -#ifdef INET6 - IPAddress& operator =(struct in6_addr const &s); - IPAddress& operator =(struct sockaddr_in6 const &s); -#endif - - /* Boolean Operators */ - bool operator ==(IPAddress const &s) const; - bool operator >=(IPAddress const &rhs) const; - bool operator <=(IPAddress const &rhs) const; - -public: - /* methods */ - inline bool IsIPv4() const { return (m_Type & IPv4); }; /// test whether content can be used as an IPv4. - inline bool IsIPv6() const { return (m_Type & IPv6); }; /// test whether content can be used as an IPv6. - inline bool IsSockAddr() const { return (m_Type & SockAddr); }; /// test whether content can be used as a sockaddr (Address and Port combo). - bool IsNoAddr() const; /// Content-neutral test for whether specific IP case ANY_ADDR is stored. - bool IsAnyAddr() const; /// Content-neutral test for whether specific IP case NO_ADDR is stored. - -#ifdef INET6 - bool GetReverseString(char buf[], IPAddressType show_format = IPv6) const; -#else - bool GetReverseString(char buf[], IPAddressType show_format = IPv4) const; -#endif - u_short GetPort() const; - u_short SetPort(u_short port); - void SetAnyAddr(); /// Set object to contain the specific IP case ANY_ADDR (format-neutral). - void SetNoAddr(); /// Set object to contain the specific IP case NO_ADDR (format-neutral). - void SetEmpty(); /// Fast reset of the stored content to what would be after default constructor. - - std::ostream& operator<<(std::ostream& os) const; - char* NtoA(char *buf, unsigned int len) const; - - bool ApplyMask(const IPAddress &); - bool ApplyMask(const unsigned int cidr, IPAddressType mtype = None); - - /* variables */ - - -public: - /* FIXME: When C => C++ conversion is done will be fully private. */ - /* Legacy Transition Methods */ - /* These are here solely to simplify the transition */ - /* when moving from converted code to unconverted */ - /* these functions can be used to convert this object */ - /* and pull out the data needed by the unconverted code */ - /* they are intentionaly hard to use, to encourage less use. */ - - void GetSockAddr(struct sockaddr_in &) const; - bool GetInAddr(struct in_addr &) const; /* false if could not convert IPv6 down to IPv4 */ -#ifdef INET6 - void GetSockAddr(struct sockaddr_in6 &) const; - void GetInAddr(struct in6_addr &) const; -#endif - -private: - /* methods */ - int matchIPAddr(const IPAddress &rhs) const; - /* Conversion for dual-type internals */ - bool GetReverseString4(char buf[], struct in_addr &) const; -#ifdef INET6 - void check4Mapped() const; - bool GetReverseString6(char buf[], struct in6_addr &) const; - void Map4to6(const struct in_addr &src, struct in6_addr &dest); - void Map6to4(const struct in6_addr &src, struct in_addr &dest); -#endif - - /* variables */ - IPAddressType m_Type; -#ifdef INET6 - struct sockaddr_in6 m_SocketAddr; -#else - struct sockaddr_in m_SocketAddr; -#endif -}; - -#endif /* _INC_IPADDRESS_H */ Index: squid3/src/Makefile.am =================================================================== RCS file: /cvsroot/squid-sf//squid3/src/Makefile.am,v retrieving revision 1.58.2.5 retrieving revision 1.58.2.6 diff -u -r1.58.2.5 -r1.58.2.6 --- squid3/src/Makefile.am 9 Mar 2007 11:46:29 -0000 1.58.2.5 +++ squid3/src/Makefile.am 18 Mar 2007 09:07:04 -0000 1.58.2.6 @@ -1,7 +1,7 @@ # # Makefile for the Squid Object Cache server # -# $Id: Makefile.am,v 1.58.2.5 2007/03/09 11:46:29 amosjeffries Exp $ +# $Id: Makefile.am,v 1.58.2.6 2007/03/18 09:07:04 amosjeffries Exp $ # # Uncomment and customize the following to suit your needs: # @@ -512,8 +512,6 @@ $(IDENT_SOURCE) \ int.cc \ internal.cc \ - IPAddress.cc \ - IPAddress.h \ $(IPC_SOURCE) \ ipcache.cc \ $(LEAKFINDERSOURCE) \ @@ -814,8 +812,6 @@ $(IDENT_SOURCE) \ internal.cc \ $(IPC_SOURCE) \ - IPAddress.h \ - IPAddress.cc \ ipcache.cc \ $(LEAKFINDERSOURCE) \ list.cc \