Fix documentation build under maverick (doxygen 1.7.1)
[senf.git] / senf / Socket / Protocols / INet / INetAddressing.hh
1 // $Id$
2 //
3 // Copyright (C) 2006
4 // Fraunhofer Institute for Open Communication Systems (FOKUS)
5 // Competence Center NETwork research (NET), St. Augustin, GERMANY
6 //     Stefan Bund <g0dil@berlios.de>
7 //
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.
12 //
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.
17 //
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.
22
23 /** \file
24     \brief INet[46]Address and INet[46]AddressingPolicy public header
25  */
26
27 #ifndef HH_SENF_Socket_Protocols_INet_INetAddressing_
28 #define HH_SENF_Socket_Protocols_INet_INetAddressing_ 1
29
30 // Custom includes
31 #include <string>
32 #include <netinet/in.h>
33 #include <senf/Socket/Protocols/BSDAddressingPolicy.hh>
34 #include <senf/Socket/Protocols/BSDSocketAddress.hh>
35 #include "INet4Address.hh"
36 #include "INet6Address.hh"
37
38 //#include "INetAddressing.mpp"
39 //-/////////////////////////////////////////////////////////////////////////////////////////////////
40
41 namespace senf {
42
43     /** \brief IPv4 socket address
44
45         INet4Address wraps the standard sockaddr_in datatype. It provides simple accessor methods
46         to access the host and port. It does \e not integrate \c gethostbyname or DNS lookup.
47
48         \implementation This implementation is based on sockaddr_in, which is needed since it needs
49             to provide a non-const struct sockaddr * for legacy compatibility.
50
51         \ingroup addr_group
52      */
53     class INet4SocketAddress
54         : public BSDSocketAddress
55     {
56     public:
57         static short const addressFamily = AF_INET;
58
59         //-////////////////////////////////////////////////////////////////////////
60         ///\name Structors and default members
61         //\{
62
63         INet4SocketAddress();
64         explicit INet4SocketAddress(std::string const & addr); ///< Set address and port
65                                         /**< This constructor expects a string of the form
66                                              'host:port'. The constructor will use this value to
67                                              initialize the host and port members. Since it uses the
68                                              INet4Address::from_string constructor, this call may
69                                              block while waiting for the resolver.
70                                              \throws AddressSyntaxException if the address syntax is
71                                                  invalid
72                                              \throws UnknownHostnameException if the
73                                                  address cannot be resolved. */
74
75         INet4SocketAddress(INet4Address const & addr, unsigned port);
76                                         ///< Set address and port explicitly
77                                         /**< \param[in] addr IP address
78                                              \param[in] port port number */
79
80         explicit INet4SocketAddress(unsigned port);
81                                         ///< Set port, address is set to 0.0.0.0
82                                         /**< \param[in] port port number */
83
84         INet4SocketAddress(const INet4SocketAddress& other);
85         INet4SocketAddress& operator=(const INet4SocketAddress& other);
86
87         //\}
88         //-////////////////////////////////////////////////////////////////////////
89
90         INet4Address address() const;   ///< Return address
91         unsigned port() const;          ///< Return port number
92
93         void address(INet4Address const & addr); ///< Set address
94         void port(unsigned p);          ///< Set port number
95
96         using BSDSocketAddress::sockaddr_p;
97         using BSDSocketAddress::socklen_p;
98
99     private:
100         struct ::sockaddr_in addr_;
101     };
102
103     /** \brief Write address and port to os
104
105         \related INet4SocketAddress
106      */
107     std::ostream & operator<<(std::ostream & os, INet4SocketAddress const & addr);
108     std::istream & operator>>(std::istream & is, INet4SocketAddress & addr);
109
110     /** \brief IPv6 socket address
111
112         This class wraps the standard \c sockaddr_in6 structure. INet6SocketAddress provides access
113         to all members of the sockaddr_in6 structure. Additionally, INet6SocketAddress supports the
114         string representations
115
116         \par ""
117             <tt>[</tt> <i>address</i> [ <tt>%</tt> <i>zone-id</i> ] <tt>]:</tt> <i>port</i> \n
118             <i>hostname</i> <tt>:</tt> <i>port</i>
119
120         Where \e address is an arbitrary numeric IPv6 address, \e zone-id is an optional network
121         interface name and \e port is the port number. So some example addresses are
122
123         \par ""
124             <tt>[2001:db8:1::1]:80</tt> \n
125             <tt>www.go6.net:80</tt> \n
126             <tt>[fe80::1\%eth0]:443</tt>
127
128         \implementation The sockaddr_in6 structure has an sin6_flowinfo member. However RFC3493 does
129             not give the use of this field and specifies, that the field should be ignored ... so
130             that's what we do. Furthermore, the GNU libc reference states, that this field is not
131             implemented in the library.
132
133         \idea Implement a INet6Address_ref class which has an interface identical to INet6Address
134             and is convertible to INet6Address (the latter has a conversion constructor taking the
135             former as arg). This class however references an external in6_addr instead of containing
136             one itself. This can be used in INet6SocketAddress to increase the performance of some
137             operations.
138
139         \ingroup addr_group
140      */
141     class INet6SocketAddress
142         : public BSDSocketAddress
143     {
144     public:
145         static short const addressFamily = AF_INET6;
146
147         //-////////////////////////////////////////////////////////////////////////
148         ///\name Structors and default members
149         //\{
150
151         INet6SocketAddress();           ///< Create empty instance
152         explicit INet6SocketAddress(std::string const & addr,
153                                     INet6Address::Resolve_t resolve = INet6Address::ResolveINet6);
154                                         ///< Initialize/convert from string representation
155                                         /**< \throws AddressSyntaxException if the address syntax is
156                                                  invalid
157                                              \throws UnknownHostnameException if the
158                                                  address cannot be resolved.
159                                              \param[in] addr Address to parse
160                                              \param[in] resolve If this is
161                                                  INet6Address::ResolveINet4, support IPv4
162                                                  addresses. See INet6Address. */
163         INet6SocketAddress(INet6Address const & addr, unsigned port);
164                                         ///< Initialize from address and port
165         INet6SocketAddress(INet6Address const & addr, unsigned port, std::string const & iface);
166                                         ///< Initialize explicitly from given parameters
167                                         /**< \throws AddressSyntaxException if the
168                                                 given iface cannot be resolved. */
169         explicit INet6SocketAddress(unsigned port);
170                                         ///< Initialize from port and set to 'unspecified' addr
171                                         /**< The address is set to [::]
172                                              \param[in] port port number  */
173
174         INet6SocketAddress(const INet6SocketAddress& other);
175         INet6SocketAddress& operator=(const INet6SocketAddress& other);
176
177         //\}
178         //-////////////////////////////////////////////////////////////////////////
179
180         INet6Address address() const;    ///< Get printable address representation
181         void address(INet6Address const & addr); ///< Change address
182
183         unsigned port() const;          ///< Get port number
184         void port(unsigned port);       ///< Change port number
185
186         std::string iface() const;      ///< Get interface name
187         void iface(std::string const & iface); ///< Change interface
188                                                /**< \throws AddressSyntaxException if the
189                                                         given iface cannot be resolved. */
190
191         using BSDSocketAddress::sockaddr_p;
192         using BSDSocketAddress::socklen_p;
193
194     protected:
195
196     private:
197         void assignIface(std::string const & iface);
198
199         struct sockaddr_in6 sockaddr_;
200     };
201
202     /** \brief Output INet6SocketAddress instance as it's string representation
203         \related INet6SocketAddress
204      */
205     std::ostream & operator<<(std::ostream & os, INet6SocketAddress const & addr);
206     std::istream & operator>>(std::istream & is, INet6SocketAddress & addr);
207
208     /// \addtogroup policy_impl_group
209     //\{
210
211     /** \brief Addressing policy supporting IPv4 addressing
212
213         \par Address Type:
214             INet4SocketAddress
215
216         This addressing policy implements addressing using Internet V4
217         addresses.
218
219         The various members are directly imported from
220         BSDAddressingPolicyMixin which see for a detailed
221         documentation.
222      */
223     struct INet4AddressingPolicy
224         : public BSDAddressingPolicy,
225           private BSDAddressingPolicyMixin<INet4SocketAddress>
226     {
227         typedef INet4SocketAddress Address;
228
229         using BSDAddressingPolicyMixin<INet4SocketAddress>::peer;
230         using BSDAddressingPolicyMixin<INet4SocketAddress>::local;
231         using BSDAddressingPolicyMixin<INet4SocketAddress>::connect;
232         using BSDAddressingPolicyMixin<INet4SocketAddress>::bind;
233     };
234
235     /** \brief Addressing policy supporting IPv6 addressing
236
237         \par Address Type:
238             INet6SocketAddress
239
240         This addressing policy implements addressing using Internet V6
241         addresses.
242
243         The various members are directly imported from
244         BSDAddressingPolicyMixin which see for a detailed
245         documentation.
246      */
247     struct INet6AddressingPolicy
248         : public BSDAddressingPolicy,
249           private BSDAddressingPolicyMixin<INet6SocketAddress>
250     {
251         typedef INet6SocketAddress Address;
252
253         using BSDAddressingPolicyMixin<INet6SocketAddress>::peer;
254         using BSDAddressingPolicyMixin<INet6SocketAddress>::local;
255         using BSDAddressingPolicyMixin<INet6SocketAddress>::connect;
256         using BSDAddressingPolicyMixin<INet6SocketAddress>::bind;
257     };
258
259     //\}
260
261 }
262
263 //-/////////////////////////////////////////////////////////////////////////////////////////////////
264 #include "INetAddressing.cci"
265 //#include "INetAddressing.ct"
266 //#include "INetAddressing.cti"
267 //#include "INetAddressing.mpp"
268 #endif
269
270 \f
271 // Local Variables:
272 // mode: c++
273 // fill-column: 100
274 // c-file-style: "senf"
275 // indent-tabs-mode: nil
276 // ispell-local-dictionary: "american"
277 // compile-command: "scons -u test"
278 // comment-column: 40
279 // End: