15#include "ns3/assert.h"
25#include <sys/socket.h>
101 a += (k[0] + ((ub4)k[1] << 8) + ((ub4)k[2] << 16) + ((ub4)k[3] << 24));
102 b += (k[4] + ((ub4)k[5] << 8) + ((ub4)k[6] << 16) + ((ub4)k[7] << 24));
103 c += (k[8] + ((ub4)k[9] << 8) + ((ub4)k[10] << 16) + ((ub4)k[11] << 24));
114 c += ((ub4)k[10] << 24);
116 c += ((ub4)k[9] << 16);
118 c += ((ub4)k[8] << 8);
120 b += ((ub4)k[7] << 24);
122 b += ((ub4)k[6] << 16);
124 b += ((ub4)k[5] << 8);
128 a += ((ub4)k[3] << 24);
130 a += ((ub4)k[2] << 16);
132 a += ((ub4)k[1] << 8);
169 if (inet_pton(AF_INET6, address,
m_address) <= 0)
171 NS_ABORT_MSG(
"Error, can not build an IPv6 address from an invalid string: " << address);
183 if (inet_pton(AF_INET6, addressStr.c_str(), &buffer) <= 0)
185 NS_LOG_WARN(
"Error, can not build an IPv6 address from an invalid string: " << addressStr);
208 if (inet_pton(AF_INET6, address,
m_address) <= 0)
211 NS_ABORT_MSG(
"Error, can not set an IPv6 address from an invalid string: " << address);
299 if (ipv6Addr.
IsAny())
323 memset(buf2 + 8, 0, 8);
325 memcpy(buf2 + 14, buf, 2);
344 memcpy(buf2 + 8, buf, 3);
347 memcpy(buf2 + 13, buf + 3, 3);
365 memcpy(buf2 + 8, buf, 8);
382 memset(buf2 + 8, 0, 8);
384 memcpy(buf2 + 14, buf, 2);
414 if (ipv6Addr.
IsAny())
431 memset(buf2, 0x00,
sizeof(buf2));
434 memcpy(buf2 + 14, buf, 2);
452 memset(buf2, 0x00,
sizeof(buf2));
455 memcpy(buf2 + 8, buf, 3);
458 memcpy(buf2 + 13, buf + 3, 3);
475 memset(buf2, 0x00,
sizeof(buf2));
478 memcpy(buf2 + 8, buf, 8);
495 memset(buf2, 0x00,
sizeof(buf2));
498 memcpy(buf2 + 14, buf, 2);
516 memset(buf, 0x00,
sizeof(buf));
534 char str[INET6_ADDRSTRLEN];
536 if (inet_ntop(AF_INET6,
m_address, str, INET6_ADDRSTRLEN))
547 return (*
this == localhost);
568 static uint8_t v4MappedPrefix[12] =
569 {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0xff};
570 return memcmp(
m_address, v4MappedPrefix,
sizeof(v4MappedPrefix)) == 0;
586 for (i = 0; i < 16; i++)
588 addr[i] = addr[i] & pref[i];
599 static Ipv6Address documentation(
"ff02::1:ff00:0");
610 return (*
this == allNodesI || *
this == allNodesL || *
this == allNodesR);
621 return (*
this == allroutersI || *
this == allroutersL || *
this == allroutersR ||
622 *
this == allroutersS);
630 return (*
this == any);
649 return masked == reference;
656 return address.CheckCompatible(
GetType(), 16);
744 static Ipv6Address ones(
"ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff");
796 if (inet_pton(AF_INET6, prefix,
m_prefix) <= 0)
798 NS_ABORT_MSG(
"Error, can not build an IPv6 prefix from an invalid string: " << prefix);
813 if (inet_pton(AF_INET6, prefix,
m_prefix) <= 0)
815 NS_ABORT_MSG(
"Error, can not build an IPv6 prefix from an invalid string: " << prefix);
819 "Ipv6Prefix: address and prefix are not compatible: " <<
Ipv6Address(prefix)
820 <<
"/" << +prefixLength);
832 "Ipv6Prefix: address and prefix are not compatible: " <<
Ipv6Address(prefix)
833 <<
"/" << +prefixLength);
842 unsigned int mod = 0;
867 for (i = nb; i < 16; i++)
904 for (i = 0; i < 16; i++)
956 uint8_t prefixBytes[16];
960 return convertedPrefix;
982 uint8_t prefixLength = 0;
985 for (
int8_t i = 15; i >= 0 && !stop; i--)
989 for (uint8_t j = 0; j < 8 && !stop; j++)
1003 return 128 - prefixLength;
cairo_uint64_t x
_cairo_uint_96by64_32x64_divrem:
a polymophic address class
static uint8_t Register(const std::string &kind, uint8_t length)
Allocate a new type id for a new type of address.
Ipv4 addresses are stored in host order in this class.
void Serialize(uint8_t buf[4]) const
Serialize this address to a 4-byte buffer.
static Ipv4Address Deserialize(const uint8_t buf[4])
size_t operator()(const Ipv6Address &x) const
Returns the hash of an IPv6 address.
Describes an IPv6 address.
static uint8_t GetType()
Return the Type of address.
bool IsLinkLocal() const
If the IPv6 address is a link-local address (fe80::/64).
bool HasPrefix(const Ipv6Prefix &prefix) const
Compares an address and a prefix.
bool IsSolicitedMulticast() const
If the IPv6 address is a Solicited multicast address.
static Ipv6Address GetAllNodesMulticast()
Get the "all nodes multicast" address.
void Print(std::ostream &os) const
Print this address to the given output stream.
static Ipv6Address MakeSolicitedAddress(Ipv6Address addr)
Make the solicited IPv6 address.
static Ipv6Address GetAny()
Get the "any" (::) Ipv6Address.
bool IsDocumentation() const
If the IPv6 address is a documentation address (2001:DB8::/32).
static Ipv6Address GetAllHostsMulticast()
Get the "all hosts multicast" address.
bool IsAllNodesMulticast() const
If the IPv6 address is "all nodes multicast" (ff02::1/8).
static bool CheckCompatible(const std::string &addressStr)
Checks if the string contains an Ipv6Address.
bool IsLinkLocalMulticast() const
If the IPv6 address is link-local multicast (ff02::/16).
static Ipv6Address Deserialize(const uint8_t buf[16])
Deserialize this address.
static Ipv6Address GetZero()
Get the 0 (::) Ipv6Address.
static Ipv6Address MakeAutoconfiguredAddress(Address addr, Ipv6Address prefix)
Make the autoconfigured IPv6 address from a Mac address.
~Ipv6Address()
Destructor.
bool IsMulticast() const
If the IPv6 address is multicast (ff00::/8).
void GetBytes(uint8_t buf[16]) const
Get the bytes corresponding to the address.
bool IsIpv4MappedAddress() const
If the address is an IPv4-mapped address.
void Set(const char *address)
Sets an Ipv6Address by parsing the input C-string.
void Serialize(uint8_t buf[16]) const
Serialize this address to a 16-byte buffer.
Ipv6Address()
Default constructor.
Address ConvertTo() const
convert the IPv6Address object to an Address object.
bool IsAny() const
If the IPv6 address is the "Any" address.
static Ipv6Address GetAllRoutersMulticast()
Get the "all routers multicast" address.
bool IsLocalhost() const
If the IPv6 address is localhost (::1).
uint8_t m_address[16]
The address representation on 128 bits (16 bytes).
static Ipv6Address ConvertFrom(const Address &address)
Convert the Address object into an Ipv6Address ones.
bool IsInitialized() const
static Ipv6Address GetOnes()
Get the "all-1" IPv6 address (ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff).
static Ipv6Address MakeAutoconfiguredLinkLocalAddress(Address mac)
Make the autoconfigured link-local IPv6 address from a Mac address.
Ipv4Address GetIpv4MappedAddress() const
Return the Ipv4 address.
static bool IsMatchingType(const Address &address)
If the Address matches the type.
static Ipv6Address MakeIpv4MappedAddress(Ipv4Address addr)
Make the Ipv4-mapped IPv6 address.
static Ipv6Address GetLoopback()
Get the loopback address.
Ipv6Address CombinePrefix(const Ipv6Prefix &prefix) const
Combine this address with a prefix.
bool IsAllRoutersMulticast() const
If the IPv6 address is "all routers multicast" (ff02::2/8).
Describes an IPv6 prefix.
uint8_t m_prefixLength
The prefix length.
static Ipv6Prefix GetLoopback()
Get the loopback prefix ( /128).
uint8_t m_prefix[16]
The prefix representation.
void Print(std::ostream &os) const
Print this address to the given output stream.
uint8_t GetPrefixLength() const
Get prefix length.
Ipv6Address ConvertToIpv6Address() const
Convert the Prefix into an IPv6 Address.
static Ipv6Prefix GetZero()
Get the zero prefix ( /0).
bool IsMatch(Ipv6Address a, Ipv6Address b) const
Check whether two addresses have the same bits in the prefix portion of their addresses.
static Ipv6Prefix GetOnes()
Get the "all-1" IPv6 mask (ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff).
void SetPrefixLength(uint8_t prefixLength)
Set prefix length.
Ipv6Prefix()
Default constructor.
uint8_t GetMinimumPrefixLength() const
Get the minimum prefix length, i.e., 128 - the length of the largest sequence trailing zeroes.
void GetBytes(uint8_t buf[16]) const
Get the bytes corresponding to the prefix.
This class can contain 16 bit addresses.
static bool IsMatchingType(const Address &address)
static Mac16Address ConvertFrom(const Address &address)
void CopyTo(uint8_t buffer[2]) const
static bool IsMatchingType(const Address &address)
static Mac48Address ConvertFrom(const Address &address)
void CopyTo(uint8_t buffer[6]) const
static bool IsMatchingType(const Address &address)
void CopyTo(uint8_t buffer[8]) const
static Mac64Address ConvertFrom(const Address &address)
A class used for addressing MAC8 MAC's.
static Mac8Address ConvertFrom(const Address &address)
Convert a generic address to a Mac8Address.
static bool IsMatchingType(const Address &address)
Check that a generic Address is compatible with Mac8Address.
void CopyTo(uint8_t *pBuffer) const
Writes address to buffer parameter.
#define NS_ASSERT(condition)
At runtime, in debugging builds, if this condition is not true, the program prints the source file,...
#define NS_ASSERT_MSG(condition, message)
At runtime, in debugging builds, if this condition is not true, the program prints the message to out...
#define ATTRIBUTE_HELPER_CPP(type)
Define the attribute value, accessor and checkers for class type.
#define NS_ABORT_MSG(msg)
Unconditional abnormal program termination with a message.
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
#define NS_LOG_FUNCTION_NOARGS()
Output the name of the function.
#define NS_LOG_FUNCTION(parameters)
If log level LOG_FUNCTION is enabled, this macro will output all input parameters separated by ",...
#define NS_LOG_WARN(msg)
Use NS_LOG to output a message of level LOG_WARN.
Every class exported by the ns3 library is enclosed in the ns3 namespace.
std::ostream & operator<<(std::ostream &os, const Angles &a)
std::istream & operator>>(std::istream &is, Angles &a)
void mixHashKey(uint32_t &a, uint32_t &b, uint32_t &c)
Mix hash keys in-place for lookuphash.
static uint32_t lookuphash(unsigned char *k, uint32_t length, uint32_t level)
Get a hash key.