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