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
ns3::InetSocketAddress
an Inet address class
Definition:
inet-socket-address.h:40
ns3::InetSocketAddress::GetIpv4
Ipv4Address GetIpv4(void) const
Definition:
inet-socket-address.cc:66
NS_LOG_FUNCTION
#define NS_LOG_FUNCTION(parameters)
Definition:
log.h:345
NS_LOG_COMPONENT_DEFINE
NS_LOG_COMPONENT_DEFINE("AddressUtils")
ns3::Address::MAX_SIZE
Definition:
address.h:94
ns3::addressUtils::IsMulticast
bool IsMulticast(const Address &ad)
Address family-independent test for a multicast address.
Definition:
address-utils.cc:114
ns3::ReadFrom
void ReadFrom(Buffer::Iterator &i, Ipv4Address &ad)
Read an Ipv4Address from a Buffer.
Definition:
address-utils.cc:70
ns3::Mac16Address::CopyFrom
void CopyFrom(const uint8_t buffer[2])
Definition:
mac16-address.cc:94
ns3::WriteTo
void WriteTo(Buffer::Iterator &i, Ipv4Address ad)
Write an Ipv4Address to a Buffer.
Definition:
address-utils.cc:28
ns3::Ipv4Address::IsMulticast
bool IsMulticast(void) const
Definition:
ipv4-address.cc:261
address-utils.h
ns3::Buffer::Iterator::ReadNtohU32
uint32_t ReadNtohU32(void)
Definition:
buffer.h:791
ns3::Buffer::Iterator
iterator in a Buffer instance
Definition:
buffer.h:98
ns3::Address
a polymophic address class
Definition:
address.h:86
ns3::Mac64Address
an EUI-64 address
Definition:
mac64-address.h:41
ns3::Mac64Address::CopyTo
void CopyTo(uint8_t buffer[8]) const
Definition:
mac64-address.cc:98
ns3::Mac48Address::CopyTo
void CopyTo(uint8_t buffer[6]) const
Definition:
mac48-address.cc:98
inet-socket-address.h
ns3::Ipv4Address::Get
uint32_t Get(void) const
Get the host-order 32-bit IP address.
Definition:
ipv4-address.cc:204
ns3::Address::GetLength
uint8_t GetLength(void) const
Definition:
address.cc:75
ns3::Mac16Address::CopyTo
void CopyTo(uint8_t buffer[2]) const
Definition:
mac16-address.cc:100
ns3::Ipv6Address::GetBytes
void GetBytes(uint8_t buf[16]) const
Get the bytes corresponding to the address.
Definition:
ipv6-address.cc:797
ns3::Mac64Address::CopyFrom
void CopyFrom(const uint8_t buffer[8])
Definition:
mac64-address.cc:92
ns3::Ipv6Address::Set
void Set(char const *address)
Sets an Ipv6Address by parsing the input C-string.
Definition:
ipv6-address.cc:319
ns3::InetSocketAddress::ConvertFrom
static InetSocketAddress ConvertFrom(const Address &address)
Definition:
inet-socket-address.cc:108
ns3::Address::CopyFrom
uint32_t CopyFrom(const uint8_t *buffer, uint8_t len)
Definition:
address.cc:101
ns3::Mac48Address
an EUI-48 address
Definition:
mac48-address.h:41
ns3::Buffer::Iterator::Read
void Read(uint8_t *buffer, uint32_t size)
Definition:
buffer.cc:1148
ns3::Mac16Address
This class can contain 16 bit addresses.
Definition:
mac16-address.h:39
ns3::Mac48Address::CopyFrom
void CopyFrom(const uint8_t buffer[6])
Definition:
mac48-address.cc:92
ns3::Buffer::Iterator::WriteHtonU32
void WriteHtonU32(uint32_t data)
Definition:
buffer.h:745
ns3::Ipv4Address::Set
void Set(uint32_t address)
input address is in host order.
Definition:
ipv4-address.cc:210
ns3::Ipv6Address
Describes an IPv6 address.
Definition:
ipv6-address.h:46
ns3::Ipv4Address
Ipv4 addresses are stored in host order in this class.
Definition:
ipv4-address.h:38
ns3::Address::CopyTo
uint32_t CopyTo(uint8_t buffer[MAX_SIZE]) const
Definition:
address.cc:82
ns3::Buffer::Iterator::Write
void Write(uint8_t const *buffer, uint32_t size)
Definition:
buffer.cc:978
ns3::InetSocketAddress::IsMatchingType
static bool IsMatchingType(const Address &address)
Definition:
inet-socket-address.cc:86
src
network
utils
address-utils.cc
Generated on Sat Apr 19 2014 14:07:05 for ns-3 by
1.8.6