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
inet6-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) 2007-2008 Louis Pasteur University
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: Sebastien Vincent <vincent@clarinet.u-strasbg.fr>
19
*/
20
21
#include "ns3/assert.h"
22
23
#include "
inet6-socket-address.h
"
24
25
namespace
ns3
26
{
27
28
Inet6SocketAddress::Inet6SocketAddress
(
Ipv6Address
ipv6, uint16_t
port
)
29
: m_ipv6 (ipv6),
30
m_port (port)
31
{
32
}
33
34
Inet6SocketAddress::Inet6SocketAddress
(
Ipv6Address
ipv6)
35
: m_ipv6 (ipv6),
36
m_port (0)
37
{
38
}
39
40
Inet6SocketAddress::Inet6SocketAddress
(
const
char
* ipv6, uint16_t
port
)
41
: m_ipv6 (
Ipv6Address
(ipv6)),
42
m_port (port)
43
{
44
}
45
46
Inet6SocketAddress::Inet6SocketAddress
(
const
char
* ipv6)
47
: m_ipv6 (
Ipv6Address
(ipv6)),
48
m_port (0)
49
{
50
}
51
52
Inet6SocketAddress::Inet6SocketAddress
(uint16_t
port
)
53
: m_ipv6 (
Ipv6Address
::GetAny ()),
54
m_port (port)
55
{
56
}
57
58
uint16_t
Inet6SocketAddress::GetPort
(
void
)
const
59
{
60
return
m_port
;
61
}
62
63
void
Inet6SocketAddress::SetPort
(uint16_t
port
)
64
{
65
m_port
=
port
;
66
}
67
68
Ipv6Address
Inet6SocketAddress::GetIpv6
(
void
)
const
69
{
70
return
m_ipv6
;
71
}
72
73
void
Inet6SocketAddress::SetIpv6
(
Ipv6Address
ipv6)
74
{
75
m_ipv6
=ipv6;
76
}
77
78
bool
Inet6SocketAddress::IsMatchingType
(
const
Address
&addr)
79
{
80
return
addr.
CheckCompatible
(
GetType
(), 18);
/* 16 (address) + 2 (port) */
81
}
82
83
Inet6SocketAddress::operator
Address
(
void
)
const
84
{
85
return
ConvertTo ();
86
}
87
88
Address
Inet6SocketAddress::ConvertTo
(
void
)
const
89
{
90
uint8_t buf[18];
91
m_ipv6
.
Serialize
(buf);
92
buf[16]=
m_port
& 0xff;
93
buf[17]=(
m_port
>> 8) &0xff;
94
return
Address
(
GetType
(), buf, 18);
95
}
96
97
Inet6SocketAddress
Inet6SocketAddress::ConvertFrom
(
const
Address
&addr)
98
{
99
NS_ASSERT
(addr.
CheckCompatible
(
GetType
(), 18));
100
uint8_t buf[18];
101
addr.
CopyTo
(buf);
102
Ipv6Address
ipv6=
Ipv6Address::Deserialize
(buf);
103
uint16_t
port
= buf[16] | (buf[17] << 8);
104
return
Inet6SocketAddress
(ipv6, port);
105
}
106
107
uint8_t
Inet6SocketAddress::GetType
(
void
)
108
{
109
static
uint8_t type=
Address::Register
();
110
return
type;
111
}
112
113
}
/* namespace ns3 */
114
src
network
utils
inet6-socket-address.cc
Generated on Tue Oct 9 2012 16:45:44 for ns-3 by
1.8.1.2