author | Lalith Suresh <suresh.lalith@gmail.com> |
Sun, 18 Jul 2010 13:29:13 +0530 | |
changeset 6339 | 366418369bda |
parent 5217 | 8a9dbc333e76 |
permissions | -rw-r--r-- |
3852 | 1 |
/* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil; -*- */ |
2 |
/* |
|
3 |
* Copyright (c) 2007-2008 Louis Pasteur University |
|
4 |
* |
|
5 |
* This program is free software; you can redistribute it and/or modify |
|
6 |
* it under the terms of the GNU General Public License version 2 as |
|
7 |
* published by the Free Software Foundation; |
|
8 |
* |
|
9 |
* This program is distributed in the hope that it will be useful, |
|
10 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
11 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
12 |
* GNU General Public License for more details. |
|
13 |
* |
|
14 |
* You should have received a copy of the GNU General Public License |
|
15 |
* along with this program; if not, write to the Free Software |
|
16 |
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
|
17 |
* |
|
18 |
* Author: Sebastien Vincent <vincent@clarinet.u-strasbg.fr> |
|
19 |
*/ |
|
20 |
||
21 |
#include "ns3/assert.h" |
|
22 |
||
5217
8a9dbc333e76
Export more IPv6 includes.
Sebastien Vincent <vincent@clarinet.u-strasbg.fr>
parents:
4731
diff
changeset
|
23 |
#include "inet6-socket-address.h" |
8a9dbc333e76
Export more IPv6 includes.
Sebastien Vincent <vincent@clarinet.u-strasbg.fr>
parents:
4731
diff
changeset
|
24 |
|
8a9dbc333e76
Export more IPv6 includes.
Sebastien Vincent <vincent@clarinet.u-strasbg.fr>
parents:
4731
diff
changeset
|
25 |
namespace ns3 |
8a9dbc333e76
Export more IPv6 includes.
Sebastien Vincent <vincent@clarinet.u-strasbg.fr>
parents:
4731
diff
changeset
|
26 |
{ |
3852 | 27 |
|
28 |
Inet6SocketAddress::Inet6SocketAddress (Ipv6Address ipv6, uint16_t port) |
|
4731
510db8599bfb
second phase of IPv6 checkins from Univ. of Strasbourg team
Sebastien Vincent <vincent@clarinet.u-strasbg.fr>
parents:
3852
diff
changeset
|
29 |
: m_ipv6(ipv6), |
3852 | 30 |
m_port(port) |
31 |
{ |
|
32 |
} |
|
33 |
||
34 |
Inet6SocketAddress::Inet6SocketAddress (Ipv6Address ipv6) |
|
4731
510db8599bfb
second phase of IPv6 checkins from Univ. of Strasbourg team
Sebastien Vincent <vincent@clarinet.u-strasbg.fr>
parents:
3852
diff
changeset
|
35 |
: m_ipv6(ipv6), |
3852 | 36 |
m_port(0) |
37 |
{ |
|
38 |
} |
|
39 |
||
4731
510db8599bfb
second phase of IPv6 checkins from Univ. of Strasbourg team
Sebastien Vincent <vincent@clarinet.u-strasbg.fr>
parents:
3852
diff
changeset
|
40 |
Inet6SocketAddress::Inet6SocketAddress (const char* ipv6, uint16_t port) |
510db8599bfb
second phase of IPv6 checkins from Univ. of Strasbourg team
Sebastien Vincent <vincent@clarinet.u-strasbg.fr>
parents:
3852
diff
changeset
|
41 |
: m_ipv6(Ipv6Address(ipv6)), |
3852 | 42 |
m_port(port) |
43 |
{ |
|
44 |
} |
|
45 |
||
4731
510db8599bfb
second phase of IPv6 checkins from Univ. of Strasbourg team
Sebastien Vincent <vincent@clarinet.u-strasbg.fr>
parents:
3852
diff
changeset
|
46 |
Inet6SocketAddress::Inet6SocketAddress (const char* ipv6) |
510db8599bfb
second phase of IPv6 checkins from Univ. of Strasbourg team
Sebastien Vincent <vincent@clarinet.u-strasbg.fr>
parents:
3852
diff
changeset
|
47 |
: m_ipv6(Ipv6Address(ipv6)), |
3852 | 48 |
m_port(0) |
49 |
{ |
|
50 |
} |
|
51 |
||
4731
510db8599bfb
second phase of IPv6 checkins from Univ. of Strasbourg team
Sebastien Vincent <vincent@clarinet.u-strasbg.fr>
parents:
3852
diff
changeset
|
52 |
Inet6SocketAddress::Inet6SocketAddress (uint16_t port) |
510db8599bfb
second phase of IPv6 checkins from Univ. of Strasbourg team
Sebastien Vincent <vincent@clarinet.u-strasbg.fr>
parents:
3852
diff
changeset
|
53 |
: m_ipv6(Ipv6Address::GetAny()), |
3852 | 54 |
m_port(port) |
55 |
{ |
|
56 |
} |
|
57 |
||
58 |
uint16_t Inet6SocketAddress::GetPort (void) const |
|
59 |
{ |
|
60 |
return m_port; |
|
61 |
} |
|
62 |
||
63 |
void Inet6SocketAddress::SetPort (uint16_t port) |
|
64 |
{ |
|
65 |
m_port=port; |
|
66 |
} |
|
67 |
||
68 |
Ipv6Address Inet6SocketAddress::GetIpv6 (void) const |
|
69 |
{ |
|
70 |
return m_ipv6; |
|
71 |
} |
|
72 |
||
73 |
void Inet6SocketAddress::SetIpv6 (Ipv6Address ipv6) |
|
74 |
{ |
|
75 |
m_ipv6=ipv6; |
|
76 |
} |
|
77 |
||
78 |
bool Inet6SocketAddress::IsMatchingType (const Address &addr) |
|
79 |
{ |
|
80 |
return addr.CheckCompatible(GetType(), 18); /* 16 (address) + 2 (port) */ |
|
81 |
} |
|
82 |
||
83 |
Inet6SocketAddress::operator Address (void) const |
|
84 |
{ |
|
85 |
return ConvertTo(); |
|
86 |
} |
|
87 |
||
88 |
Address Inet6SocketAddress::ConvertTo (void) const |
|
89 |
{ |
|
90 |
uint8_t buf[18]; |
|
91 |
m_ipv6.Serialize(buf); |
|
92 |
buf[16]=m_port & 0xff; |
|
93 |
buf[17]=(m_port >> 8) &0xff; |
|
94 |
return Address(GetType(), buf, 18); |
|
95 |
} |
|
96 |
||
97 |
Inet6SocketAddress Inet6SocketAddress::ConvertFrom (const Address &addr) |
|
98 |
{ |
|
99 |
NS_ASSERT(addr.CheckCompatible(GetType(), 18)); |
|
100 |
uint8_t buf[18]; |
|
101 |
addr.CopyTo(buf); |
|
102 |
Ipv6Address ipv6=Ipv6Address::Deserialize(buf); |
|
103 |
uint16_t port= buf[16] | (buf[17] << 8); |
|
104 |
return Inet6SocketAddress(ipv6, port); |
|
105 |
} |
|
106 |
||
107 |
uint8_t Inet6SocketAddress::GetType (void) |
|
108 |
{ |
|
109 |
static uint8_t type=Address::Register(); |
|
110 |
return type; |
|
111 |
} |
|
112 |
||
113 |
} /* namespace ns3 */ |
|
114 |