25 #include "ns3/assert.h"
49 static uint32_t
lookuphash (
unsigned char* k, uint32_t length, uint32_t level)
52 #define mix(a, b, c) \
54 (a) -= (b); (a) -= (c); (a) ^= ((c) >> 13); \
55 (b) -= (c); (b) -= (a); (b) ^= ((a) << 8); \
56 (c) -= (a); (c) -= (b); (c) ^= ((b) >> 13); \
57 (a) -= (b); (a) -= (c); (a) ^= ((c) >> 12); \
58 (b) -= (c); (b) -= (a); (b) ^= ((a) << 16); \
59 (c) -= (a); (c) -= (b); (c) ^= ((b) >> 5); \
60 (a) -= (b); (a) -= (c); (a) ^= ((c) >> 3); \
61 (b) -= (c); (b) -= (a); (b) ^= ((a) << 10); \
62 (c) -= (a); (c) -= (b); (c) ^= ((b) >> 15); \
79 a += (k[0] + ((ub4)k[1] << 8) + ((ub4)k[2] << 16) + ((ub4)k[3] << 24));
80 b += (k[4] + ((ub4)k[5] << 8) + ((ub4)k[6] << 16) + ((ub4)k[7] << 24));
81 c += (k[8] + ((ub4)k[9] << 8) + ((ub4)k[10] << 16) + ((ub4)k[11] << 24));
91 case 11: c += ((ub4)k[10] << 24);
92 case 10: c += ((ub4)k[9] << 16);
93 case 9: c += ((ub4)k[8] << 8);
94 case 8: b += ((ub4)k[7] << 24);
95 case 7: b += ((ub4)k[6] << 16);
96 case 6: b += ((ub4)k[5] << 8);
98 case 4: a += ((ub4)k[3] << 24);
99 case 3: a += ((ub4)k[2] << 16);
100 case 2: a += ((ub4)k[1] << 8);
125 static const char xdigits_l[] =
"0123456789abcdef";
126 static const char xdigits_u[] =
"0123456789ABCDEF";
127 unsigned char tmp[16];
128 unsigned char* tp = tmp;
129 unsigned char* endp = 0;
130 unsigned char* colonp = 0;
131 const char* xdigits = 0;
133 const char* curtok = 0;
136 int seen_xdigits = 0;
137 unsigned int val = 0;
139 memset (tp, 0x00, 16);
145 if (*++address !=
':')
153 while ((ch = *address++) !=
'\0')
157 if ((pch = strchr ((xdigits = xdigits_l), ch)) == 0)
159 pch = strchr ((xdigits = xdigits_u), ch);
165 val |= (pch - xdigits);
167 if (++seen_xdigits > 4)
192 *tp++ = (
unsigned char)(val >> 8) & 0xff;
193 *tp++ = (
unsigned char) val & 0xff;
201 if (ch ==
'.' && ((tp + 4 ) <= endp) &&
202 inet_pton4 (curtok, tp) > 0)
218 *tp++ = (
unsigned char)(val >> 8) & 0xff;
219 *tp++ = (
unsigned char) val & 0xff;
228 const int n = tp - colonp;
236 for (i = 1; i <= n; i++)
238 endp[-i] = colonp[n - i];
250 memcpy (addr, tmp, 16);
320 uint8_t buf[16] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
321 0x00, 0x00, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00 };
347 memcpy (buf2 + 14, buf, 2);
365 memcpy (buf2 + 8, buf, 3);
368 memcpy (buf2 + 13, buf + 3, 3);
385 memcpy (buf2 + 8, buf, 8);
400 memset (buf2, 0x00,
sizeof (buf2));
403 memcpy (buf2 + 14, buf, 2);
420 memset (buf2, 0x00,
sizeof (buf2));
423 memcpy (buf2 + 8, buf, 3);
426 memcpy (buf2 + 13, buf + 3, 3);
442 memset (buf2, 0x00,
sizeof (buf2));
445 memcpy (buf2 + 8, buf, 8);
460 memset (buf, 0x00,
sizeof (buf));
476 os << std::hex << std::setw (2) << std::setfill (
'0') << (
unsigned int)
m_address[0]
477 << std::hex << std::setw (2) << std::setfill (
'0') << (
unsigned int)
m_address[1] <<
":"
478 << std::hex << std::setw (2) << std::setfill (
'0') << (
unsigned int)
m_address[2]
479 << std::hex << std::setw (2) << std::setfill (
'0') << (
unsigned int)
m_address[3] <<
":"
480 << std::hex << std::setw (2) << std::setfill (
'0') << (
unsigned int)
m_address[4]
481 << std::hex << std::setw (2) << std::setfill (
'0') << (
unsigned int)
m_address[5] <<
":"
482 << std::hex << std::setw (2) << std::setfill (
'0') << (
unsigned int)
m_address[6]
483 << std::hex << std::setw (2) << std::setfill (
'0') << (
unsigned int)
m_address[7] <<
":"
484 << std::hex << std::setw (2) << std::setfill (
'0') << (
unsigned int)
m_address[8]
485 << std::hex << std::setw (2) << std::setfill (
'0') << (
unsigned int)
m_address[9] <<
":"
486 << std::hex << std::setw (2) << std::setfill (
'0') << (
unsigned int)
m_address[10]
487 << std::hex << std::setw (2) << std::setfill (
'0') << (
unsigned int)
m_address[11] <<
":"
488 << std::hex << std::setw (2) << std::setfill (
'0') << (
unsigned int)
m_address[12]
489 << std::hex << std::setw (2) << std::setfill (
'0') << (
unsigned int)
m_address[13] <<
":"
490 << std::hex << std::setw (2) << std::setfill (
'0') << (
unsigned int)
m_address[14]
491 << std::hex << std::setw (2) << std::setfill (
'0') << (
unsigned int)
m_address[15]
492 << std::dec << std::setfill (
' ');
499 return (*
this == localhost);
525 uint8_t v4MappedPrefix[12] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
526 0x00, 0x00, 0xff, 0xff };
527 if (memcmp(
m_address, v4MappedPrefix,
sizeof(v4MappedPrefix)) == 0)
546 for (i = 0; i < 16; i++)
548 addr[i] = addr[i] & pref[i];
561 if (buf[0] == 0xff &&
575 return (*
this == allnodes);
582 return (*
this == allrouters);
589 return (*
this == allhosts);
596 return (*
this == any);
692 static Ipv6Address ones (
"ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff");
783 for (i = nb; i < 16; i++)
817 for (i = 0; i < 16; i++)
830 os << std::hex << std::setw (2) << std::setfill (
'0') << (
unsigned int)
m_prefix[0]
831 << std::hex << std::setw (2) << std::setfill (
'0') << (
unsigned int)
m_prefix[1] <<
":"
832 << std::hex << std::setw (2) << std::setfill (
'0') << (
unsigned int)
m_prefix[2]
833 << std::hex << std::setw (2) << std::setfill (
'0') << (
unsigned int)
m_prefix[3] <<
":"
834 << std::hex << std::setw (2) << std::setfill (
'0') << (
unsigned int)
m_prefix[4]
835 << std::hex << std::setw (2) << std::setfill (
'0') << (
unsigned int)
m_prefix[5] <<
":"
836 << std::hex << std::setw (2) << std::setfill (
'0') << (
unsigned int)
m_prefix[6]
837 << std::hex << std::setw (2) << std::setfill (
'0') << (
unsigned int)
m_prefix[7] <<
":"
838 << std::hex << std::setw (2) << std::setfill (
'0') << (
unsigned int)
m_prefix[8]
839 << std::hex << std::setw (2) << std::setfill (
'0') << (
unsigned int)
m_prefix[9] <<
":"
840 << std::hex << std::setw (2) << std::setfill (
'0') << (
unsigned int)
m_prefix[10]
841 << std::hex << std::setw (2) << std::setfill (
'0') << (
unsigned int)
m_prefix[11] <<
":"
842 << std::hex << std::setw (2) << std::setfill (
'0') << (
unsigned int)
m_prefix[12]
843 << std::hex << std::setw (2) << std::setfill (
'0') << (
unsigned int)
m_prefix[13] <<
":"
844 << std::hex << std::setw (2) << std::setfill (
'0') << (
unsigned int)
m_prefix[14]
845 << std::hex << std::setw (2) << std::setfill (
'0') << (
unsigned int)
m_prefix[15];
879 uint8_t prefixLength = 0;
881 for(i = 0; i < 16; i++)
bool IsMatch(Ipv6Address a, Ipv6Address b) const
If the Address match the type.
static bool IsMatchingType(const Address &address)
If the Address matches the type.
bool IsAny() const
If the IPv6 address is the "Any" address.
static Ipv4Address Deserialize(const uint8_t buf[4])
static Ipv6Address GetLoopback()
Get the loopback address.
std::istream & operator>>(std::istream &is, Angles &a)
#define NS_LOG_FUNCTION(parameters)
Ipv6Address()
Default constructor.
uint8_t m_address[16]
The address representation on 128 bits (16 bytes).
bool IsLinkLocalMulticast() const
If the IPv6 address is link-local multicast (ff02::/16).
Ipv6Prefix()
Default constructor.
static Ipv6Address Deserialize(const uint8_t buf[16])
Deserialize this address.
bool IsLinkLocal() const
If the IPv6 address is a link-local address (fe80::/64).
bool IsAllRoutersMulticast() const
If the IPv6 address is "all routers multicast" (ff02::2/8).
#define NS_ASSERT(condition)
bool IsEqual(const Ipv6Prefix &other) const
Comparison operation between two Ipv6Prefix.
static Ipv6Address GetAny()
Get the "any" (::) Ipv6Address.
static Ipv6Address MakeAutoconfiguredAddress(Mac16Address addr, Ipv6Address prefix)
Make the autoconfigured IPv6 address with Mac16Address.
#define NS_LOG_COMPONENT_DEFINE(name)
size_t operator()(Ipv6Address const &x) const
Unary operator to hash IPv6 address.
bool IsEqual(const Ipv6Address &other) const
Comparison operation between two Ipv6Addresses.
bool IsDocumentation() const
If the IPv6 address is a documentation address (2001:DB8::/32).
bool IsAllHostsMulticast() const
If the IPv6 address is "all hosts multicast" (ff02::3/8).
#define NS_LOG_FUNCTION_NOARGS()
bool IsAllNodesMulticast() const
If the IPv6 address is "all nodes multicast" (ff02::1/8).
static Ipv6Prefix GetZero()
Get the zero prefix ( /0).
static uint32_t lookuphash(unsigned char *k, uint32_t length, uint32_t level)
Get a hash key.
a polymophic address class
bool CheckCompatible(uint8_t type, uint8_t len) const
void CopyTo(uint8_t buffer[8]) const
void CopyTo(uint8_t buffer[6]) const
Address ConvertTo(void) const
convert the IPv6Address object to an Address object.
static Ipv6Address GetZero()
Get the 0 (::) Ipv6Address.
void CopyTo(uint8_t buffer[2]) const
void Print(std::ostream &os) const
Print this address to the given output stream.
void Serialize(uint8_t buf[4]) const
void GetBytes(uint8_t buf[16]) const
Get the bytes corresponding to the address.
void Set(char const *address)
Sets an Ipv6Address by parsing the input C-string.
static Ipv6Address GetAllHostsMulticast()
Get the "all hosts multicast" address.
std::ostream & operator<<(std::ostream &os, const Angles &a)
bool operator!=(Callback< R, T1, T2, T3, T4, T5, T6, T7, T8, T9 > a, Callback< R, T1, T2, T3, T4, T5, T6, T7, T8, T9 > b)
bool IsMulticast() const
If the IPv6 address is multicast (ff00::/8).
static Ipv6Address GetAllNodesMulticast()
Get the "all nodes multicast" address.
uint8_t m_prefix[16]
The prefix representation.
static bool AsciiToIpv6Host(const char *address, uint8_t addr[16])
Convert an IPv6 C-string into a 128-bit representation.
static Ipv6Address MakeAutoconfiguredLinkLocalAddress(Mac16Address mac)
Make the autoconfigured link-local IPv6 address with Mac16Address.
Describes an IPv6 address.
Ipv4 addresses are stored in host order in this class.
void Print(std::ostream &os) const
Print this address to the given output stream.
bool IsSolicitedMulticast() const
If the IPv6 address is a Solicited multicast address.
static Ipv6Prefix GetOnes()
Get the "all-1" IPv6 mask (ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff).
uint32_t CopyTo(uint8_t buffer[MAX_SIZE]) const
void GetBytes(uint8_t buf[16]) const
Get the bytes corresponding to the prefix.
bool operator==(const EventId &a, const EventId &b)
~Ipv6Address()
Destructor.
static Ipv6Address GetOnes()
Get the "all-1" IPv6 address (ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff).
static Ipv6Prefix GetLoopback()
Get the loopback prefix ( /128).
Describes an IPv6 prefix. It is just a bitmask like Ipv4Mask.
Ipv4Address GetIpv4MappedAddress() const
Return the Ipv4 address.
uint8_t GetPrefixLength() const
Get prefix length.
ATTRIBUTE_HELPER_CPP(ObjectFactory)
bool IsLocalhost() const
If the IPv6 address is localhost (::1).
static Ipv6Address MakeIpv4MappedAddress(Ipv4Address addr)
Make the Ipv4-mapped IPv6 address.
Ipv6Address CombinePrefix(Ipv6Prefix const &prefix)
Combine this address with a prefix.
bool IsIpv4MappedAddress()
If the address is an IPv4-mapped address.
static uint8_t Register(void)
static uint8_t GetType(void)
Return the Type of address.
static Ipv6Address MakeSolicitedAddress(Ipv6Address addr)
Make the solicited IPv6 address.
static Ipv6Address GetAllRoutersMulticast()
Get the "all routers multicast" address.
static Ipv6Address ConvertFrom(const Address &address)
Convert the Address object into an Ipv6Address ones.
void Serialize(uint8_t buf[16]) const
Serialize this address to a 16-byte buffer.