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
23
namespace
ns3 {
24
25
void
WriteTo
(
Buffer::Iterator
&i,
Ipv4Address
ad)
26
{
27
i.
WriteHtonU32
(ad.
Get
());
28
}
29
void
WriteTo
(
Buffer::Iterator
&i,
Ipv6Address
ad)
30
{
31
uint8_t buf[16];
32
ad.
GetBytes
(buf);
33
i.
Write
(buf, 16);
34
}
35
void
WriteTo
(
Buffer::Iterator
&i,
const
Address
&ad)
36
{
37
uint8_t mac[
Address::MAX_SIZE
];
38
ad.
CopyTo
(mac);
39
i.
Write
(mac, ad.
GetLength
());
40
}
41
void
WriteTo
(
Buffer::Iterator
&i,
Mac48Address
ad)
42
{
43
uint8_t mac[6];
44
ad.
CopyTo
(mac);
45
i.
Write
(mac, 6);
46
}
47
48
void
ReadFrom
(
Buffer::Iterator
&i,
Ipv4Address
&ad)
49
{
50
ad.
Set
(i.
ReadNtohU32
());
51
}
52
void
ReadFrom
(
Buffer::Iterator
&i,
Ipv6Address
&ad)
53
{
54
uint8_t ipv6[16];
55
i.
Read
(ipv6, 16);
56
ad.
Set
(ipv6);
57
}
58
void
ReadFrom
(
Buffer::Iterator
&i,
Address
&ad, uint32_t len)
59
{
60
uint8_t mac[
Address::MAX_SIZE
];
61
i.
Read
(mac, len);
62
ad.
CopyFrom
(mac, len);
63
}
64
void
ReadFrom
(
Buffer::Iterator
&i,
Mac48Address
&ad)
65
{
66
uint8_t mac[6];
67
i.
Read
(mac, 6);
68
ad.
CopyFrom
(mac);
69
}
70
71
namespace
addressUtils {
72
73
bool
IsMulticast
(
const
Address
&ad)
74
{
75
if
(
InetSocketAddress::IsMatchingType
(ad))
76
{
77
InetSocketAddress
inetAddr =
InetSocketAddress::ConvertFrom
(ad);
78
Ipv4Address
ipv4 = inetAddr.
GetIpv4
();
79
return
ipv4.
IsMulticast
();
80
}
81
// IPv6 case can go here, in future
82
return
false
;
83
}
84
85
}
// namespace addressUtils
86
87
}
// namespace ns3
src
network
utils
address-utils.cc
Generated on Tue Oct 9 2012 16:45:44 for ns-3 by
1.8.1.2