A Discrete-Event Network Simulator
Home
Tutorials ▼
English
Documentation ▼
Installation
Manual
Models
Contributing
Wiki
Development ▼
API Docs
Issue Tracker
Merge Requests
API
Loading...
Searching...
No Matches
inet6-socket-address.cc
Go to the documentation of this file.
1
/*
2
* Copyright (c) 2007-2008 Louis Pasteur University
3
*
4
* SPDX-License-Identifier: GPL-2.0-only
5
*
6
* Author: Sebastien Vincent <vincent@clarinet.u-strasbg.fr>
7
*/
8
9
#include "
inet6-socket-address.h
"
10
11
#include "ns3/assert.h"
12
#include "ns3/log.h"
13
14
namespace
ns3
15
{
16
17
NS_LOG_COMPONENT_DEFINE
(
"Inet6SocketAddress"
);
18
19
Inet6SocketAddress::Inet6SocketAddress
(
Ipv6Address
ipv6, uint16_t
port
)
20
: m_ipv6(ipv6),
21
m_port(
port
)
22
{
23
NS_LOG_FUNCTION
(
this
<< ipv6 <<
port
);
24
}
25
26
Inet6SocketAddress::Inet6SocketAddress
(
Ipv6Address
ipv6)
27
: m_ipv6(ipv6),
28
m_port(0)
29
{
30
NS_LOG_FUNCTION
(
this
<< ipv6);
31
}
32
33
Inet6SocketAddress::Inet6SocketAddress
(
const
char
* ipv6, uint16_t
port
)
34
: m_ipv6(
Ipv6Address
(ipv6)),
35
m_port(
port
)
36
{
37
NS_LOG_FUNCTION
(
this
<< ipv6 <<
port
);
38
}
39
40
Inet6SocketAddress::Inet6SocketAddress
(
const
char
* ipv6)
41
: m_ipv6(
Ipv6Address
(ipv6)),
42
m_port(0)
43
{
44
NS_LOG_FUNCTION
(
this
<< ipv6);
45
}
46
47
Inet6SocketAddress::Inet6SocketAddress
(uint16_t
port
)
48
: m_ipv6(
Ipv6Address
::GetAny()),
49
m_port(
port
)
50
{
51
NS_LOG_FUNCTION
(
this
<<
port
);
52
}
53
54
uint16_t
55
Inet6SocketAddress::GetPort
()
const
56
{
57
NS_LOG_FUNCTION
(
this
);
58
return
m_port
;
59
}
60
61
void
62
Inet6SocketAddress::SetPort
(uint16_t
port
)
63
{
64
NS_LOG_FUNCTION
(
this
<<
port
);
65
m_port
=
port
;
66
}
67
68
Ipv6Address
69
Inet6SocketAddress::GetIpv6
()
const
70
{
71
NS_LOG_FUNCTION
(
this
);
72
return
m_ipv6
;
73
}
74
75
void
76
Inet6SocketAddress::SetIpv6
(
Ipv6Address
ipv6)
77
{
78
NS_LOG_FUNCTION
(
this
<< ipv6);
79
m_ipv6
= ipv6;
80
}
81
82
bool
83
Inet6SocketAddress::IsMatchingType
(
const
Address
& addr)
84
{
85
NS_LOG_FUNCTION
(&addr);
86
return
addr.
CheckCompatible
(
GetType
(), 18);
/* 16 (address) + 2 (port) */
87
}
88
89
Inet6SocketAddress::operator
Address
()
const
90
{
91
return
ConvertTo();
92
}
93
94
Address
95
Inet6SocketAddress::ConvertTo
()
const
96
{
97
NS_LOG_FUNCTION
(
this
);
98
uint8_t buf[18];
99
m_ipv6
.
Serialize
(buf);
100
buf[16] =
m_port
& 0xff;
101
buf[17] = (
m_port
>> 8) & 0xff;
102
return
Address
(
GetType
(), buf, 18);
103
}
104
105
Inet6SocketAddress
106
Inet6SocketAddress::ConvertFrom
(
const
Address
& addr)
107
{
108
NS_LOG_FUNCTION
(&addr);
109
NS_ASSERT
(addr.
CheckCompatible
(
GetType
(), 18));
110
uint8_t buf[18];
111
addr.
CopyTo
(buf);
112
Ipv6Address
ipv6 =
Ipv6Address::Deserialize
(buf);
113
uint16_t
port
= buf[16] | (buf[17] << 8);
114
return
Inet6SocketAddress
(ipv6,
port
);
115
}
116
117
uint8_t
118
Inet6SocketAddress::GetType
()
119
{
120
NS_LOG_FUNCTION_NOARGS
();
121
static
uint8_t type =
Address::Register
();
122
return
type;
123
}
124
125
}
/* namespace ns3 */
ns3::Address
a polymophic address class
Definition
address.h:90
ns3::Address::CheckCompatible
bool CheckCompatible(uint8_t type, uint8_t len) const
Definition
address.cc:118
ns3::Address::Register
static uint8_t Register()
Allocate a new type id for a new type of address.
Definition
address.cc:135
ns3::Address::CopyTo
uint32_t CopyTo(uint8_t buffer[MAX_SIZE]) const
Copy the address bytes into a buffer.
Definition
address.cc:75
ns3::Inet6SocketAddress
An Inet6 address class.
Definition
inet6-socket-address.h:27
ns3::Inet6SocketAddress::GetType
static uint8_t GetType()
Get the type.
Definition
inet6-socket-address.cc:118
ns3::Inet6SocketAddress::SetPort
void SetPort(uint16_t port)
Set the port.
Definition
inet6-socket-address.cc:62
ns3::Inet6SocketAddress::ConvertFrom
static Inet6SocketAddress ConvertFrom(const Address &addr)
Convert the address to a InetSocketAddress.
Definition
inet6-socket-address.cc:106
ns3::Inet6SocketAddress::GetPort
uint16_t GetPort() const
Get the port.
Definition
inet6-socket-address.cc:55
ns3::Inet6SocketAddress::Inet6SocketAddress
Inet6SocketAddress(Ipv6Address ipv6, uint16_t port)
Constructor.
Definition
inet6-socket-address.cc:19
ns3::Inet6SocketAddress::SetIpv6
void SetIpv6(Ipv6Address ipv6)
Set the IPv6 address.
Definition
inet6-socket-address.cc:76
ns3::Inet6SocketAddress::IsMatchingType
static bool IsMatchingType(const Address &addr)
If the address match.
Definition
inet6-socket-address.cc:83
ns3::Inet6SocketAddress::m_port
uint16_t m_port
The port.
Definition
inet6-socket-address.h:126
ns3::Inet6SocketAddress::GetIpv6
Ipv6Address GetIpv6() const
Get the IPv6 address.
Definition
inet6-socket-address.cc:69
ns3::Inet6SocketAddress::ConvertTo
Address ConvertTo() const
Convert to Address.
Definition
inet6-socket-address.cc:95
ns3::Inet6SocketAddress::m_ipv6
Ipv6Address m_ipv6
The IPv6 address.
Definition
inet6-socket-address.h:121
ns3::Ipv6Address
Describes an IPv6 address.
Definition
ipv6-address.h:38
ns3::Ipv6Address::Deserialize
static Ipv6Address Deserialize(const uint8_t buf[16])
Deserialize this address.
Definition
ipv6-address.cc:227
ns3::Ipv6Address::Serialize
void Serialize(uint8_t buf[16]) const
Serialize this address to a 16-byte buffer.
Definition
ipv6-address.cc:220
port
uint16_t port
Definition
dsdv-manet.cc:33
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:55
NS_LOG_COMPONENT_DEFINE
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition
log.h:191
NS_LOG_FUNCTION_NOARGS
#define NS_LOG_FUNCTION_NOARGS()
Output the name of the function.
Definition
log-macros-enabled.h:195
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:229
inet6-socket-address.h
ns3
Every class exported by the ns3 library is enclosed in the ns3 namespace.
src
network
utils
inet6-socket-address.cc
Generated on Tue Dec 10 2024 18:20:46 for ns-3 by
1.11.0