Packets: Fix VariantParser invalid parser access bug
[senf.git] / Socket / Protocols / INet / INetAddressing.hh
index f2972e0..f9327b5 100644 (file)
@@ -1,9 +1,9 @@
 // $Id$
 //
 // Copyright (C) 2006
-// Fraunhofer Institut fuer offene Kommunikationssysteme (FOKUS)
-// Kompetenzzentrum fuer Satelitenkommunikation (SatCom)
-//     Stefan Bund <stefan.bund@fokus.fraunhofer.de>
+// Fraunhofer Institute for Open Communication Systems (FOKUS)
+// Competence Center NETwork research (NET), St. Augustin, GERMANY
+//     Stefan Bund <g0dil@berlios.de>
 //
 // 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
     \brief INet[46]Address and INet[46]AddressingPolicy public header
  */
 
-#ifndef HH_INetAddressing_
-#define HH_INetAddressing_ 1
+#ifndef HH_SENF_Socket_Protocols_INet_INetAddressing_
+#define HH_SENF_Socket_Protocols_INet_INetAddressing_ 1
 
 // Custom includes
 #include <string>
 #include <exception>
 #include <netinet/in.h>
-#include <boost/operators.hpp>
-#include "../../../Socket/SocketPolicy.hh"
-#include "../../../Socket/ClientSocketHandle.hh"
-#include "../../../Socket/CommunicationPolicy.hh"
-#include "../../../Socket/Protocols/GenericAddressingPolicy.hh"
-#include "../../../Utils/safe_bool.hh"
+#include "../../SocketPolicy.hh"
+#include "../../ClientSocketHandle.hh"
+#include "../../CommunicationPolicy.hh"
+#include "../BSDAddressingPolicy.hh"
+#include "../BSDSocketAddress.hh"
 #include "INet4Address.hh"
 #include "INet6Address.hh"
 
@@ -56,10 +55,15 @@ namespace senf {
         \ingroup addr_group
      */
     class INet4SocketAddress
-        : public boost::equality_comparable<INet4SocketAddress>, 
-          public senf::comparable_safe_bool<INet4SocketAddress>
+        : public BSDSocketAddress
     {
     public:
+        static short const addressFamily = AF_INET;
+
+        ///////////////////////////////////////////////////////////////////////////
+        ///\name Structors and default members
+        ///@{
+
         INet4SocketAddress();
         explicit INet4SocketAddress(std::string const & addr); ///< Set address and port
                                         /**< This constructor expects a string of the form
@@ -67,9 +71,9 @@ namespace senf {
                                              initialize the host and port members. Since it uses the
                                              INet4Address::from_string constructor, this call may
                                              block while waiting for the resolver.
-                                             \throws SyntaxException if the address syntax is
+                                             \throws AddressSyntaxException if the address syntax is
                                                  invalid
-                                             \throws INet4Address::UnknownHostnameException if the
+                                             \throws UnknownHostnameException if the
                                                  address cannot be resolved. */
 
         INet4SocketAddress(INet4Address const & addr, unsigned port); 
@@ -77,31 +81,24 @@ namespace senf {
                                         /**< \param[in] addr IP address
                                              \param[in] port port number */
 
-        bool operator==(INet4SocketAddress const & other) const;
-                                        ///< Check INet4SocketAddress for equality
+        explicit INet4SocketAddress(unsigned port);
+                                        ///< Set port, address is set to 0.0.0.0
+                                        /**< \param[in] port port number */
 
-        INet4Address address() const;   ///< Return address
-        unsigned port() const;          ///< Return port number
+        INet4SocketAddress(const INet4SocketAddress& other);
+        INet4SocketAddress& operator=(const INet4SocketAddress& other);
 
-        bool boolean_test() const;      ///< \c true, if address is empty (i.e. 0.0.0.0:0)
+        ///@}
+        ///////////////////////////////////////////////////////////////////////////
 
-        void clear();                   ///< Clear address/port to 0.0.0.0:0
+        INet4Address address() const;   ///< Return address
+        unsigned port() const;          ///< Return port number
 
         void address(INet4Address const & addr); ///< Set address
         void port(unsigned p);          ///< Set port number
 
-        /// \name Generic Address Interface
-        /// @{
-
-        struct sockaddr * sockaddr_p();
-        struct sockaddr const * sockaddr_p() const;
-        unsigned sockaddr_len() const;
-
-        /// @}
-
-        struct SyntaxException : public std::exception
-        { virtual char const * what() const throw() 
-                { return "Invalid IpV4 socket address syntax"; } };
+        using BSDSocketAddress::sockaddr_p;
+        using BSDSocketAddress::socklen_p;
 
     private:
         struct ::sockaddr_in addr_;
@@ -145,10 +142,10 @@ namespace senf {
         \ingroup addr_group
      */
     class INet6SocketAddress
+        : public BSDSocketAddress
     {
     public:
-        ///////////////////////////////////////////////////////////////////////////
-        // Types
+        static short const addressFamily = AF_INET6;
 
         ///////////////////////////////////////////////////////////////////////////
         ///\name Structors and default members
@@ -158,29 +155,30 @@ namespace senf {
         explicit INet6SocketAddress(std::string const & addr, 
                                     INet6Address::Resolve_t resolve = INet6Address::ResolveINet6);
                                         ///< Initialize/convert from string representation
-                                        /**< \throws SyntaxException if the address syntax is
+                                        /**< \throws AddressSyntaxException if the address syntax is
                                                  invalid
-                                             \throws INet6Address::UnknownHostnameException if the
+                                             \throws UnknownHostnameException if the
                                                  address cannot be resolved.
                                              \param[in] addr Address to parse
                                              \param[in] resolve If this is
-                                                 INet6Address::ResolveINet4, support IpV4
+                                                 INet6Address::ResolveINet4, support IPv4
                                                  addresses. See INet6Address. */
         INet6SocketAddress(INet6Address const & addr, unsigned port);
                                         ///< Initialize from address and port
         INet6SocketAddress(INet6Address const & addr, unsigned port, std::string const & iface);
                                         ///< Initialize explicitly from given parameters
+        explicit INet6SocketAddress(unsigned port);
+                                        ///< Initialize from port and set to 'unspecified' addr
+                                        /**< The address is set to [::]
+                                             \param[in] port port number  */
+
+        INet6SocketAddress(const INet6SocketAddress& other);
+        INet6SocketAddress& operator=(const INet6SocketAddress& other);
 
         ///@}
         ///////////////////////////////////////////////////////////////////////////
 
-        bool operator==(INet6SocketAddress const & other) const; ///< Check addresses for equality
-        bool operator!=(INet6SocketAddress const & other) const; ///< Inverse of above
-
-        void clear();                   ///< Clear socket address
-
         INet6Address address() const;    ///< Get printable address representation
-
         void address(INet6Address const & addr); ///< Change address
 
         unsigned port() const;          ///< Get port number
@@ -189,18 +187,8 @@ namespace senf {
         std::string iface() const;      ///< Get interface name
         void iface(std::string const & iface); ///< Change interface
 
-        ///\name Generic SocketAddress interface
-        ///@{
-
-        struct sockaddr * sockaddr_p();
-        struct sockaddr const * sockaddr_p() const;
-        unsigned sockaddr_len() const;
-
-        ///@}
-
-        struct SyntaxException : public std::exception
-        { virtual char const * what() const throw() 
-                { return "Invalid IpV6 socket address syntax"; } };
+        using BSDSocketAddress::sockaddr_p;
+        using BSDSocketAddress::socklen_p;
 
     protected:
 
@@ -221,25 +209,25 @@ namespace senf {
     /** \brief Addressing policy supporting IPv4 addressing
 
         \par Address Type:
-            INet4Address
+            INet4SocketAddress
 
         This addressing policy implements addressing using Internet V4
         addresses.
 
         The various members are directly imported from
-        GenericAddressingPolicy which see for a detailed
+        BSDAddressingPolicyMixin which see for a detailed
         documentation.
      */
     struct INet4AddressingPolicy
-        : public AddressingPolicyBase,
-          private GenericAddressingPolicy<INet4SocketAddress>
+        : public BSDAddressingPolicy,
+          private BSDAddressingPolicyMixin<INet4SocketAddress>
     {
         typedef INet4SocketAddress Address;
 
-        using GenericAddressingPolicy<INet4SocketAddress>::peer;
-        using GenericAddressingPolicy<INet4SocketAddress>::local;
-        using GenericAddressingPolicy<INet4SocketAddress>::connect;
-        using GenericAddressingPolicy<INet4SocketAddress>::bind;
+        using BSDAddressingPolicyMixin<INet4SocketAddress>::peer;
+        using BSDAddressingPolicyMixin<INet4SocketAddress>::local;
+        using BSDAddressingPolicyMixin<INet4SocketAddress>::connect;
+        using BSDAddressingPolicyMixin<INet4SocketAddress>::bind;
     };
 
     /** \brief Addressing policy supporting IPv6 addressing
@@ -251,19 +239,19 @@ namespace senf {
         addresses.
 
         The various members are directly imported from
-        GenericAddressingPolicy which see for a detailed
+        BSDAddressingPolicyMixin which see for a detailed
         documentation.
      */
     struct INet6AddressingPolicy
-        : public AddressingPolicyBase,
-          private GenericAddressingPolicy<INet6SocketAddress>
+        : public BSDAddressingPolicy,
+          private BSDAddressingPolicyMixin<INet6SocketAddress>
     {
         typedef INet6SocketAddress Address;
 
-        using GenericAddressingPolicy<INet6SocketAddress>::peer;
-        using GenericAddressingPolicy<INet6SocketAddress>::local;
-        using GenericAddressingPolicy<INet6SocketAddress>::connect;
-        using GenericAddressingPolicy<INet6SocketAddress>::bind;
+        using BSDAddressingPolicyMixin<INet6SocketAddress>::peer;
+        using BSDAddressingPolicyMixin<INet6SocketAddress>::local;
+        using BSDAddressingPolicyMixin<INet6SocketAddress>::connect;
+        using BSDAddressingPolicyMixin<INet6SocketAddress>::bind;
     };
 
     /// @}