20 #include "mac48-address.h"
21 #include "ns3/address.h"
22 #include "ns3/assert.h"
34 #define ASCII_a (0x41)
35 #define ASCII_z (0x5a)
36 #define ASCII_A (0x61)
37 #define ASCII_Z (0x7a)
38 #define ASCII_COLON (0x3a)
39 #define ASCII_ZERO (0x30)
42 AsciiToLowCase (
char c)
45 if (c >= ASCII_a && c <= ASCII_z) {
47 }
else if (c >= ASCII_A && c <= ASCII_Z) {
48 return c + (ASCII_a - ASCII_A);
55 Mac48Address::Mac48Address ()
58 std::memset (m_address, 0, 6);
60 Mac48Address::Mac48Address (
const char *str)
64 while (*str != 0 && i < 6)
67 while (*str != ASCII_COLON && *str != 0)
70 char low = AsciiToLowCase (*str);
73 byte |= low - ASCII_a + 10;
77 byte |= low - ASCII_ZERO;
95 std::memcpy (m_address, buffer, 6);
101 std::memcpy (buffer, m_address, 6);
118 return Address (GetType (), m_address, 6);
126 address.
CopyTo (retval.m_address);
133 static uint64_t
id = 0;
136 address.m_address[0] = (
id >> 40) & 0xff;
137 address.m_address[1] = (
id >> 32) & 0xff;
138 address.m_address[2] = (
id >> 24) & 0xff;
139 address.m_address[3] = (
id >> 16) & 0xff;
140 address.m_address[4] = (
id >> 8) & 0xff;
141 address.m_address[5] = (
id >> 0) & 0xff;
145 Mac48Address::GetType (
void)
162 return (m_address[0] & 0x01) == 0x01;
195 uint8_t etherBuffer[6];
196 etherAddr.
CopyTo (etherBuffer);
210 etherBuffer[3] |= ipBuffer[1] & 0x7f;
211 etherBuffer[4] = ipBuffer[2];
212 etherBuffer[5] = ipBuffer[3];
226 uint8_t etherBuffer[6];
227 uint8_t ipBuffer[16];
231 etherAddr.
CopyTo (etherBuffer);
234 etherBuffer[2] = ipBuffer[12];
235 etherBuffer[3] = ipBuffer[13];
236 etherBuffer[4] = ipBuffer[14];
237 etherBuffer[5] = ipBuffer[15];
249 os.setf (std::ios::hex, std::ios::basefield);
251 for (uint8_t i=0; i < 5; i++)
253 os << std::setw (2) << (uint32_t)ad[i] <<
":";
256 os << std::setw (2) << (uint32_t)ad[5];
257 os.setf (std::ios::dec, std::ios::basefield);
263 AsInt (std::string v)
266 std::istringstream iss;
269 iss >> std::hex >> retval >> std::dec;
273 std::istream&
operator>> (std::istream& is, Mac48Address & address)
278 std::string::size_type col = 0;
279 for (uint8_t i = 0; i < 6; ++i)
282 std::string::size_type next;
283 next = v.find (
":", col);
284 if (next == std::string::npos)
286 tmp = v.substr (col, v.size ()-col);
287 address.m_address[i] = AsInt (tmp);
292 tmp = v.substr (col, next-col);
293 address.m_address[i] = AsInt (tmp);
static bool IsMatchingType(const Address &address)
std::istream & operator>>(std::istream &is, Angles &a)
#define NS_LOG_FUNCTION(parameters)
static Mac48Address GetMulticastPrefix(void)
#define NS_ASSERT(condition)
#define NS_LOG_COMPONENT_DEFINE(name)
bool IsBroadcast(void) const
#define NS_LOG_FUNCTION_NOARGS()
a polymophic address class
bool CheckCompatible(uint8_t type, uint8_t len) const
void CopyTo(uint8_t buffer[6]) const
static Mac48Address Allocate(void)
static Mac48Address GetMulticast(Ipv4Address address)
static Mac48Address GetBroadcast(void)
void Serialize(uint8_t buf[4]) const
static Mac48Address ConvertFrom(const Address &address)
std::ostream & operator<<(std::ostream &os, const Angles &a)
#define ATTRIBUTE_HELPER_CPP(type)
void CopyFrom(const uint8_t buffer[6])
Describes an IPv6 address.
Ipv4 addresses are stored in host order in this class.
uint32_t CopyTo(uint8_t buffer[MAX_SIZE]) const
static Mac48Address GetMulticast6Prefix(void)
Get the multicast prefix for IPv6 (33:33:00:00:00:00).
Address ConvertTo(void) const
static uint8_t Register(void)
void Serialize(uint8_t buf[16]) const
Serialize this address to a 16-byte buffer.