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
* 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
{
34
NS_LOG_FUNCTION
(
this
<< ipv4 <<
port
);
35
}
36
37
InetSocketAddress::InetSocketAddress
(
Ipv4Address
ipv4)
38
: m_ipv4(ipv4),
39
m_port(0)
40
{
41
NS_LOG_FUNCTION
(
this
<< ipv4);
42
}
43
44
InetSocketAddress::InetSocketAddress
(
const
char
* ipv4, uint16_t
port
)
45
: m_ipv4(
Ipv4Address
(ipv4)),
46
m_port(
port
)
47
{
48
NS_LOG_FUNCTION
(
this
<< ipv4 <<
port
);
49
}
50
51
InetSocketAddress::InetSocketAddress
(
const
char
* ipv4)
52
: m_ipv4(
Ipv4Address
(ipv4)),
53
m_port(0)
54
{
55
NS_LOG_FUNCTION
(
this
<< ipv4);
56
}
57
58
InetSocketAddress::InetSocketAddress
(uint16_t
port
)
59
: m_ipv4(
Ipv4Address
::GetAny()),
60
m_port(
port
)
61
{
62
NS_LOG_FUNCTION
(
this
<<
port
);
63
}
64
65
uint16_t
66
InetSocketAddress::GetPort
()
const
67
{
68
NS_LOG_FUNCTION
(
this
);
69
return
m_port
;
70
}
71
72
Ipv4Address
73
InetSocketAddress::GetIpv4
()
const
74
{
75
NS_LOG_FUNCTION
(
this
);
76
return
m_ipv4
;
77
}
78
79
void
80
InetSocketAddress::SetPort
(uint16_t
port
)
81
{
82
NS_LOG_FUNCTION
(
this
<<
port
);
83
m_port
=
port
;
84
}
85
86
void
87
InetSocketAddress::SetIpv4
(
Ipv4Address
address)
88
{
89
NS_LOG_FUNCTION
(
this
<< address);
90
m_ipv4
= address;
91
}
92
93
bool
94
InetSocketAddress::IsMatchingType
(
const
Address
& address)
95
{
96
NS_LOG_FUNCTION
(&address);
97
return
address.CheckCompatible(
GetType
(), 6);
98
}
99
100
InetSocketAddress::operator
Address
()
const
101
{
102
return
ConvertTo();
103
}
104
105
Address
106
InetSocketAddress::ConvertTo
()
const
107
{
108
NS_LOG_FUNCTION
(
this
);
109
uint8_t buf[6];
110
m_ipv4
.
Serialize
(buf);
111
buf[4] =
m_port
& 0xff;
112
buf[5] = (
m_port
>> 8) & 0xff;
113
return
Address
(
GetType
(), buf, 6);
114
}
115
116
InetSocketAddress
117
InetSocketAddress::ConvertFrom
(
const
Address
& address)
118
{
119
NS_LOG_FUNCTION
(&address);
120
NS_ASSERT
(address.CheckCompatible(
GetType
(), 6));
/* 4 (address) + 2 (port) */
121
uint8_t buf[6];
122
address.CopyTo(buf);
123
Ipv4Address
ipv4 =
Ipv4Address::Deserialize
(buf);
124
uint16_t
port
= buf[4] | (buf[5] << 8);
125
InetSocketAddress
inet(ipv4,
port
);
126
return
inet;
127
}
128
129
uint8_t
130
InetSocketAddress::GetType
()
131
{
132
NS_LOG_FUNCTION_NOARGS
();
133
static
uint8_t type =
Address::Register
();
134
return
type;
135
}
136
137
}
// 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:80
ns3::InetSocketAddress::GetType
static uint8_t GetType()
Get the underlying address type (automatically assigned).
Definition:
inet-socket-address.cc:130
ns3::InetSocketAddress::ConvertTo
Address ConvertTo() const
Convert to an Address type.
Definition:
inet-socket-address.cc:106
ns3::InetSocketAddress::GetPort
uint16_t GetPort() const
Definition:
inet-socket-address.cc:66
ns3::InetSocketAddress::m_port
uint16_t m_port
the port
Definition:
inet-socket-address.h:125
ns3::InetSocketAddress::SetIpv4
void SetIpv4(Ipv4Address address)
Definition:
inet-socket-address.cc:87
ns3::InetSocketAddress::IsMatchingType
static bool IsMatchingType(const Address &address)
Definition:
inet-socket-address.cc:94
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:124
ns3::InetSocketAddress::GetIpv4
Ipv4Address GetIpv4() const
Definition:
inet-socket-address.cc:73
ns3::InetSocketAddress::ConvertFrom
static InetSocketAddress ConvertFrom(const Address &address)
Returns an InetSocketAddress which corresponds to the input Address.
Definition:
inet-socket-address.cc:117
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
ns3
Every class exported by the ns3 library is enclosed in the ns3 namespace.
src
network
utils
inet-socket-address.cc
Generated on Tue May 28 2024 23:38:43 for ns-3 by
1.9.6