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
24
namespace
ns3 {
25
26
InetSocketAddress::InetSocketAddress
(
Ipv4Address
ipv4, uint16_t
port
)
27
: m_ipv4 (ipv4),
28
m_port (port)
29
{
30
}
31
InetSocketAddress::InetSocketAddress
(
Ipv4Address
ipv4)
32
: m_ipv4 (ipv4),
33
m_port (0)
34
{
35
}
36
InetSocketAddress::InetSocketAddress
(
const
char
*ipv4, uint16_t
port
)
37
: m_ipv4 (
Ipv4Address
(ipv4)),
38
m_port (port)
39
{
40
}
41
InetSocketAddress::InetSocketAddress
(
const
char
* ipv4)
42
: m_ipv4 (
Ipv4Address
(ipv4)),
43
m_port (0)
44
{
45
}
46
InetSocketAddress::InetSocketAddress
(uint16_t
port
)
47
: m_ipv4 (
Ipv4Address
::GetAny ()),
48
m_port (port)
49
{
50
}
51
uint16_t
52
InetSocketAddress::GetPort
(
void
)
const
53
{
54
return
m_port
;
55
}
56
Ipv4Address
57
InetSocketAddress::GetIpv4
(
void
)
const
58
{
59
return
m_ipv4
;
60
}
61
62
void
63
InetSocketAddress::SetPort
(uint16_t
port
)
64
{
65
m_port
=
port
;
66
}
67
void
68
InetSocketAddress::SetIpv4
(
Ipv4Address
address)
69
{
70
m_ipv4
= address;
71
}
72
73
bool
74
InetSocketAddress::IsMatchingType
(
const
Address
&address)
75
{
76
return
address.
CheckCompatible
(
GetType
(), 6);
77
}
78
79
InetSocketAddress::operator
Address
()
const
80
{
81
return
ConvertTo ();
82
}
83
84
Address
85
InetSocketAddress::ConvertTo
(
void
)
const
86
{
87
uint8_t buf[6];
88
m_ipv4
.
Serialize
(buf);
89
buf[4] =
m_port
& 0xff;
90
buf[5] = (
m_port
>> 8) & 0xff;
91
return
Address
(
GetType
(), buf, 6);
92
}
93
InetSocketAddress
94
InetSocketAddress::ConvertFrom
(
const
Address
&address)
95
{
96
NS_ASSERT
(address.
CheckCompatible
(
GetType
(), 6));
97
uint8_t buf[6];
98
address.
CopyTo
(buf);
99
Ipv4Address
ipv4 =
Ipv4Address::Deserialize
(buf);
100
uint16_t
port
= buf[4] | (buf[5] << 8);
101
return
InetSocketAddress
(ipv4, port);
102
}
103
uint8_t
104
InetSocketAddress::GetType
(
void
)
105
{
106
static
uint8_t type =
Address::Register
();
107
return
type;
108
}
109
110
}
// namespace ns3
src
network
utils
inet-socket-address.cc
Generated on Tue Nov 13 2012 10:32:20 for ns-3 by
1.8.1.2