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
address-utils.cc
Go to the documentation of this file.
1
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2
/*
3
* Copyright (c) 2006 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
#include "
address-utils.h
"
21
#include "
inet-socket-address.h
"
22
#include "ns3/log.h"
23
24
NS_LOG_COMPONENT_DEFINE
(
"AddressUtils"
);
25
26
namespace
ns3 {
27
28
void
WriteTo
(
Buffer::Iterator
&i,
Ipv4Address
ad)
29
{
30
NS_LOG_FUNCTION
(&i << &ad);
31
i.
WriteHtonU32
(ad.
Get
());
32
}
33
void
WriteTo
(
Buffer::Iterator
&i,
Ipv6Address
ad)
34
{
35
NS_LOG_FUNCTION
(&i << &ad);
36
uint8_t buf[16];
37
ad.
GetBytes
(buf);
38
i.
Write
(buf, 16);
39
}
40
void
WriteTo
(
Buffer::Iterator
&i,
const
Address
&ad)
41
{
42
NS_LOG_FUNCTION
(&i << &ad);
43
uint8_t mac[
Address::MAX_SIZE
];
44
ad.
CopyTo
(mac);
45
i.
Write
(mac, ad.
GetLength
());
46
}
47
void
WriteTo
(
Buffer::Iterator
&i,
Mac64Address
ad)
48
{
49
NS_LOG_FUNCTION
(&i << &ad);
50
uint8_t mac[8];
51
ad.
CopyTo
(mac);
52
i.
Write
(mac, 8);
53
}
54
void
WriteTo
(
Buffer::Iterator
&i,
Mac48Address
ad)
55
{
56
NS_LOG_FUNCTION
(&i << &ad);
57
uint8_t mac[6];
58
ad.
CopyTo
(mac);
59
i.
Write
(mac, 6);
60
}
61
void
WriteTo
(
Buffer::Iterator
&i,
Mac16Address
ad)
62
{
63
NS_LOG_FUNCTION
(&i << &ad);
64
uint8_t mac[2];
65
ad.
CopyTo
(mac);
66
i.
Write
(mac+1, 1);
67
i.
Write
(mac, 1);
68
}
69
70
void
ReadFrom
(
Buffer::Iterator
&i,
Ipv4Address
&ad)
71
{
72
NS_LOG_FUNCTION
(&i << &ad);
73
ad.
Set
(i.
ReadNtohU32
());
74
}
75
void
ReadFrom
(
Buffer::Iterator
&i,
Ipv6Address
&ad)
76
{
77
NS_LOG_FUNCTION
(&i << &ad);
78
uint8_t ipv6[16];
79
i.
Read
(ipv6, 16);
80
ad.
Set
(ipv6);
81
}
82
void
ReadFrom
(
Buffer::Iterator
&i,
Address
&ad, uint32_t len)
83
{
84
NS_LOG_FUNCTION
(&i << &ad << len);
85
uint8_t mac[
Address::MAX_SIZE
];
86
i.
Read
(mac, len);
87
ad.
CopyFrom
(mac, len);
88
}
89
void
ReadFrom
(
Buffer::Iterator
&i,
Mac64Address
&ad)
90
{
91
NS_LOG_FUNCTION
(&i << &ad);
92
uint8_t mac[8];
93
i.
Read
(mac, 8);
94
ad.
CopyFrom
(mac);
95
}
96
void
ReadFrom
(
Buffer::Iterator
&i,
Mac48Address
&ad)
97
{
98
NS_LOG_FUNCTION
(&i << &ad);
99
uint8_t mac[6];
100
i.
Read
(mac, 6);
101
ad.
CopyFrom
(mac);
102
}
103
void
ReadFrom
(
Buffer::Iterator
&i,
Mac16Address
&ad)
104
{
105
NS_LOG_FUNCTION
(&i << &ad);
106
uint8_t mac[2];
107
i.
Read
(mac+1, 1);
108
i.
Read
(mac, 1);
109
ad.
CopyFrom
(mac);
110
}
111
112
namespace
addressUtils {
113
114
bool
IsMulticast
(
const
Address
&ad)
115
{
116
NS_LOG_FUNCTION
(&ad);
117
if
(
InetSocketAddress::IsMatchingType
(ad))
118
{
119
InetSocketAddress
inetAddr =
InetSocketAddress::ConvertFrom
(ad);
120
Ipv4Address
ipv4 = inetAddr.
GetIpv4
();
121
return
ipv4.
IsMulticast
();
122
}
123
// IPv6 case can go here, in future
124
return
false
;
125
}
126
127
}
// namespace addressUtils
128
129
}
// namespace ns3
src
network
utils
address-utils.cc
Generated on Fri Aug 30 2013 01:43:00 for ns-3 by
1.8.1.2