A Discrete-Event Network Simulator
Home
Tutorials ▼
English
Documentation ▼
Installation
Manual
Models
Contributing
Wiki
Development ▼
API Docs
Issue Tracker
Merge Requests
API
inet-socket-address.cc
Go to the documentation of this file.
1
/*
2
* Copyright (c) 2005 INRIA
3
*
4
* This program is free software; you can redistribute it and/or modify
5
* it under the terms of the GNU General Public License version 2 as
6
* published by the Free Software Foundation;
7
*
8
* This program is distributed in the hope that it will be useful,
9
* but WITHOUT ANY WARRANTY; without even the implied warranty of
10
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11
* GNU General Public License for more details.
12
*
13
* You should have received a copy of the GNU General Public License
14
* along with this program; if not, write to the Free Software
15
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
16
*
17
* Author: Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
18
*/
19
20
#include "
inet-socket-address.h
"
21
22
#include "ns3/assert.h"
23
#include "ns3/log.h"
24
25
namespace
ns3
26
{
27
28
NS_LOG_COMPONENT_DEFINE
(
"InetSocketAddress"
);
29
30
InetSocketAddress::InetSocketAddress
(
Ipv4Address
ipv4
, uint16_t
port
)
31
: m_ipv4(
ipv4
),
32
m_port(
port
),
33
m_tos(0)
34
{
35
NS_LOG_FUNCTION
(
this
<<
ipv4
<<
port
);
36
}
37
38
InetSocketAddress::InetSocketAddress
(
Ipv4Address
ipv4
)
39
: m_ipv4(
ipv4
),
40
m_port(0),
41
m_tos(0)
42
{
43
NS_LOG_FUNCTION
(
this
<<
ipv4
);
44
}
45
46
InetSocketAddress::InetSocketAddress
(
const
char
*
ipv4
, uint16_t
port
)
47
: m_ipv4(
Ipv4Address
(
ipv4
)),
48
m_port(
port
),
49
m_tos(0)
50
{
51
NS_LOG_FUNCTION
(
this
<<
ipv4
<<
port
);
52
}
53
54
InetSocketAddress::InetSocketAddress
(
const
char
*
ipv4
)
55
: m_ipv4(
Ipv4Address
(
ipv4
)),
56
m_port(0),
57
m_tos(0)
58
{
59
NS_LOG_FUNCTION
(
this
<<
ipv4
);
60
}
61
62
InetSocketAddress::InetSocketAddress
(uint16_t
port
)
63
: m_ipv4(
Ipv4Address
::GetAny()),
64
m_port(
port
),
65
m_tos(0)
66
{
67
NS_LOG_FUNCTION
(
this
<<
port
);
68
}
69
70
uint16_t
71
InetSocketAddress::GetPort
()
const
72
{
73
NS_LOG_FUNCTION
(
this
);
74
return
m_port
;
75
}
76
77
Ipv4Address
78
InetSocketAddress::GetIpv4
()
const
79
{
80
NS_LOG_FUNCTION
(
this
);
81
return
m_ipv4
;
82
}
83
84
uint8_t
85
InetSocketAddress::GetTos
()
const
86
{
87
NS_LOG_FUNCTION
(
this
);
88
return
m_tos
;
89
}
90
91
void
92
InetSocketAddress::SetPort
(uint16_t
port
)
93
{
94
NS_LOG_FUNCTION
(
this
<<
port
);
95
m_port
=
port
;
96
}
97
98
void
99
InetSocketAddress::SetIpv4
(
Ipv4Address
address
)
100
{
101
NS_LOG_FUNCTION
(
this
<<
address
);
102
m_ipv4
=
address
;
103
}
104
105
void
106
InetSocketAddress::SetTos
(uint8_t tos)
107
{
108
NS_LOG_FUNCTION
(
this
<< tos);
109
m_tos
= tos;
110
}
111
112
bool
113
InetSocketAddress::IsMatchingType
(
const
Address
&
address
)
114
{
115
NS_LOG_FUNCTION
(&
address
);
116
return
address
.CheckCompatible(
GetType
(), 7);
117
}
118
119
InetSocketAddress::operator
Address
()
const
120
{
121
return
ConvertTo();
122
}
123
124
Address
125
InetSocketAddress::ConvertTo
()
const
126
{
127
NS_LOG_FUNCTION
(
this
);
128
uint8_t buf[7];
129
m_ipv4
.
Serialize
(buf);
130
buf[4] =
m_port
& 0xff;
131
buf[5] = (
m_port
>> 8) & 0xff;
132
buf[6] =
m_tos
;
133
return
Address
(
GetType
(), buf, 7);
134
}
135
136
InetSocketAddress
137
InetSocketAddress::ConvertFrom
(
const
Address
&
address
)
138
{
139
NS_LOG_FUNCTION
(&
address
);
140
NS_ASSERT
(
address
.CheckCompatible(
GetType
(), 7));
141
uint8_t buf[7];
142
address
.CopyTo(buf);
143
Ipv4Address
ipv4
=
Ipv4Address::Deserialize
(buf);
144
uint16_t
port
= buf[4] | (buf[5] << 8);
145
uint8_t tos = buf[6];
146
InetSocketAddress
inet(
ipv4
,
port
);
147
inet.
SetTos
(tos);
148
return
inet;
149
}
150
151
uint8_t
152
InetSocketAddress::GetType
()
153
{
154
NS_LOG_FUNCTION_NOARGS
();
155
static
uint8_t
type
=
Address::Register
();
156
return
type
;
157
}
158
159
}
// namespace ns3
ns3::Address
a polymophic address class
Definition:
address.h:101
ns3::Address::Register
static uint8_t Register()
Allocate a new type id for a new type of address.
Definition:
address.cc:146
ns3::InetSocketAddress
an Inet address class
Definition:
inet-socket-address.h:42
ns3::InetSocketAddress::SetPort
void SetPort(uint16_t port)
Definition:
inet-socket-address.cc:92
ns3::InetSocketAddress::GetType
static uint8_t GetType()
Get the underlying address type (automatically assigned).
Definition:
inet-socket-address.cc:152
ns3::InetSocketAddress::ConvertTo
Address ConvertTo() const
Convert to an Address type.
Definition:
inet-socket-address.cc:125
ns3::InetSocketAddress::GetPort
uint16_t GetPort() const
Definition:
inet-socket-address.cc:71
ns3::InetSocketAddress::SetTos
void SetTos(uint8_t tos)
Definition:
inet-socket-address.cc:106
ns3::InetSocketAddress::m_port
uint16_t m_port
the port
Definition:
inet-socket-address.h:133
ns3::InetSocketAddress::SetIpv4
void SetIpv4(Ipv4Address address)
Definition:
inet-socket-address.cc:99
ns3::InetSocketAddress::IsMatchingType
static bool IsMatchingType(const Address &address)
Definition:
inet-socket-address.cc:113
ns3::InetSocketAddress::InetSocketAddress
InetSocketAddress(Ipv4Address ipv4, uint16_t port)
Definition:
inet-socket-address.cc:30
ns3::InetSocketAddress::m_ipv4
Ipv4Address m_ipv4
the IPv4 address
Definition:
inet-socket-address.h:132
ns3::InetSocketAddress::GetIpv4
Ipv4Address GetIpv4() const
Definition:
inet-socket-address.cc:78
ns3::InetSocketAddress::m_tos
uint8_t m_tos
the ToS
Definition:
inet-socket-address.h:134
ns3::InetSocketAddress::ConvertFrom
static InetSocketAddress ConvertFrom(const Address &address)
Returns an InetSocketAddress which corresponds to the input Address.
Definition:
inet-socket-address.cc:137
ns3::InetSocketAddress::GetTos
uint8_t GetTos() const
Definition:
inet-socket-address.cc:85
ns3::Ipv4Address
Ipv4 addresses are stored in host order in this class.
Definition:
ipv4-address.h:42
ns3::Ipv4Address::Serialize
void Serialize(uint8_t buf[4]) const
Serialize this address to a 4-byte buffer.
Definition:
ipv4-address.cc:295
ns3::Ipv4Address::Deserialize
static Ipv4Address Deserialize(const uint8_t buf[4])
Definition:
ipv4-address.cc:305
port
uint16_t port
Definition:
dsdv-manet.cc:44
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:66
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:206
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:240
inet-socket-address.h
check-style-clang-format.type
type
Definition:
check-style-clang-format.py:704
first.address
address
Definition:
first.py:47
ns3
Every class exported by the ns3 library is enclosed in the ns3 namespace.
nsclick-simple-lan.ipv4
ipv4
Definition:
nsclick-simple-lan.py:57
src
network
utils
inet-socket-address.cc
Generated on Sun Mar 3 2024 17:11:06 for ns-3 by
1.9.1