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