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
src
network
utils
inet-socket-address.cc
Generated on Fri Dec 21 2012 19:00:44 for ns-3 by
1.8.1.2