4 // Fraunhofer Institut fuer offene Kommunikationssysteme (FOKUS)
5 // Kompetenzzentrum fuer Satelitenkommunikation (SatCom)
6 // Stefan Bund <stefan.bund@fokus.fraunhofer.de>
8 // This program is free software; you can redistribute it and/or modify
9 // it under the terms of the GNU General Public License as published by
10 // the Free Software Foundation; either version 2 of the License, or
11 // (at your option) any later version.
13 // This program is distributed in the hope that it will be useful,
14 // but WITHOUT ANY WARRANTY; without even the implied warranty of
15 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 // GNU General Public License for more details.
18 // You should have received a copy of the GNU General Public License
19 // along with this program; if not, write to the
20 // Free Software Foundation, Inc.,
21 // 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
24 \brief INet[46]Address and INet[46]AddressingPolicy public header
27 #ifndef HH_INetAddressing_
28 #define HH_INetAddressing_ 1
33 #include <netinet/in.h>
34 #include "SocketPolicy.hh"
35 #include "ClientSocketHandle.hh"
36 #include "CommunicationPolicy.hh"
37 #include "GenericAddressingPolicy.hh"
39 //#include "INetAddressing.mpp"
40 ///////////////////////////////hh.p////////////////////////////////////////
44 /// \addtogroup addr_group
47 /** \brief IPv4 socket address
49 INet4Address wrapps the standard sockaddr_in datatype. It provides simple accessor methods
50 to accss the host and port. It does \e not integrate \c gethostbyname or DNS lookup.
52 \todo Implement real INet4Address datatype and rename this one to INet4SockAddress ...
53 \todo Implement more complete interface
54 \todo gethostbyname support ?
60 INet4Address(char const * address); ///< Set address and port
61 /**< See INet4Address(std::string)
62 \throws InvalidINetAddressException
63 \fixme Why do I need this version? Shouldn't the
64 std::string version be enough ? */
65 INet4Address(std::string address); ///< Set address and port
66 /**< This constructor expects a string of the form
67 'xxx.xxx.xxx.xxx:pppp'. The constructor will use this
68 value to initialize the host and port members. This
69 constructor does \e only support numeric ip addresses
71 \param[in] address Address and port
72 \throws InvalidINetAddressException */
73 INet4Address(std::string host, unsigned port); ///< Set address and port explicitly
74 /**< \param[in] host ip address in dotted-quad notation
75 \param[in] port port number
76 \throws InvalidINetAddressException */
79 bool operator==(INet4Address const & other) const; ///< Check INet4Address for equality
81 std::string str() const; ///< Return "address:port" string
82 std::string host() const; ///< Return address in doted quad notation
83 unsigned port() const; ///< Return portnumber
85 void clear(); ///< Clear address/port to 0.0.0.0:0
87 /// \name Generic Address Interface
90 struct sockaddr * sockaddr_p();
91 struct sockaddr const * sockaddr_p() const;
92 unsigned sockaddr_len() const;
97 void assignString(std::string addr);
99 struct ::sockaddr_in addr_;
102 /** \brief Write address and port to os
104 \related INet4Address
106 std::ostream & operator<<(std::ostream & os, INet4Address const & addr);
108 /** \brief IPv6 socket address
116 /** \brief Signal invalid INet address syntax
118 \related INet4Address
119 \relatesalso INet6Address
121 struct InvalidINetAddressException : public std::exception
122 { char const * what() const throw() { return "invalid inet address"; } };
126 /// \addtogroup policy_impl_group
129 /** \brief Addressing policy supporting IPv4 addressing
134 This addressing policy implements addressing using Internet V4
137 The various members are directly importet from
138 GenericAddressingPolicy which see for a detailed
141 struct INet4AddressingPolicy
142 : public AddressingPolicyBase,
143 private GenericAddressingPolicy<INet4Address>
145 typedef INet4Address Address;
147 using GenericAddressingPolicy<INet4Address>::peer;
148 using GenericAddressingPolicy<INet4Address>::local;
149 using GenericAddressingPolicy<INet4Address>::connect;
150 using GenericAddressingPolicy<INet4Address>::bind;
153 /** \brief Addressing policy supporting IPv6 addressing
158 This addressing policy implements addressing using Internet V6
161 The various members are directly importet from
162 GenericAddressingPolicy which see for a detailed
167 struct INet6AddressingPolicy : public AddressingPolicyBase
169 typedef INet6Address Address;
176 ///////////////////////////////hh.e////////////////////////////////////////
177 #include "INetAddressing.cci"
178 //#include "INetAddressing.ct"
179 //#include "INetAddressing.cti"
180 //#include "INetAddressing.mpp"
186 // c-file-style: "senf"