A Discrete-Event Network Simulator
API
 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 
29 {
30  NS_LOG_FUNCTION (&i << &ad);
31  i.WriteHtonU32 (ad.Get ());
32 }
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 }
48 {
49  NS_LOG_FUNCTION (&i << &ad);
50  uint8_t mac[8];
51  ad.CopyTo (mac);
52  i.Write (mac, 8);
53 }
55 {
56  NS_LOG_FUNCTION (&i << &ad);
57  uint8_t mac[6];
58  ad.CopyTo (mac);
59  i.Write (mac, 6);
60 }
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 
71 {
72  NS_LOG_FUNCTION (&i << &ad);
73  ad.Set (i.ReadNtohU32 ());
74 }
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 }
90 {
91  NS_LOG_FUNCTION (&i << &ad);
92  uint8_t mac[8];
93  i.Read (mac, 8);
94  ad.CopyFrom (mac);
95 }
97 {
98  NS_LOG_FUNCTION (&i << &ad);
99  uint8_t mac[6];
100  i.Read (mac, 6);
101  ad.CopyFrom (mac);
102 }
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);
118  {
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
an Inet address class
Ipv4Address GetIpv4(void) const
#define NS_LOG_FUNCTION(parameters)
Definition: log.h:345
NS_LOG_COMPONENT_DEFINE("AddressUtils")
bool IsMulticast(const Address &ad)
Address family-independent test for a multicast address.
void ReadFrom(Buffer::Iterator &i, Ipv4Address &ad)
Read an Ipv4Address from a Buffer.
void CopyFrom(const uint8_t buffer[2])
void WriteTo(Buffer::Iterator &i, Ipv4Address ad)
Write an Ipv4Address to a Buffer.
bool IsMulticast(void) const
uint32_t ReadNtohU32(void)
Definition: buffer.h:791
iterator in a Buffer instance
Definition: buffer.h:98
a polymophic address class
Definition: address.h:86
an EUI-64 address
Definition: mac64-address.h:41
void CopyTo(uint8_t buffer[8]) const
void CopyTo(uint8_t buffer[6]) const
uint32_t Get(void) const
Get the host-order 32-bit IP address.
uint8_t GetLength(void) const
Definition: address.cc:75
void CopyTo(uint8_t buffer[2]) const
void GetBytes(uint8_t buf[16]) const
Get the bytes corresponding to the address.
void CopyFrom(const uint8_t buffer[8])
void Set(char const *address)
Sets an Ipv6Address by parsing the input C-string.
static InetSocketAddress ConvertFrom(const Address &address)
uint32_t CopyFrom(const uint8_t *buffer, uint8_t len)
Definition: address.cc:101
an EUI-48 address
Definition: mac48-address.h:41
void Read(uint8_t *buffer, uint32_t size)
Definition: buffer.cc:1148
This class can contain 16 bit addresses.
Definition: mac16-address.h:39
void CopyFrom(const uint8_t buffer[6])
void WriteHtonU32(uint32_t data)
Definition: buffer.h:745
void Set(uint32_t address)
input address is in host order.
Describes an IPv6 address.
Definition: ipv6-address.h:46
Ipv4 addresses are stored in host order in this class.
Definition: ipv4-address.h:38
uint32_t CopyTo(uint8_t buffer[MAX_SIZE]) const
Definition: address.cc:82
void Write(uint8_t const *buffer, uint32_t size)
Definition: buffer.cc:978
static bool IsMatchingType(const Address &address)