A Discrete-Event Network Simulator
API
Loading...
Searching...
No Matches
address-utils.cc
Go to the documentation of this file.
1/*
2 * Copyright (c) 2006 INRIA
3 *
4 * SPDX-License-Identifier: GPL-2.0-only
5 *
6 * Author: Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
7 */
8#include "address-utils.h"
9
10#include "inet-socket-address.h"
12
13#include "ns3/log.h"
14
15namespace ns3
16{
17
18NS_LOG_COMPONENT_DEFINE("AddressUtils");
19
20void
22{
23 NS_LOG_FUNCTION(&i << &ad);
24 i.WriteHtonU32(ad.Get());
25}
26
27void
29{
30 NS_LOG_FUNCTION(&i << &ad);
31 uint8_t buf[16];
32 ad.GetBytes(buf);
33 i.Write(buf, 16);
34}
35
36void
38{
39 NS_LOG_FUNCTION(&i << &ad);
40 uint8_t mac[Address::MAX_SIZE];
41 ad.CopyTo(mac);
42 i.Write(mac, ad.GetLength());
43}
44
45void
47{
48 NS_LOG_FUNCTION(&i << &ad);
49 uint8_t mac[8];
50 ad.CopyTo(mac);
51 i.Write(mac, 8);
52}
53
54void
56{
57 NS_LOG_FUNCTION(&i << &ad);
58 uint8_t mac[6];
59 ad.CopyTo(mac);
60 i.Write(mac, 6);
61}
62
63void
65{
66 NS_LOG_FUNCTION(&i << &ad);
67 uint8_t mac[2];
68 ad.CopyTo(mac);
69 i.Write(mac + 1, 1);
70 i.Write(mac, 1);
71}
72
73void
75{
76 NS_LOG_FUNCTION(&i << &ad);
77 ad.Set(i.ReadNtohU32());
78}
79
80void
82{
83 NS_LOG_FUNCTION(&i << &ad);
84 uint8_t ipv6[16];
85 i.Read(ipv6, 16);
86 ad.Set(ipv6);
87}
88
89void
91{
92 NS_LOG_FUNCTION(&i << &ad << len);
93 uint8_t mac[Address::MAX_SIZE];
94 i.Read(mac, len);
95 ad.CopyFrom(mac, len);
96}
97
98void
100{
101 NS_LOG_FUNCTION(&i << &ad);
102 uint8_t mac[8];
103 i.Read(mac, 8);
104 ad.CopyFrom(mac);
105}
106
107void
109{
110 NS_LOG_FUNCTION(&i << &ad);
111 uint8_t mac[6];
112 i.Read(mac, 6);
113 ad.CopyFrom(mac);
114}
115
116void
118{
119 NS_LOG_FUNCTION(&i << &ad);
120 uint8_t mac[2];
121 i.Read(mac + 1, 1);
122 i.Read(mac, 1);
123 ad.CopyFrom(mac);
124}
125
126namespace addressUtils
127{
128
129bool
131{
132 NS_LOG_FUNCTION(&ad);
134 {
136 Ipv4Address ipv4 = inetAddr.GetIpv4();
137 return ipv4.IsMulticast();
138 }
139 else if (Ipv4Address::IsMatchingType(ad))
140 {
142 return ipv4.IsMulticast();
143 }
145 {
147 Ipv6Address ipv6 = inetAddr.GetIpv6();
148 return ipv6.IsMulticast();
149 }
150 else if (Ipv6Address::IsMatchingType(ad))
151 {
153 return ipv6.IsMulticast();
154 }
155
156 return false;
157}
158
159} // namespace addressUtils
160
161} // namespace ns3
a polymophic address class
Definition address.h:90
uint32_t CopyFrom(const uint8_t *buffer, uint8_t len)
Definition address.cc:95
static constexpr uint32_t MAX_SIZE
The maximum size of a byte buffer which can be stored in an Address instance.
Definition address.h:96
uint8_t GetLength() const
Get the length of the underlying address.
Definition address.cc:67
uint32_t CopyTo(uint8_t buffer[MAX_SIZE]) const
Copy the address bytes into a buffer.
Definition address.cc:75
iterator in a Buffer instance
Definition buffer.h:89
void Write(const uint8_t *buffer, uint32_t size)
Definition buffer.cc:937
void Read(uint8_t *buffer, uint32_t size)
Definition buffer.cc:1114
uint32_t ReadNtohU32()
Definition buffer.h:967
void WriteHtonU32(uint32_t data)
Definition buffer.h:922
An Inet6 address class.
static Inet6SocketAddress ConvertFrom(const Address &addr)
Convert the address to a InetSocketAddress.
static bool IsMatchingType(const Address &addr)
If the address match.
Ipv6Address GetIpv6() const
Get the IPv6 address.
an Inet address class
static bool IsMatchingType(const Address &address)
Ipv4Address GetIpv4() const
static InetSocketAddress ConvertFrom(const Address &address)
Returns an InetSocketAddress which corresponds to the input Address.
Ipv4 addresses are stored in host order in this class.
static Ipv4Address ConvertFrom(const Address &address)
static bool IsMatchingType(const Address &address)
void Set(uint32_t address)
input address is in host order.
uint32_t Get() const
Get the host-order 32-bit IP address.
Describes an IPv6 address.
bool IsMulticast() const
If the IPv6 address is multicast (ff00::/8).
void GetBytes(uint8_t buf[16]) const
Get the bytes corresponding to the address.
void Set(const char *address)
Sets an Ipv6Address by parsing the input C-string.
static Ipv6Address ConvertFrom(const Address &address)
Convert the Address object into an Ipv6Address ones.
static bool IsMatchingType(const Address &address)
If the Address matches the type.
This class can contain 16 bit addresses.
void CopyTo(uint8_t buffer[2]) const
void CopyFrom(const uint8_t buffer[2])
an EUI-48 address
void CopyFrom(const uint8_t buffer[6])
void CopyTo(uint8_t buffer[6]) const
an EUI-64 address
void CopyFrom(const uint8_t buffer[8])
void CopyTo(uint8_t buffer[8]) const
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition log.h:191
#define NS_LOG_FUNCTION(parameters)
If log level LOG_FUNCTION is enabled, this macro will output all input parameters separated by ",...
bool IsMulticast(const Address &ad)
Address family-independent test for a multicast address.
Every class exported by the ns3 library is enclosed in the ns3 namespace.
void WriteTo(Buffer::Iterator &i, Ipv4Address ad)
Write an Ipv4Address to a Buffer.
void ReadFrom(Buffer::Iterator &i, Ipv4Address &ad)
Read an Ipv4Address from a Buffer.