25 #include "ns3/assert.h" 
   27 #include "mac48-address.h" 
   28 #include "ipv6-address.h" 
   47 static uint32_t 
lookuphash (
unsigned char* k, uint32_t length, uint32_t level)
 
   50 #define mix(a, b, c) \ 
   52      (a) -= (b); (a) -= (c); (a) ^= ((c) >> 13); \ 
   53      (b) -= (c); (b) -= (a); (b) ^= ((a) << 8);  \ 
   54      (c) -= (a); (c) -= (b); (c) ^= ((b) >> 13); \ 
   55      (a) -= (b); (a) -= (c); (a) ^= ((c) >> 12); \ 
   56      (b) -= (c); (b) -= (a); (b) ^= ((a) << 16); \ 
   57      (c) -= (a); (c) -= (b); (c) ^= ((b) >> 5);  \ 
   58      (a) -= (b); (a) -= (c); (a) ^= ((c) >> 3);  \ 
   59      (b) -= (c); (b) -= (a); (b) ^= ((a) << 10); \ 
   60      (c) -= (a); (c) -= (b); (c) ^= ((b) >> 15); \ 
   77       a += (k[0] + ((ub4)k[1] << 8) + ((ub4)k[2] << 16) + ((ub4)k[3] << 24));
 
   78       b += (k[4] + ((ub4)k[5] << 8) + ((ub4)k[6] << 16) + ((ub4)k[7] << 24));
 
   79       c += (k[8] + ((ub4)k[9] << 8) + ((ub4)k[10] << 16) + ((ub4)k[11] << 24));
 
   89     case 11: c += ((ub4)k[10] << 24);
 
   90     case 10: c += ((ub4)k[9] << 16);
 
   91     case 9: c += ((ub4)k[8] << 8);  
 
   92     case 8: b += ((ub4)k[7] << 24);
 
   93     case 7: b += ((ub4)k[6] << 16);
 
   94     case 6: b += ((ub4)k[5] << 8);
 
   96     case 4: a += ((ub4)k[3] << 24);
 
   97     case 3: a += ((ub4)k[2] << 16);
 
   98     case 2: a += ((ub4)k[1] << 8);
 
  123   static const char xdigits_l[] = 
"0123456789abcdef";
 
  124   static const char xdigits_u[] = 
"0123456789ABCDEF";
 
  125   unsigned char tmp[16];
 
  126   unsigned char* tp = tmp;
 
  127   unsigned char* endp = 0;
 
  128   unsigned char* colonp = 0;
 
  129   const char* xdigits = 0;
 
  131   const char* curtok = 0;
 
  134   int seen_xdigits = 0;
 
  135   unsigned int val = 0;
 
  137   memset (tp, 0x00, 16);
 
  143       if (*++address != 
':')
 
  151   while ((ch = *address++) != 
'\0')
 
  155       if ((pch = strchr ((xdigits = xdigits_l), ch)) == 0)
 
  157           pch = strchr ((xdigits = xdigits_u), ch);
 
  163           val |= (pch - xdigits);
 
  165           if (++seen_xdigits > 4)
 
  190           *tp++ = (
unsigned char)(val >> 8) & 0xff;
 
  191           *tp++ = (
unsigned char) val & 0xff;
 
  199       if (ch == 
'.' && ((tp + 4 ) <= endp) &&
 
  200           inet_pton4 (curtok, tp) > 0)
 
  216       *tp++ = (
unsigned char)(val >> 8) & 0xff;
 
  217       *tp++ = (
unsigned char) val & 0xff;
 
  226       const int n = tp - colonp;
 
  234       for (i = 1; i <= n; i++)
 
  236           endp[-i] = colonp[n - i];
 
  248   memcpy (addr, tmp, 16);
 
  318   uint8_t buf[16] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
 
  319                       0x00, 0x00, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00 };
 
  345   memcpy (buf2 + 8, buf, 3);
 
  348   memcpy (buf2 + 13, buf + 3, 3);
 
  364   memset (buf2, 0x00, 
sizeof (buf2));
 
  367   memcpy (buf2 + 8, buf, 3);
 
  370   memcpy (buf2 + 13, buf + 3, 3);
 
  386   memset (buf, 0x00, 
sizeof (buf));
 
  402   os << std::hex << std::setw (2) << std::setfill (
'0') << (
unsigned int) 
m_address[0]
 
  403      << std::hex << std::setw (2) << std::setfill (
'0') << (
unsigned int) 
m_address[1] << 
":" 
  404      << std::hex << std::setw (2) << std::setfill (
'0') << (
unsigned int) 
m_address[2]
 
  405      << std::hex << std::setw (2) << std::setfill (
'0') << (
unsigned int) 
m_address[3] << 
":" 
  406      << std::hex << std::setw (2) << std::setfill (
'0') << (
unsigned int) 
m_address[4]
 
  407      << std::hex << std::setw (2) << std::setfill (
'0') << (
unsigned int) 
m_address[5] << 
":" 
  408      << std::hex << std::setw (2) << std::setfill (
'0') << (
unsigned int) 
m_address[6]
 
  409      << std::hex << std::setw (2) << std::setfill (
'0') << (
unsigned int) 
m_address[7] << 
":" 
  410      << std::hex << std::setw (2) << std::setfill (
'0') << (
unsigned int) 
m_address[8]
 
  411      << std::hex << std::setw (2) << std::setfill (
'0') << (
unsigned int) 
m_address[9] << 
":" 
  412      << std::hex << std::setw (2) << std::setfill (
'0') << (
unsigned int) 
m_address[10]
 
  413      << std::hex << std::setw (2) << std::setfill (
'0') << (
unsigned int) 
m_address[11] << 
":" 
  414      << std::hex << std::setw (2) << std::setfill (
'0') << (
unsigned int) 
m_address[12]
 
  415      << std::hex << std::setw (2) << std::setfill (
'0') << (
unsigned int) 
m_address[13] << 
":" 
  416      << std::hex << std::setw (2) << std::setfill (
'0') << (
unsigned int) 
m_address[14]
 
  417      << std::hex << std::setw (2) << std::setfill (
'0') << (
unsigned int) 
m_address[15]
 
  418      << std::dec << std::setfill (
' ');
 
  425   return (*
this == localhost);
 
  451   uint8_t v4MappedPrefix[12] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
 
  452                                  0x00, 0x00, 0xff, 0xff };
 
  453   if (memcmp(
m_address, v4MappedPrefix, 
sizeof(v4MappedPrefix)) == 0)
 
  472   for (i = 0; i < 16; i++)
 
  474       addr[i] = addr[i] & pref[i];
 
  487   if (buf[0] == 0xff && 
 
  501   return (*
this == allnodes);
 
  508   return (*
this == allrouters);
 
  515   return (*
this == allhosts);
 
  522   return (*
this == any);
 
  605   static Ipv6Address ones (
"ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff");
 
  642 std::istream& 
operator >> (std::istream& is, Ipv6Address& address)
 
  646   address = Ipv6Address (str.c_str ());
 
  696       for (i = nb; i < 16; i++)
 
  730   for (i = 0; i < 16; i++)
 
  743   os << std::hex << std::setw (2) << std::setfill (
'0') << (
unsigned int) 
m_prefix[0]
 
  744   << std::hex << std::setw (2) << std::setfill (
'0') << (
unsigned int) 
m_prefix[1] << 
":" 
  745   << std::hex << std::setw (2) << std::setfill (
'0') << (
unsigned int) 
m_prefix[2]
 
  746   << std::hex << std::setw (2) << std::setfill (
'0') << (
unsigned int) 
m_prefix[3] << 
":" 
  747   << std::hex << std::setw (2) << std::setfill (
'0') << (
unsigned int) 
m_prefix[4]
 
  748   << std::hex << std::setw (2) << std::setfill (
'0') << (
unsigned int) 
m_prefix[5] << 
":" 
  749   << std::hex << std::setw (2) << std::setfill (
'0') << (
unsigned int) 
m_prefix[6]
 
  750   << std::hex << std::setw (2) << std::setfill (
'0') << (
unsigned int) 
m_prefix[7] << 
":" 
  751   << std::hex << std::setw (2) << std::setfill (
'0') << (
unsigned int) 
m_prefix[8]
 
  752   << std::hex << std::setw (2) << std::setfill (
'0') << (
unsigned int) 
m_prefix[9] << 
":" 
  753   << std::hex << std::setw (2) << std::setfill (
'0') << (
unsigned int) 
m_prefix[10]
 
  754   << std::hex << std::setw (2) << std::setfill (
'0') << (
unsigned int) 
m_prefix[11] << 
":" 
  755   << std::hex << std::setw (2) << std::setfill (
'0') << (
unsigned int) 
m_prefix[12]
 
  756   << std::hex << std::setw (2) << std::setfill (
'0') << (
unsigned int) 
m_prefix[13] << 
":" 
  757   << std::hex << std::setw (2) << std::setfill (
'0') << (
unsigned int) 
m_prefix[14]
 
  758   << std::hex << std::setw (2) << std::setfill (
'0') << (
unsigned int) 
m_prefix[15];
 
  792   uint8_t prefixLength = 0;
 
  794   for(i = 0; i < 16; i++)
 
  823 std::istream& 
operator >> (std::istream& is, Ipv6Prefix& prefix)
 
  827   prefix = Ipv6Prefix (str.c_str ());
 
  831 bool operator == (Ipv6Prefix 
const &a, Ipv6Prefix 
const &b)
 
  833   return a.IsEqual (b);
 
  836 bool operator != (Ipv6Prefix 
const &a, Ipv6Prefix 
const &b)
 
  838   return !a.IsEqual (b);
 
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)
static Ipv6Address MakeAutoconfiguredAddress(Mac48Address addr, Ipv6Address prefix)
Make the autoconfigured IPv6 address with Mac48Address. 
#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. 
#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 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[6]) const 
Address ConvertTo(void) const 
convert the IPv6Address object to an Address object. 
static Ipv6Address GetZero()
Get the 0 (::) Ipv6Address. 
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)
#define ATTRIBUTE_HELPER_CPP(type)
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. 
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. 
~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. 
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. 
static Ipv6Address MakeAutoconfiguredLinkLocalAddress(Mac48Address mac)
Make the autoconfigured link-local IPv6 address with Mac48Address. 
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.