A Discrete-Event Network Simulator
Home
Tutorials ▼
English
Portuguese
Docs ▼
Wiki
Manual
Models
Develop ▼
API
Bugs
API
src
network
utils
inet-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) 2005 INRIA
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: Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
19
*/
20
21
#include "
inet-socket-address.h
"
22
#include "ns3/assert.h"
23
#include "ns3/log.h"
24
25
namespace
ns3
{
26
27
NS_LOG_COMPONENT_DEFINE
(
"InetSocketAddress"
);
28
29
InetSocketAddress::InetSocketAddress
(
Ipv4Address
ipv4, uint16_t
port
)
30
: m_ipv4 (ipv4),
31
m_port (
port
),
32
m_tos (0)
33
{
34
NS_LOG_FUNCTION
(
this
<< ipv4 <<
port
);
35
}
36
InetSocketAddress::InetSocketAddress
(
Ipv4Address
ipv4)
37
: m_ipv4 (ipv4),
38
m_port (0),
39
m_tos (0)
40
{
41
NS_LOG_FUNCTION
(
this
<< ipv4);
42
}
43
InetSocketAddress::InetSocketAddress
(
const
char
*ipv4, uint16_t
port
)
44
: m_ipv4 (
Ipv4Address
(ipv4)),
45
m_port (
port
),
46
m_tos (0)
47
{
48
NS_LOG_FUNCTION
(
this
<< ipv4 <<
port
);
49
}
50
InetSocketAddress::InetSocketAddress
(
const
char
* ipv4)
51
: m_ipv4 (
Ipv4Address
(ipv4)),
52
m_port (0),
53
m_tos (0)
54
{
55
NS_LOG_FUNCTION
(
this
<< ipv4);
56
}
57
InetSocketAddress::InetSocketAddress
(uint16_t
port
)
58
: m_ipv4 (
Ipv4Address
::GetAny ()),
59
m_port (
port
),
60
m_tos (0)
61
{
62
NS_LOG_FUNCTION
(
this
<<
port
);
63
}
64
uint16_t
65
InetSocketAddress::GetPort
(
void
)
const
66
{
67
NS_LOG_FUNCTION
(
this
);
68
return
m_port
;
69
}
70
Ipv4Address
71
InetSocketAddress::GetIpv4
(
void
)
const
72
{
73
NS_LOG_FUNCTION
(
this
);
74
return
m_ipv4
;
75
}
76
uint8_t
77
InetSocketAddress::GetTos
(
void
)
const
78
{
79
NS_LOG_FUNCTION
(
this
);
80
return
m_tos
;
81
}
82
83
void
84
InetSocketAddress::SetPort
(uint16_t
port
)
85
{
86
NS_LOG_FUNCTION
(
this
<<
port
);
87
m_port
=
port
;
88
}
89
void
90
InetSocketAddress::SetIpv4
(
Ipv4Address
address
)
91
{
92
NS_LOG_FUNCTION
(
this
<<
address
);
93
m_ipv4
=
address
;
94
}
95
void
96
InetSocketAddress::SetTos
(uint8_t tos)
97
{
98
NS_LOG_FUNCTION
(
this
<< tos);
99
m_tos
= tos;
100
}
101
102
bool
103
InetSocketAddress::IsMatchingType
(
const
Address
&
address
)
104
{
105
NS_LOG_FUNCTION
(&
address
);
106
return
address
.CheckCompatible (
GetType
(), 7);
107
}
108
109
InetSocketAddress::operator
Address
()
const
110
{
111
return
ConvertTo ();
112
}
113
114
Address
115
InetSocketAddress::ConvertTo
(
void
)
const
116
{
117
NS_LOG_FUNCTION
(
this
);
118
uint8_t buf[7];
119
m_ipv4
.
Serialize
(buf);
120
buf[4] =
m_port
& 0xff;
121
buf[5] = (
m_port
>> 8) & 0xff;
122
buf[6] =
m_tos
;
123
return
Address
(
GetType
(), buf, 7);
124
}
125
InetSocketAddress
126
InetSocketAddress::ConvertFrom
(
const
Address
&
address
)
127
{
128
NS_LOG_FUNCTION
(&
address
);
129
NS_ASSERT
(
address
.CheckCompatible (
GetType
(), 7));
130
uint8_t buf[7];
131
address
.CopyTo (buf);
132
Ipv4Address
ipv4 =
Ipv4Address::Deserialize
(buf);
133
uint16_t
port
= buf[4] | (buf[5] << 8);
134
uint8_t tos = buf[6];
135
InetSocketAddress
inet (ipv4,
port
);
136
inet.
SetTos
(tos);
137
return
inet;
138
}
139
uint8_t
140
InetSocketAddress::GetType
(
void
)
141
{
142
NS_LOG_FUNCTION_NOARGS
();
143
static
uint8_t type =
Address::Register
();
144
return
type;
145
}
146
147
}
// namespace ns3
ns3::Ipv4Address::Deserialize
static Ipv4Address Deserialize(const uint8_t buf[4])
Definition:
ipv4-address.cc:317
ns3::InetSocketAddress::InetSocketAddress
InetSocketAddress(Ipv4Address ipv4, uint16_t port)
Definition:
inet-socket-address.cc:29
ns3::InetSocketAddress
an Inet address class
Definition:
inet-socket-address.h:40
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::InetSocketAddress::m_port
uint16_t m_port
the port
Definition:
inet-socket-address.h:131
ns3::InetSocketAddress::GetTos
uint8_t GetTos(void) const
Definition:
inet-socket-address.cc:77
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
ns3::InetSocketAddress::ConvertTo
Address ConvertTo(void) const
Convert to an Address type.
Definition:
inet-socket-address.cc:115
ns3::InetSocketAddress::m_tos
uint8_t m_tos
the ToS
Definition:
inet-socket-address.h:132
port
uint16_t port
Definition:
dsdv-manet.cc:45
ns3::Address
a polymophic address class
Definition:
address.h:90
inet-socket-address.h
ns3
Every class exported by the ns3 library is enclosed in the ns3 namespace.
ns3::InetSocketAddress::ConvertFrom
static InetSocketAddress ConvertFrom(const Address &address)
Returns an InetSocketAddress which corresponds to the input Address.
Definition:
inet-socket-address.cc:126
first.address
address
Definition:
first.py:37
ns3::InetSocketAddress::SetTos
void SetTos(uint8_t tos)
Definition:
inet-socket-address.cc:96
ns3::InetSocketAddress::SetPort
void SetPort(uint16_t port)
Definition:
inet-socket-address.cc:84
ns3::InetSocketAddress::GetPort
uint16_t GetPort(void) const
Definition:
inet-socket-address.cc:65
ns3::InetSocketAddress::SetIpv4
void SetIpv4(Ipv4Address address)
Definition:
inet-socket-address.cc:90
ns3::Ipv4Address
Ipv4 addresses are stored in host order in this class.
Definition:
ipv4-address.h:40
ns3::InetSocketAddress::m_ipv4
Ipv4Address m_ipv4
the IPv4 address
Definition:
inet-socket-address.h:130
ns3::Address::Register
static uint8_t Register(void)
Allocate a new type id for a new type of address.
Definition:
address.cc:138
ns3::InetSocketAddress::IsMatchingType
static bool IsMatchingType(const Address &address)
Definition:
inet-socket-address.cc:103
ns3::Ipv4Address::Serialize
void Serialize(uint8_t buf[4]) const
Serialize this address to a 4-byte buffer.
Definition:
ipv4-address.cc:308
ns3::InetSocketAddress::GetType
static uint8_t GetType(void)
Get the underlying address type (automatically assigned).
Definition:
inet-socket-address.cc:140
ns3::InetSocketAddress::GetIpv4
Ipv4Address GetIpv4(void) const
Definition:
inet-socket-address.cc:71
Generated on Wed Nov 7 2018 10:02:07 for ns-3 by
1.8.14