--------------------- PatchSet 4103 Date: 2007/03/18 13:54:08 Author: amosjeffries Branch: squid3-ipv6 Tag: (none) Log: Cleaned out old code experiments. Added debug (stderr) output on some error cases. Completed most of the existing TODO list. Members: lib/IPAddress.cc:1.1.2.1->1.1.2.2 Index: squid3/lib/IPAddress.cc =================================================================== RCS file: /cvsroot/squid-sf//squid3/lib/Attic/IPAddress.cc,v retrieving revision 1.1.2.1 retrieving revision 1.1.2.2 diff -u -r1.1.2.1 -r1.1.2.2 --- squid3/lib/IPAddress.cc 18 Mar 2007 09:07:02 -0000 1.1.2.1 +++ squid3/lib/IPAddress.cc 18 Mar 2007 13:54:08 -0000 1.1.2.2 @@ -1,5 +1,5 @@ /* - * $Id: IPAddress.cc,v 1.1.2.1 2007/03/18 09:07:02 amosjeffries Exp $ + * $Id: IPAddress.cc,v 1.1.2.2 2007/03/18 13:54:08 amosjeffries Exp $ */ #include "IPAddress.h" @@ -225,12 +225,8 @@ } #endif - /* FIXME: an error occured. invalid address type */ - // return an empty string for the buffer, and log an error + fprintf(stderr,"ERROR: IPAddress::GetReverseString : Address stored cannot be converted to type requested.\n"); buf[0] = '\0'; - -// TODO debug output a warning. - return false; } @@ -249,11 +245,9 @@ { 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(); + fprintf(stderr, "IPAddress:::operator= : Given Bad IP '%s'\n", s); + return *this; } return operator=(hp->h_addr_list[0]); @@ -262,17 +256,6 @@ 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) { @@ -303,12 +286,6 @@ 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) { @@ -323,19 +300,6 @@ 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 @@ -355,17 +319,9 @@ #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; @@ -377,11 +333,6 @@ 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); } @@ -414,7 +365,8 @@ #ifdef INET6 /* this */ operator=(*ipv6); #else - // FIXME : Log the discarded address. + fprintf(stderr, "IPAddress::operator= : Discarded IPv6 Address. Protocol disabled (temporary).\n"); + // TODO see if there is another address in the list that might be usable ?? #endif break; @@ -483,6 +435,16 @@ return prt; } +/** + * NtoA 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 if provided in the form of a defined variable MAX_IPSTRLEN + * Should a buffer shorter be provided the string result will be truncated + * at the length of the available buffer. + * + * A copy of the buffer is also returned for simple immediate display. + */ char* IPAddress::NtoA(char* buf, unsigned int blen) const { char t[MAX_IPSTRLEN]; @@ -490,7 +452,7 @@ // Ensure we have a buffer. if(buf == NULL) { - // TODO debug output a warning. + fprintf(stderr,"IPAddress::NtoA : Buffer received has no allocated space.\n"); return NULL; } @@ -574,9 +536,8 @@ 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?? + fprintf(stderr,"IPAddress::GetInAddr : Cannot convert non-IP to IPv4.\n"); + memset(&buf,0xFFFFFFFF,sizeof(struct in_addr)); return false; } }