INetAddressing.hh
Go to the documentation of this file.
1 //
2 // Copyright (c) 2020 Fraunhofer Institute for Applied Information Technology (FIT)
3 // Network Research Group (NET)
4 // Schloss Birlinghoven, 53754 Sankt Augustin, GERMANY
5 // Contact: support@wiback.org
6 //
7 // This file is part of the SENF code tree.
8 // It is licensed under the 3-clause BSD License (aka New BSD License).
9 // See LICENSE.txt in the top level directory for details or visit
10 // https://opensource.org/licenses/BSD-3-Clause
11 //
12 
13 
18 #ifndef HH_SENF_Socket_Protocols_INet_INetAddressing_
19 #define HH_SENF_Socket_Protocols_INet_INetAddressing_ 1
20 
21 // Custom includes
22 #include <string>
23 #include <netinet/in.h>
26 #include "INet4Address.hh"
27 #include "INet6Address.hh"
28 
29 //#include "INetAddressing.mpp"
30 //-/////////////////////////////////////////////////////////////////////////////////////////////////
31 
32 namespace senf {
33 
45  : public BSDSocketAddress
46  {
47  public:
48  static short const addressFamily = AF_INET;
49 
50  //-////////////////////////////////////////////////////////////////////////
52  //\{
53 
55  explicit INet4SocketAddress(std::string const & addr);
56 
66  INet4SocketAddress(INet4Address const & addr, unsigned port);
68 
71  explicit INet4SocketAddress(unsigned port);
73 
77 
78  //\}
79  //-////////////////////////////////////////////////////////////////////////
80 
81  INet4Address address() const;
82  unsigned port() const;
83 
84  void address(INet4Address const & addr);
85  void port(unsigned p);
86 
89 
90  private:
91  struct ::sockaddr_in addr_;
92  };
93 
98  std::ostream & operator<<(std::ostream & os, INet4SocketAddress const & addr);
99  std::istream & operator>>(std::istream & is, INet4SocketAddress & addr);
100 
133  : public BSDSocketAddress
134  {
135  public:
136  static short const addressFamily = AF_INET6;
137 
138  //-////////////////////////////////////////////////////////////////////////
140  //\{
141 
143  explicit INet6SocketAddress(std::string const & addr,
146 
154  INet6SocketAddress(INet6Address const & addr, unsigned port);
156  INet6SocketAddress(INet6Address const & addr, unsigned port, std::string const & iface);
158 
160  explicit INet6SocketAddress(unsigned port);
162 
167 
168  //\}
169  //-////////////////////////////////////////////////////////////////////////
170 
171  INet6Address address() const;
172  void address(INet6Address const & addr);
173 
174  unsigned port() const;
175  void port(unsigned port);
176 
177  std::string iface() const;
178  void iface(std::string const & iface);
179 
184 
185  protected:
186 
187  private:
188  void assignIface(std::string const & iface);
189 
190  struct sockaddr_in6 sockaddr_;
191  };
192 
196  std::ostream & operator<<(std::ostream & os, INet6SocketAddress const & addr);
197  std::istream & operator>>(std::istream & is, INet6SocketAddress & addr);
198 
200  //\{
201 
215  : public BSDAddressingPolicy,
216  private BSDAddressingPolicyMixin<INet4SocketAddress>
217  {
219 
224  };
225 
239  : public BSDAddressingPolicy,
240  private BSDAddressingPolicyMixin<INet6SocketAddress>
241  {
243 
248  };
249 
250  //\}
251 
252 }
253 
254 //-/////////////////////////////////////////////////////////////////////////////////////////////////
255 #include "INetAddressing.cci"
256 //#include "INetAddressing.ct"
257 //#include "INetAddressing.cti"
258 //#include "INetAddressing.mpp"
259 #endif
260 
261 
262 // Local Variables:
263 // mode: c++
264 // fill-column: 100
265 // c-file-style: "senf"
266 // indent-tabs-mode: nil
267 // ispell-local-dictionary: "american"
268 // compile-command: "scons -u test"
269 // comment-column: 40
270 // End:
static short const addressFamily
Addressing policy supporting IPv6 addressing.
INet6SocketAddress Address
INet4SocketAddress & operator=(const INet4SocketAddress &other)
BSDSocketAddress public header.
IPv6 socket address.
Addressing policy supporting IPv4 addressing.
INet6Address public header.
IPv4 socket address.
std::istream & operator>>(std::istream &is, INet4SocketAddress &addr)
INet4Address public header.
std::ostream & operator<<(std::ostream &os, INet4SocketAddress const &addr)
Write address and port to os.
socklen_t const * socklen_p() const
INet6 network address.
Socket addressing, BSD style.
struct sockaddr const * sockaddr_p() const
IPv4 Internet address.
Definition: INet4Address.hh:78
BSDAddressingPolicyMixin public header.
INet4SocketAddress Address
unsigned port() const
Return port number.
Template for generic AddressingPolicy implementation based on the BSD socket API. ...
INet4Address address() const
Return address.