A Discrete-Event Network Simulator
Home
Tutorials ▼
English
Portuguese
Docs ▼
Wiki
Manual
Models
Develop ▼
API
Bugs
API
src
network
utils
inet6-socket-address.cc
Go to the documentation of this file.
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
#include "
inet6-socket-address.h
"
23
#include "ns3/log.h"
24
25
namespace
ns3
26
{
27
28
NS_LOG_COMPONENT_DEFINE
(
"Inet6SocketAddress"
);
29
30
Inet6SocketAddress::Inet6SocketAddress
(
Ipv6Address
ipv6, uint16_t
port
)
31
: m_ipv6 (ipv6),
32
m_port (
port
)
33
{
34
NS_LOG_FUNCTION
(
this
<< ipv6 <<
port
);
35
}
36
37
Inet6SocketAddress::Inet6SocketAddress
(
Ipv6Address
ipv6)
38
: m_ipv6 (ipv6),
39
m_port (0)
40
{
41
NS_LOG_FUNCTION
(
this
<< ipv6);
42
}
43
44
Inet6SocketAddress::Inet6SocketAddress
(
const
char
* ipv6, uint16_t
port
)
45
: m_ipv6 (
Ipv6Address
(ipv6)),
46
m_port (
port
)
47
{
48
NS_LOG_FUNCTION
(
this
<< ipv6 <<
port
);
49
}
50
51
Inet6SocketAddress::Inet6SocketAddress
(
const
char
* ipv6)
52
: m_ipv6 (
Ipv6Address
(ipv6)),
53
m_port (0)
54
{
55
NS_LOG_FUNCTION
(
this
<< ipv6);
56
}
57
58
Inet6SocketAddress::Inet6SocketAddress
(uint16_t
port
)
59
: m_ipv6 (
Ipv6Address
::GetAny ()),
60
m_port (
port
)
61
{
62
NS_LOG_FUNCTION
(
this
<<
port
);
63
}
64
65
uint16_t
Inet6SocketAddress::GetPort
(
void
)
const
66
{
67
NS_LOG_FUNCTION
(
this
);
68
return
m_port
;
69
}
70
71
void
Inet6SocketAddress::SetPort
(uint16_t
port
)
72
{
73
NS_LOG_FUNCTION
(
this
<<
port
);
74
m_port
=
port
;
75
}
76
77
Ipv6Address
Inet6SocketAddress::GetIpv6
(
void
)
const
78
{
79
NS_LOG_FUNCTION
(
this
);
80
return
m_ipv6
;
81
}
82
83
void
Inet6SocketAddress::SetIpv6
(
Ipv6Address
ipv6)
84
{
85
NS_LOG_FUNCTION
(
this
<< ipv6);
86
m_ipv6
=ipv6;
87
}
88
89
bool
Inet6SocketAddress::IsMatchingType
(
const
Address
&addr)
90
{
91
NS_LOG_FUNCTION
(&addr);
92
return
addr.
CheckCompatible
(
GetType
(), 18);
/* 16 (address) + 2 (port) */
93
}
94
95
Inet6SocketAddress::operator
Address
(
void
)
const
96
{
97
return
ConvertTo ();
98
}
99
100
Address
Inet6SocketAddress::ConvertTo
(
void
)
const
101
{
102
NS_LOG_FUNCTION
(
this
);
103
uint8_t buf[18];
104
m_ipv6
.
Serialize
(buf);
105
buf[16]=
m_port
& 0xff;
106
buf[17]=(
m_port
>> 8) &0xff;
107
return
Address
(
GetType
(), buf, 18);
108
}
109
110
Inet6SocketAddress
Inet6SocketAddress::ConvertFrom
(
const
Address
&addr)
111
{
112
NS_LOG_FUNCTION
(&addr);
113
NS_ASSERT
(addr.
CheckCompatible
(
GetType
(), 18));
114
uint8_t buf[18];
115
addr.
CopyTo
(buf);
116
Ipv6Address
ipv6=
Ipv6Address::Deserialize
(buf);
117
uint16_t
port
= buf[16] | (buf[17] << 8);
118
return
Inet6SocketAddress
(ipv6,
port
);
119
}
120
121
uint8_t
Inet6SocketAddress::GetType
(
void
)
122
{
123
NS_LOG_FUNCTION_NOARGS
();
124
static
uint8_t type=
Address::Register
();
125
return
type;
126
}
127
128
}
/* namespace ns3 */
129
NS_LOG_FUNCTION
#define NS_LOG_FUNCTION(parameters)
If log level LOG_FUNCTION is enabled, this macro will output all input parameters separated by "...
Definition:
log-macros-enabled.h:213
ns3::Inet6SocketAddress::GetIpv6
Ipv6Address GetIpv6(void) const
Get the IPv6 address.
Definition:
inet6-socket-address.cc:77
ns3::Inet6SocketAddress::SetIpv6
void SetIpv6(Ipv6Address ipv6)
Set the IPv6 address.
Definition:
inet6-socket-address.cc:83
ns3::Ipv6Address::Deserialize
static Ipv6Address Deserialize(const uint8_t buf[16])
Deserialize this address.
Definition:
ipv6-address.cc:337
ns3::Address::CheckCompatible
bool CheckCompatible(uint8_t type, uint8_t len) const
Definition:
address.cc:122
NS_ASSERT
#define NS_ASSERT(condition)
At runtime, in debugging builds, if this condition is not true, the program prints the source file...
Definition:
assert.h:67
NS_LOG_COMPONENT_DEFINE
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition:
log.h:202
NS_LOG_FUNCTION_NOARGS
#define NS_LOG_FUNCTION_NOARGS()
Output the name of the function.
Definition:
log-macros-enabled.h:176
port
uint16_t port
Definition:
dsdv-manet.cc:45
ns3::Address
a polymophic address class
Definition:
address.h:90
ns3::Inet6SocketAddress::m_ipv6
Ipv6Address m_ipv6
The IPv6 address.
Definition:
inet6-socket-address.h:131
ns3::Inet6SocketAddress::Inet6SocketAddress
Inet6SocketAddress(Ipv6Address ipv6, uint16_t port)
Constructor.
Definition:
inet6-socket-address.cc:30
ns3::Inet6SocketAddress::m_port
uint16_t m_port
The port.
Definition:
inet6-socket-address.h:136
ns3::Inet6SocketAddress::GetType
static uint8_t GetType(void)
Get the type.
Definition:
inet6-socket-address.cc:121
ns3::Inet6SocketAddress
An Inet6 address class.
Definition:
inet6-socket-address.h:36
ns3
Every class exported by the ns3 library is enclosed in the ns3 namespace.
ns3::Ipv6Address
Describes an IPv6 address.
Definition:
ipv6-address.h:49
inet6-socket-address.h
ns3::Inet6SocketAddress::ConvertFrom
static Inet6SocketAddress ConvertFrom(const Address &addr)
Convert the address to a InetSocketAddress.
Definition:
inet6-socket-address.cc:110
ns3::Inet6SocketAddress::IsMatchingType
static bool IsMatchingType(const Address &addr)
If the address match.
Definition:
inet6-socket-address.cc:89
ns3::Inet6SocketAddress::SetPort
void SetPort(uint16_t port)
Set the port.
Definition:
inet6-socket-address.cc:71
ns3::Inet6SocketAddress::GetPort
uint16_t GetPort(void) const
Get the port.
Definition:
inet6-socket-address.cc:65
ns3::Inet6SocketAddress::ConvertTo
Address ConvertTo(void) const
Convert to Address.
Definition:
inet6-socket-address.cc:100
ns3::Address::Register
static uint8_t Register(void)
Allocate a new type id for a new type of address.
Definition:
address.cc:138
ns3::Ipv6Address::Serialize
void Serialize(uint8_t buf[16]) const
Serialize this address to a 16-byte buffer.
Definition:
ipv6-address.cc:331
ns3::Address::CopyTo
uint32_t CopyTo(uint8_t buffer[MAX_SIZE]) const
Copy the address bytes into a buffer.
Definition:
address.cc:82
Generated on Wed Nov 7 2018 10:02:07 for ns-3 by
1.8.14