X-Git-Url: http://g0dil.de/git?a=blobdiff_plain;f=Socket%2FINetAddressing.hh;h=d97c83cd1377011bf5125e08c129597edb976d2e;hb=cf4ebe486e7e0543ac8568d3043f43d95f197a96;hp=9b8b160aaae7f1d067a2d6ee63ac7e36ac80adac;hpb=032707d24b1059febe83ce56b11fd79df106c6e2;p=senf.git diff --git a/Socket/INetAddressing.hh b/Socket/INetAddressing.hh index 9b8b160..d97c83c 100644 --- a/Socket/INetAddressing.hh +++ b/Socket/INetAddressing.hh @@ -20,6 +20,10 @@ // Free Software Foundation, Inc., // 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/** \file + \brief INet[46]Address and INet[46]AddressingPolicy public header + */ + #ifndef HH_INetAddressing_ #define HH_INetAddressing_ 1 @@ -37,50 +41,207 @@ namespace senf { + /// \addtogroup addr_group + /// @{ - /** \brief - - \todo Implement real INet4Address datatype and - rename this one to INet4SockAddress ... + /** \brief IPv4 socket address + + INet4Address wrapps the standard sockaddr_in datatype. It provides simple accessor methods + to accss the host and port. It does \e not integrate \c gethostbyname or DNS lookup. + \todo Implement real INet4Address datatype and rename this one to INet4SockAddress ... \todo Implement more complete interface + \todo gethostbyname support ? */ class INet4Address { public: INet4Address(); - INet4Address(char const * address); - INet4Address(std::string address); - INet4Address(std::string host, unsigned port); + INet4Address(char const * address); ///< Set address and port + /**< See INet4Address(std::string) + \throws InvalidINetAddressException + \fixme Why do I need this version? Shouldn't the + std::string version be enough ? */ + INet4Address(std::string address); ///< Set address and port + /**< This constructor expects a string of the form + 'xxx.xxx.xxx.xxx:pppp'. The constructor will use this + value to initialize the host and port members. This + constructor does \e only support numeric ip addresses + not hostnames + \param[in] address Address and port + \throws InvalidINetAddressException */ + INet4Address(std::string host, unsigned port); ///< Set address and port explicitly + /**< \param[in] host ip address in dotted-quad notation + \param[in] port port number + \throws InvalidINetAddressException */ + + + bool operator==(INet4Address const & other) const; ///< Check INet4Address for equality - bool operator==(INet4Address const & other) const; + std::string str() const; ///< Return "address:port" string + std::string host() const; ///< Return address in doted quad notation + unsigned port() const; ///< Return portnumber - std::string str() const; - std::string host() const; - unsigned port() const; + void clear(); ///< Clear address/port to 0.0.0.0:0 - void clear(); + /// \name Generic Address Interface + /// @{ struct sockaddr * sockaddr_p(); struct sockaddr const * sockaddr_p() const; unsigned sockaddr_len() const; + /// @} + private: void assignString(std::string addr); struct ::sockaddr_in addr_; }; + /** \brief Write address and port to os + + \related INet4Address + */ std::ostream & operator<<(std::ostream & os, INet4Address const & addr); - /** \brief + /** \brief IPv6 network address \todo Implement */ class INet6Address { + public: + /////////////////////////////////////////////////////////////////////////// + // Types + + /////////////////////////////////////////////////////////////////////////// + ///\name Structors and default members + ///@{ + + INet6Address(); + INet6Address(std::string const & addr); + INet6Address(char const * addr); + INet6Address(struct in6_addr const & addr); + + ///@} + /////////////////////////////////////////////////////////////////////////// + + void clear(); + std::string address() const; + + bool operator==(INet6Address const & other) const; + bool operator!=(INet6Address const & other) const; + + struct in6_addr & addr(); + struct in6_addr const & addr() const; + struct in6_addr * addr_p(); + struct in6_addr const * addr_p() const; + unsigned addr_len() const; + + protected: + + private: + struct in6_addr addr_; + }; + + std::ostream & operator<<(std::ostream & os, INet6Address const & addr); + + /** \brief IPv6 socket address + + \implementation The sockaddr_in6 structure has an sin6_flowinfo member. However RFC3493 does + not give the use of this field and specifies, that the field should be ignored ... so that's + what we do. Furthermore, the GNU libc reference states, that this field is not implemented + in the library. + + \idea Implement a INet6Address_ref class which has an interface identical to INet6Address + and is convertible to INet6Address (the latter has a conversion constructor taking the + former as arg). This class however references an external in6_addr instead of containing one + itself. This can be used in INet6SocketAddress to increase the performance of some + operations. + */ + class INet6SocketAddress + { + public: + /////////////////////////////////////////////////////////////////////////// + // Types + + /////////////////////////////////////////////////////////////////////////// + ///\name Structors and default members + ///@{ + + INet6SocketAddress(); + INet6SocketAddress(std::string const & addr); + INet6SocketAddress(char const * addr); + INet6SocketAddress(INet6Address const & addr, unsigned port); + INet6SocketAddress(INet6Address const & addr, unsigned port, std::string const & iface); + INet6SocketAddress(std::string const & addr, std::string const & iface); + + ///@} + /////////////////////////////////////////////////////////////////////////// + + bool operator==(INet6SocketAddress const & other) const; + bool operator!=(INet6SocketAddress const & other) const; + + void clear(); + + std::string address() const; + void address(std::string const & addr); + + INet6Address host() const; + void host(INet6Address const & addr); + + unsigned port() const; + void port(unsigned poirt); + + std::string iface() const; + void iface(std::string const & iface); + + ///\name Generic SocketAddress interface + ///@{ + + struct sockaddr * sockaddr_p(); + struct sockaddr const * sockaddr_p() const; + unsigned sockaddr_len() const; + + ///@} + + protected: + + private: + void assignAddr(std::string const & addr); + void assignIface(std::string const & iface); + + struct sockaddr_in6 sockaddr_; }; - + + std::ostream & operator<<(std::ostream & os, INet6SocketAddress const & addr); + + /** \brief Signal invalid INet address syntax + + \related INet4Address + \relatesalso INet6Address + */ + struct InvalidINetAddressException : public std::exception + { char const * what() const throw() { return "invalid inet address"; } }; + + /// @} + + /// \addtogroup policy_impl_group + /// @{ + + /** \brief Addressing policy supporting IPv4 addressing + + \par Address Type: + INet4Address + + This addressing policy implements addressing using Internet V4 + addresses. + + The various members are directly importet from + GenericAddressingPolicy which see for a detailed + documentation. + */ struct INet4AddressingPolicy : public AddressingPolicyBase, private GenericAddressingPolicy @@ -93,17 +254,33 @@ namespace senf { using GenericAddressingPolicy::bind; }; - /** \brief + /** \brief Addressing policy supporting IPv6 addressing + + \par Address Type: + INet6Address + + This addressing policy implements addressing using Internet V6 + addresses. - \todo Implement + The various members are directly importet from + GenericAddressingPolicy which see for a detailed + documentation. + + \todo implement */ - struct INet6AddressingPolicy : public AddressingPolicyBase + struct INet6AddressingPolicy + : public AddressingPolicyBase, + private GenericAddressingPolicy { - typedef INet6Address Address; + typedef INet6SocketAddress Address; + + using GenericAddressingPolicy::peer; + using GenericAddressingPolicy::local; + using GenericAddressingPolicy::connect; + using GenericAddressingPolicy::bind; }; - struct InvalidINetAddressException : public std::exception - { char const * what() const throw() { return "invalid inet address"; } }; + /// @} } @@ -118,4 +295,5 @@ namespace senf { // Local Variables: // mode: c++ // c-file-style: "senf" +// fill-column: 100 // End: