Patch file generated Sat Apr  7 15:24:21 NZST 2007 from
CVS branch squid3-ipv6
CVS base branch HEAD
CVS repository: amosjeffries@cvs.devel.squid-cache.org:/cvsroot/squid
CVS module: squid3/include

cvs -q rdiff -u -kk -r Z-squid3-ipv6_merge_HEAD -r squid3-ipv6 squid3/include
Index: squid3/include/IPAddress.h
diff -u /dev/null squid3/include/IPAddress.h:1.1.2.8
--- /dev/null		Thu Jan  1 01:00:00 1970
+++ squid3/include/IPAddress.h	Thu Apr  5 02:47:56 2007
@@ -0,0 +1,230 @@
+/*
+ * $Id$
+ */
+#ifndef _INC_IPADDRESS_H
+#define _INC_IPADDRESS_H
+
+#include "autoconf.h"
+
+#include <sys/socket.h>
+#include <netinet/in.h>
+#include <iostream>
+#include <netdb.h>
+
+
+/// Specify the type of Address being or to be handled.
+enum IPAddressType {
+        None     =0, ///< Nothing Special. Equates to default if used as a parameter.
+        SockAddr =1, ///< Full SocketAddr Details Stored. Port and Address can be used together or seperately.
+        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
+// Yuck. But there are still structures that need it to be an 'integer constant'.
+#define MAX_IPSTRLEN  75
+
+/**
+ * Holds and manipulates IPv4, IPv6, and Socket Addresses.
+ */
+class IPAddress
+{
+public:
+  /** @name Constructors and Destructor */
+  /*@{*/
+    // default constructor.
+    IPAddress();
+    IPAddress(const IPAddress &);
+    IPAddress(const struct in_addr &);
+    IPAddress(const struct sockaddr_in &);
+#ifdef USE_IPV6
+    IPAddress(const struct in6_addr &);
+    IPAddress(const struct sockaddr_in6 &);
+#endif
+    IPAddress(const hostent *);
+    IPAddress(const char*);
+    /// Default destructor.
+    ~IPAddress();
+    /*@}*/
+
+    /** @name Assignment Operators */
+    /*@{*/
+    IPAddress& operator =(const IPAddress &s);
+    IPAddress& operator =(struct sockaddr_in const &s);
+    IPAddress& operator =(struct in_addr const &s);
+#ifdef USE_IPV6
+    IPAddress& operator =(struct in6_addr const &s);
+    IPAddress& operator =(struct sockaddr_in6 const &s);
+#endif
+    bool operator =(const struct hostent *s);
+    bool operator =(const char *s);
+    /*@}*/
+
+    /** @name Boolean Operators */
+    /*@{*/
+    bool operator ==(IPAddress const &s) const;
+    bool operator >=(IPAddress const &rhs) const;
+    bool operator <=(IPAddress const &rhs) const;
+
+public:
+  /* methods */
+
+            /** Test whether content can be used as an IPv4 address
+             *  \retval true  if content was received as an IPv4 address
+             *  \retval true  if content was received as an IPv4-Mapped address
+             *  \retval false if content was received as a non-mapped IPv6 native address.
+             */
+    inline bool IsIPv4() const { return (m_Type & IPv4); };
+
+            /** Test whether content can be used as an IPv6 address.
+             *  \retval true  if --enable-ipv6 has been compiled.
+             *  \retval false if --disable-ipv6 has been compiled.
+             *  \retval false if --with-ipv6-split-stack has been compiled AND content is IPv4-mapped.
+             */
+    inline bool IsIPv6() const {
+            return (m_Type & IPv6)
+#ifdef USE_IPV6_SPLITSTACK
+                    && !(m_Type & IPv4)
+#endif
+            ;
+        };
+
+            /** Test whether content can be used as a Socket address.
+             *  \retval true  if address AND port are both set
+             *  \retval true  if content was received as a Socket address
+             *  \retval false if port in unset (zero)
+             */
+    inline bool IsSockAddr() const { return (m_Type & SockAddr); };
+
+            /** Content-neutral test for whether the specific IP case ANY_ADDR is stored.
+             *  This is the default content of a new undefined IPAddress object.
+             *  \retval true IPv4 0.0.0.0
+             *  \retval true IPv6 ::
+             *  \retval false anything else.
+             */
+    bool IsAnyAddr() const;
+            /** Content-neutral test for whether the specific IP case NO_ADDR is stored.
+             *  \retval true IPv4 255.255.255.255
+             *  \retval true IPv6 ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff
+             *  \retval false anything else.
+             */
+    bool IsNoAddr() const;
+    /*@}*/
+
+           /** Retrieve the Port if stored.
+            *  \retval 0 Port is unset or an error occured.
+            *  \retval n Port associated with this address in host native -endian.
+            */
+    u_short GetPort() const;
+           /** Set the Port value for an address.
+            *  Replaces any previously existing Port value.
+            *  \param port Port being assigned in host native -endian.
+            *  \retval 0 Port is unset or an error occured.
+            *  \retval n Port associated with this address in host native -endian.
+            */
+    u_short SetPort(u_short port);
+
+           /// Set object to contain the specific IP case ANY_ADDR (format-neutral).
+           /// see IsAnyAddr() for more detail.
+    void SetAnyAddr();
+
+           /// Set object to contain the specific IP case NO_ADDR (format-neutral).
+           /// see \link IsNoAddr() for more detail.
+    void SetNoAddr();
+
+           /// Fast reset of the stored content to what would be after default constructor.
+    void SetEmpty();
+
+           /** Apply a mask to the stored address.
+            *  \param mask Netmask format to be bit-mask-AND'd over the stored address.
+            */
+    const int ApplyMask(const IPAddress &mask);
+
+           /** Apply a mask to the stored address.
+            *  CIDR will be converted appropriate to map the stored content.
+            *  \param cidr   CIDR Mask being applied. As an integer in host format.
+            *  \param mtype  Type of CIDR mask being applied (IPv4,IPv6, or None for default)
+            */
+    bool ApplyMask(const unsigned int cidr, IPAddressType mtype = None);
+
+
+           /** Return the ASCII equivalent of the address
+            *  Semantically equivalent to the IPv4 inet_ntoa()
+            *  eg. 127.0.0.1 (IPv4) or ::1 (IPv6)
+            *  But for memory safety it requires a buffer as input
+            *  instead of producing one magically.
+            *  If buffer is not large enough the data is truncated silently.
+            * \param buf Allocated buffer to write address to
+            * \param len byte length of buffer available for writing.
+            * \return pointer to buffer received.
+            */
+    char* NtoA(char *buf, unsigned int len) const;
+
+           /** Return the ASCII equivalent of the address:port combination
+            *  Provides a URL formatted version of the content.
+            *  If buffer is not large enough the data is truncated silently.
+            *  eg. 127.0.0.1:80 (IPv4) or [::1]:80 (IPv6)
+            * \param buf Allocated buffer to write address:port to
+            * \param len byte length of buffer available for writing.
+            * \return pointer to buffer received.
+            */
+    char* ToURL(char *buf, unsigned int len) const;
+
+           /** \fn bool GetReverseString(char buf[], IPAddressType show_format)
+            *  Convert the content into a Reverse-DNS string.
+            *  The buffer sent MUST be allocated large enough to hold the resulting string.
+            *  Name truncation will occur if buf does not have enough space.
+            *  The constant MAX_IPSTRLEN is defined to provide for sizing arrays correctly.
+            *  \param show_format may be one of: IPv4,IPv6 for the format of rDNS string wanted.
+            *  \param buf buffer to receive the text string output.
+            */
+#ifdef USE_IPV6
+    bool GetReverseString(char buf[], IPAddressType show_format = IPv6) const;
+#else
+    bool GetReverseString(char buf[], IPAddressType show_format = IPv4) const;
+#endif
+
+#ifdef _GLIBCXX_IOSTREAM
+    std::ostream& operator<<(std::ostream& os) const;
+#endif
+
+
+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 USE_IPV6
+    void GetSockAddr(struct sockaddr_in6 &) const;
+    void GetInAddr(struct in6_addr &) const;
+#endif
+
+private:
+    int matchIPAddr(const IPAddress &rhs) const;
+    /* Conversion for dual-type internals */
+    bool GetReverseString4(char buf[], struct in_addr &) const;
+#ifdef USE_IPV6
+    void check4Mapped();
+    bool GetReverseString6(char buf[], struct in6_addr &) const;
+    void Map4to6(const struct in_addr &src, struct in6_addr &dest) const;
+    void Map6to4(const struct in6_addr &src, struct in_addr &dest) const;
+#endif
+
+  /* variables */
+    IPAddressType m_Type;
+#ifdef USE_IPV6
+    struct sockaddr_in6 m_SocketAddr;
+#else
+    struct sockaddr_in m_SocketAddr;
+#endif
+};
+
+#endif /* _INC_IPADDRESS_H */
Index: squid3/include/util.h
diff -u squid3/include/util.h:1.15 squid3/include/util.h:1.10.8.10
--- squid3/include/util.h:1.15	Sat Oct 14 06:51:15 2006
+++ squid3/include/util.h	Thu Apr  5 02:26:32 2007
@@ -43,6 +43,7 @@
 #if HAVE_SYS_TIME_H
 #include <sys/time.h>
 #endif
+#include <arpa/inet.h>
 
 #if !defined(SQUIDHOSTNAMELEN)
 #define SQUIDHOSTNAMELEN 256
@@ -123,8 +124,7 @@
 extern void xmalloc_find_leaks(void);
 #endif
 
-typedef struct IN_ADDR SIA;
-SQUIDCEXTERN int safe_inet_addr(const char *, SIA *);
+SQUIDCEXTERN int safe_inet_addr(const char *, struct in_addr *);
 SQUIDCEXTERN time_t parse_iso3307_time(const char *buf);
 SQUIDCEXTERN char *base64_decode(const char *coded);
 SQUIDCEXTERN const char *base64_encode(const char *decoded);

