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
inet-socket-address.cc
Go to the documentation of this file.
1
/*
2
* Copyright (c) 2005 INRIA
3
*
4
* SPDX-License-Identifier: GPL-2.0-only
5
*
6
* Author: Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
7
*/
8
9
#include "
inet-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
(
"InetSocketAddress"
);
18
19
InetSocketAddress::InetSocketAddress
(
Ipv4Address
ipv4, uint16_t
port
)
20
: m_ipv4(ipv4),
21
m_port(
port
)
22
{
23
NS_LOG_FUNCTION
(
this
<< ipv4 <<
port
);
24
}
25
26
InetSocketAddress::InetSocketAddress
(
Ipv4Address
ipv4)
27
: m_ipv4(ipv4),
28
m_port(0)
29
{
30
NS_LOG_FUNCTION
(
this
<< ipv4);
31
}
32
33
InetSocketAddress::InetSocketAddress
(
const
char
* ipv4, uint16_t
port
)
34
: m_ipv4(
Ipv4Address
(ipv4)),
35
m_port(
port
)
36
{
37
NS_LOG_FUNCTION
(
this
<< ipv4 <<
port
);
38
}
39
40
InetSocketAddress::InetSocketAddress
(
const
char
* ipv4)
41
: m_ipv4(
Ipv4Address
(ipv4)),
42
m_port(0)
43
{
44
NS_LOG_FUNCTION
(
this
<< ipv4);
45
}
46
47
InetSocketAddress::InetSocketAddress
(uint16_t
port
)
48
: m_ipv4(
Ipv4Address
::GetAny()),
49
m_port(
port
)
50
{
51
NS_LOG_FUNCTION
(
this
<<
port
);
52
}
53
54
uint16_t
55
InetSocketAddress::GetPort
()
const
56
{
57
NS_LOG_FUNCTION
(
this
);
58
return
m_port
;
59
}
60
61
Ipv4Address
62
InetSocketAddress::GetIpv4
()
const
63
{
64
NS_LOG_FUNCTION
(
this
);
65
return
m_ipv4
;
66
}
67
68
void
69
InetSocketAddress::SetPort
(uint16_t
port
)
70
{
71
NS_LOG_FUNCTION
(
this
<<
port
);
72
m_port
=
port
;
73
}
74
75
void
76
InetSocketAddress::SetIpv4
(
Ipv4Address
address)
77
{
78
NS_LOG_FUNCTION
(
this
<< address);
79
m_ipv4
= address;
80
}
81
82
bool
83
InetSocketAddress::IsMatchingType
(
const
Address
& address)
84
{
85
NS_LOG_FUNCTION
(&address);
86
return
address.CheckCompatible(
GetType
(), 6);
87
}
88
89
InetSocketAddress::operator
Address
()
const
90
{
91
return
ConvertTo();
92
}
93
94
Address
95
InetSocketAddress::ConvertTo
()
const
96
{
97
NS_LOG_FUNCTION
(
this
);
98
uint8_t buf[6];
99
m_ipv4
.
Serialize
(buf);
100
buf[4] =
m_port
& 0xff;
101
buf[5] = (
m_port
>> 8) & 0xff;
102
return
Address
(
GetType
(), buf, 6);
103
}
104
105
InetSocketAddress
106
InetSocketAddress::ConvertFrom
(
const
Address
& address)
107
{
108
NS_LOG_FUNCTION
(&address);
109
NS_ASSERT
(address.CheckCompatible(
GetType
(), 6));
/* 4 (address) + 2 (port) */
110
uint8_t buf[6];
111
address.CopyTo(buf);
112
Ipv4Address
ipv4 =
Ipv4Address::Deserialize
(buf);
113
uint16_t
port
= buf[4] | (buf[5] << 8);
114
InetSocketAddress
inet(ipv4,
port
);
115
return
inet;
116
}
117
118
uint8_t
119
InetSocketAddress::GetType
()
120
{
121
NS_LOG_FUNCTION_NOARGS
();
122
static
uint8_t type =
Address::Register
();
123
return
type;
124
}
125
126
}
// namespace ns3
ns3::Address
a polymophic address class
Definition
address.h:90
ns3::Address::Register
static uint8_t Register()
Allocate a new type id for a new type of address.
Definition
address.cc:135
ns3::InetSocketAddress
an Inet address class
Definition
inet-socket-address.h:31
ns3::InetSocketAddress::SetPort
void SetPort(uint16_t port)
Definition
inet-socket-address.cc:69
ns3::InetSocketAddress::GetType
static uint8_t GetType()
Get the underlying address type (automatically assigned).
Definition
inet-socket-address.cc:119
ns3::InetSocketAddress::ConvertTo
Address ConvertTo() const
Convert to an Address type.
Definition
inet-socket-address.cc:95
ns3::InetSocketAddress::GetPort
uint16_t GetPort() const
Definition
inet-socket-address.cc:55
ns3::InetSocketAddress::m_port
uint16_t m_port
the port
Definition
inet-socket-address.h:114
ns3::InetSocketAddress::SetIpv4
void SetIpv4(Ipv4Address address)
Definition
inet-socket-address.cc:76
ns3::InetSocketAddress::IsMatchingType
static bool IsMatchingType(const Address &address)
Definition
inet-socket-address.cc:83
ns3::InetSocketAddress::InetSocketAddress
InetSocketAddress(Ipv4Address ipv4, uint16_t port)
Definition
inet-socket-address.cc:19
ns3::InetSocketAddress::m_ipv4
Ipv4Address m_ipv4
the IPv4 address
Definition
inet-socket-address.h:113
ns3::InetSocketAddress::GetIpv4
Ipv4Address GetIpv4() const
Definition
inet-socket-address.cc:62
ns3::InetSocketAddress::ConvertFrom
static InetSocketAddress ConvertFrom(const Address &address)
Returns an InetSocketAddress which corresponds to the input Address.
Definition
inet-socket-address.cc:106
ns3::Ipv4Address
Ipv4 addresses are stored in host order in this class.
Definition
ipv4-address.h:31
ns3::Ipv4Address::Serialize
void Serialize(uint8_t buf[4]) const
Serialize this address to a 4-byte buffer.
Definition
ipv4-address.cc:285
ns3::Ipv4Address::Deserialize
static Ipv4Address Deserialize(const uint8_t buf[4])
Definition
ipv4-address.cc:295
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
inet-socket-address.h
ns3
Every class exported by the ns3 library is enclosed in the ns3 namespace.
src
network
utils
inet-socket-address.cc
Generated on Sat Nov 9 2024 09:20:45 for ns-3 by
1.11.0