INetAddressing.cci
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 
14 /** \file
15  \brief INet[46]Address and INet[46]AddressingPolicy inline non-template implementation
16  */
17 
18 // Custom includes
19 #include <arpa/inet.h>
20 
21 #define prefix_ inline
22 //-/////////////////////////////////////////////////////////////////////////////////////////////////
23 
24 //-/////////////////////////////////////////////////////////////////////////////////////////////////
25 // senf::INet4Address
26 
27 prefix_ senf::INet4SocketAddress::INet4SocketAddress()
28  : BSDSocketAddress (sizeof(sockaddr_in), AF_INET)
29 {}
30 
31 prefix_ senf::INet4SocketAddress::INet4SocketAddress(const INet4SocketAddress& other)
32  : BSDSocketAddress(other)
33 {}
34 
35 prefix_ senf::INet4SocketAddress&
36 senf::INet4SocketAddress::operator=(const INet4SocketAddress& other)
37 {
38  BSDSocketAddress::operator=(other);
39  return *this;
40 }
41 
42 prefix_ senf::INet4Address senf::INet4SocketAddress::address()
43  const
44 {
45  return INet4Address::from_inaddr(addr_.sin_addr.s_addr);
46 }
47 
48 prefix_ unsigned senf::INet4SocketAddress::port()
49  const
50 {
51  return ntohs(addr_.sin_port);
52 }
53 
54 prefix_ void senf::INet4SocketAddress::address(INet4Address const & addr)
55 {
56  addr_.sin_addr.s_addr = addr.inaddr();
57 }
58 
59 prefix_ void senf::INet4SocketAddress::port(unsigned p)
60 {
61  addr_.sin_port = htons(p);
62 }
63 
64 //-/////////////////////////////////////////////////////////////////////////////////////////////////
65 // senf::INet6SocketAddress
66 
67 prefix_ senf::INet6SocketAddress::INet6SocketAddress()
68  : BSDSocketAddress (sizeof(sockaddr_in6), AF_INET6)
69 {}
70 
71 prefix_ senf::INet6SocketAddress::INet6SocketAddress(INet6Address const & addr, unsigned port)
72  : BSDSocketAddress (sizeof(sockaddr_in6), AF_INET6)
73 {
74  std::copy(addr.begin(), addr.end(), &sockaddr_.sin6_addr.s6_addr[0]);
75  sockaddr_.sin6_port = htons(port);
76 }
77 
78 prefix_ senf::INet6SocketAddress::INet6SocketAddress(INet6Address const & addr, unsigned port,
79  std::string const & iface)
80  : BSDSocketAddress (sizeof(sockaddr_in6), AF_INET6)
81 {
82  std::copy(addr.begin(), addr.end(), &sockaddr_.sin6_addr.s6_addr[0]);
83  sockaddr_.sin6_port = htons(port);
84  assignIface(iface);
85 }
86 
87 prefix_ senf::INet6SocketAddress::INet6SocketAddress(unsigned port)
88  : BSDSocketAddress (sizeof(sockaddr_in6), AF_INET6)
89 {
90  sockaddr_.sin6_port = htons(port);
91 }
92 
93 prefix_ senf::INet6SocketAddress::INet6SocketAddress(const INet6SocketAddress& other)
94  : BSDSocketAddress (other)
95 {}
96 
97 prefix_ senf::INet6SocketAddress&
98 senf::INet6SocketAddress::operator=(const INet6SocketAddress& other)
99 {
100  BSDSocketAddress::operator=(other);
101  return *this;
102 }
103 
104 prefix_ senf::INet6Address senf::INet6SocketAddress::address()
105  const
106 {
107  return INet6Address::from_data(&sockaddr_.sin6_addr.s6_addr[0]);
108 }
109 
110 prefix_ void senf::INet6SocketAddress::address(INet6Address const & addr)
111 {
112  std::copy(addr.begin(), addr.end(), &sockaddr_.sin6_addr.s6_addr[0]);
113 }
114 
115 prefix_ unsigned senf::INet6SocketAddress::port()
116  const
117 {
118  return ntohs(sockaddr_.sin6_port);
119 }
120 
121 prefix_ void senf::INet6SocketAddress::port(unsigned port)
122 {
123  sockaddr_.sin6_port = htons(port);
124 }
125 
126 prefix_ void senf::INet6SocketAddress::iface(std::string const & iface)
127 {
128  assignIface(iface);
129 }
130 
131 //-/////////////////////////////////////////////////////////////////////////////////////////////////
132 #undef prefix_
133 
134 
135 // Local Variables:
136 // mode: c++
137 // fill-column: 100
138 // c-file-style: "senf"
139 // indent-tabs-mode: nil
140 // ispell-local-dictionary: "american"
141 // compile-command: "scons -u test"
142 // comment-column: 40
143 // End: