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
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
15 \brief INet[46]Address and INet[46]AddressingPolicy inline non-template implementation
19 #include <arpa/inet.h>
21 #define prefix_ inline
22 //-/////////////////////////////////////////////////////////////////////////////////////////////////
24 //-/////////////////////////////////////////////////////////////////////////////////////////////////
27 prefix_ senf::INet4SocketAddress::INet4SocketAddress()
28 : BSDSocketAddress (sizeof(sockaddr_in), AF_INET)
31 prefix_ senf::INet4SocketAddress::INet4SocketAddress(const INet4SocketAddress& other)
32 : BSDSocketAddress(other)
35 prefix_ senf::INet4SocketAddress&
36 senf::INet4SocketAddress::operator=(const INet4SocketAddress& other)
38 BSDSocketAddress::operator=(other);
42 prefix_ senf::INet4Address senf::INet4SocketAddress::address()
45 return INet4Address::from_inaddr(addr_.sin_addr.s_addr);
48 prefix_ unsigned senf::INet4SocketAddress::port()
51 return ntohs(addr_.sin_port);
54 prefix_ void senf::INet4SocketAddress::address(INet4Address const & addr)
56 addr_.sin_addr.s_addr = addr.inaddr();
59 prefix_ void senf::INet4SocketAddress::port(unsigned p)
61 addr_.sin_port = htons(p);
64 //-/////////////////////////////////////////////////////////////////////////////////////////////////
65 // senf::INet6SocketAddress
67 prefix_ senf::INet6SocketAddress::INet6SocketAddress()
68 : BSDSocketAddress (sizeof(sockaddr_in6), AF_INET6)
71 prefix_ senf::INet6SocketAddress::INet6SocketAddress(INet6Address const & addr, unsigned port)
72 : BSDSocketAddress (sizeof(sockaddr_in6), AF_INET6)
74 std::copy(addr.begin(), addr.end(), &sockaddr_.sin6_addr.s6_addr[0]);
75 sockaddr_.sin6_port = htons(port);
78 prefix_ senf::INet6SocketAddress::INet6SocketAddress(INet6Address const & addr, unsigned port,
79 std::string const & iface)
80 : BSDSocketAddress (sizeof(sockaddr_in6), AF_INET6)
82 std::copy(addr.begin(), addr.end(), &sockaddr_.sin6_addr.s6_addr[0]);
83 sockaddr_.sin6_port = htons(port);
87 prefix_ senf::INet6SocketAddress::INet6SocketAddress(unsigned port)
88 : BSDSocketAddress (sizeof(sockaddr_in6), AF_INET6)
90 sockaddr_.sin6_port = htons(port);
93 prefix_ senf::INet6SocketAddress::INet6SocketAddress(const INet6SocketAddress& other)
94 : BSDSocketAddress (other)
97 prefix_ senf::INet6SocketAddress&
98 senf::INet6SocketAddress::operator=(const INet6SocketAddress& other)
100 BSDSocketAddress::operator=(other);
104 prefix_ senf::INet6Address senf::INet6SocketAddress::address()
107 return INet6Address::from_data(&sockaddr_.sin6_addr.s6_addr[0]);
110 prefix_ void senf::INet6SocketAddress::address(INet6Address const & addr)
112 std::copy(addr.begin(), addr.end(), &sockaddr_.sin6_addr.s6_addr[0]);
115 prefix_ unsigned senf::INet6SocketAddress::port()
118 return ntohs(sockaddr_.sin6_port);
121 prefix_ void senf::INet6SocketAddress::port(unsigned port)
123 sockaddr_.sin6_port = htons(port);
126 prefix_ void senf::INet6SocketAddress::iface(std::string const & iface)
131 //-/////////////////////////////////////////////////////////////////////////////////////////////////
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