A Discrete-Event Network Simulator
Home
Tutorials ▼
English
Portuguese
Docs ▼
Wiki
Manual
Models
Develop ▼
API
Bugs
API
Main Page
Related Pages
Modules
Namespaces
Classes
Files
File List
File Members
All
Classes
Namespaces
Files
Functions
Variables
Typedefs
Enumerations
Enumerator
Properties
Friends
Macros
Groups
Pages
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
NS_LOG_COMPONENT_DEFINE
(
"InetSocketAddress"
);
26
27
namespace
ns3 {
28
29
InetSocketAddress::InetSocketAddress
(
Ipv4Address
ipv4, uint16_t
port
)
30
: m_ipv4 (ipv4),
31
m_port (port)
32
{
33
NS_LOG_FUNCTION
(
this
<< ipv4 << port);
34
}
35
InetSocketAddress::InetSocketAddress
(
Ipv4Address
ipv4)
36
: m_ipv4 (ipv4),
37
m_port (0)
38
{
39
NS_LOG_FUNCTION
(
this
<< ipv4);
40
}
41
InetSocketAddress::InetSocketAddress
(
const
char
*ipv4, uint16_t
port
)
42
: m_ipv4 (
Ipv4Address
(ipv4)),
43
m_port (port)
44
{
45
NS_LOG_FUNCTION
(
this
<< ipv4 << port);
46
}
47
InetSocketAddress::InetSocketAddress
(
const
char
* ipv4)
48
: m_ipv4 (
Ipv4Address
(ipv4)),
49
m_port (0)
50
{
51
NS_LOG_FUNCTION
(
this
<< ipv4);
52
}
53
InetSocketAddress::InetSocketAddress
(uint16_t
port
)
54
: m_ipv4 (
Ipv4Address
::GetAny ()),
55
m_port (port)
56
{
57
NS_LOG_FUNCTION
(
this
<< port);
58
}
59
uint16_t
60
InetSocketAddress::GetPort
(
void
)
const
61
{
62
NS_LOG_FUNCTION
(
this
);
63
return
m_port
;
64
}
65
Ipv4Address
66
InetSocketAddress::GetIpv4
(
void
)
const
67
{
68
NS_LOG_FUNCTION
(
this
);
69
return
m_ipv4
;
70
}
71
72
void
73
InetSocketAddress::SetPort
(uint16_t
port
)
74
{
75
NS_LOG_FUNCTION
(
this
<< port);
76
m_port
=
port
;
77
}
78
void
79
InetSocketAddress::SetIpv4
(
Ipv4Address
address
)
80
{
81
NS_LOG_FUNCTION
(
this
<< address);
82
m_ipv4
=
address
;
83
}
84
85
bool
86
InetSocketAddress::IsMatchingType
(
const
Address
&
address
)
87
{
88
NS_LOG_FUNCTION
(&address);
89
return
address.
CheckCompatible
(
GetType
(), 6);
90
}
91
92
InetSocketAddress::operator
Address
()
const
93
{
94
return
ConvertTo ();
95
}
96
97
Address
98
InetSocketAddress::ConvertTo
(
void
)
const
99
{
100
NS_LOG_FUNCTION
(
this
);
101
uint8_t buf[6];
102
m_ipv4
.
Serialize
(buf);
103
buf[4] =
m_port
& 0xff;
104
buf[5] = (
m_port
>> 8) & 0xff;
105
return
Address
(
GetType
(), buf, 6);
106
}
107
InetSocketAddress
108
InetSocketAddress::ConvertFrom
(
const
Address
&
address
)
109
{
110
NS_LOG_FUNCTION
(&address);
111
NS_ASSERT
(address.
CheckCompatible
(
GetType
(), 6));
112
uint8_t buf[6];
113
address.
CopyTo
(buf);
114
Ipv4Address
ipv4 =
Ipv4Address::Deserialize
(buf);
115
uint16_t
port
= buf[4] | (buf[5] << 8);
116
return
InetSocketAddress
(ipv4, port);
117
}
118
uint8_t
119
InetSocketAddress::GetType
(
void
)
120
{
121
NS_LOG_FUNCTION_NOARGS
();
122
static
uint8_t type =
Address::Register
();
123
return
type;
124
}
125
126
}
// namespace ns3
ns3::Ipv4Address::Deserialize
static Ipv4Address Deserialize(const uint8_t buf[4])
Definition:
ipv4-address.cc:289
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
ns3::InetSocketAddress::GetIpv4
Ipv4Address GetIpv4(void) const
Definition:
inet-socket-address.cc:66
NS_LOG_FUNCTION
#define NS_LOG_FUNCTION(parameters)
Definition:
log.h:345
ns3::InetSocketAddress::m_port
uint16_t m_port
Definition:
inet-socket-address.h:113
NS_ASSERT
#define NS_ASSERT(condition)
Definition:
assert.h:64
NS_LOG_FUNCTION_NOARGS
#define NS_LOG_FUNCTION_NOARGS()
Output the name of the function.
Definition:
log.h:309
port
uint16_t port
Definition:
dsdv-manet.cc:44
ns3::Address
a polymophic address class
Definition:
address.h:86
ns3::Address::CheckCompatible
bool CheckCompatible(uint8_t type, uint8_t len) const
Definition:
address.cc:122
inet-socket-address.h
ns3::Ipv4Address::Serialize
void Serialize(uint8_t buf[4]) const
Serialize this address to a 4-byte buffer.
Definition:
ipv4-address.cc:280
ns3::InetSocketAddress::ConvertFrom
static InetSocketAddress ConvertFrom(const Address &address)
Definition:
inet-socket-address.cc:108
ns3::InetSocketAddress::SetPort
void SetPort(uint16_t port)
Definition:
inet-socket-address.cc:73
ns3::InetSocketAddress::SetIpv4
void SetIpv4(Ipv4Address address)
Definition:
inet-socket-address.cc:79
ns3::Ipv4Address
Ipv4 addresses are stored in host order in this class.
Definition:
ipv4-address.h:38
ns3::Address::CopyTo
uint32_t CopyTo(uint8_t buffer[MAX_SIZE]) const
Definition:
address.cc:82
ns3::InetSocketAddress::ConvertTo
Address ConvertTo(void) const
Definition:
inet-socket-address.cc:98
NS_LOG_COMPONENT_DEFINE
NS_LOG_COMPONENT_DEFINE("InetSocketAddress")
ns3::InetSocketAddress::GetPort
uint16_t GetPort(void) const
Definition:
inet-socket-address.cc:60
first.address
tuple address
Definition:
first.py:37
ns3::InetSocketAddress::m_ipv4
Ipv4Address m_ipv4
Definition:
inet-socket-address.h:112
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:86
ns3::InetSocketAddress::GetType
static uint8_t GetType(void)
Definition:
inet-socket-address.cc:119
src
network
utils
inet-socket-address.cc
Generated on Sat Apr 19 2014 14:07:06 for ns-3 by
1.8.6