INET Framework for OMNeT++/OMNEST
inet::Ipv6Address Class Reference

Stores a 128-bit Ipv6 address in an efficient way. More...

#include <Ipv6Address.h>

Public Types

enum  Scope {
  UNSPECIFIED, LOOPBACK, MULTICAST, LINK,
  SITE, GLOBAL
}
 Ipv6 address scope (RFC 3513) More...
 

Protected Member Functions

bool doTryParse (const char *&addr)
 

Private Attributes

uint32_t d [4]
 

Predefined addresses

static const Ipv6Address UNSPECIFIED_ADDRESS
 The unspecified address. More...
 
static const Ipv6Address LOOPBACK_ADDRESS
 The loopback address. More...
 
static const Ipv6Address ALL_NODES_1
 All-nodes multicast address, scope 1 (interface-local) More...
 
static const Ipv6Address ALL_NODES_2
 All-nodes multicast address, scope 2 (link-local) More...
 
static const Ipv6Address ALL_ROUTERS_1
 All-routers multicast address, scope 1 (interface-local) More...
 
static const Ipv6Address ALL_ROUTERS_2
 All-routers multicast address, scope 2 (link-local) More...
 
static const Ipv6Address ALL_ROUTERS_5
 All-routers multicast address, scope 5 (site-local) More...
 
static const Ipv6Address SOLICITED_NODE_PREFIX
 The solicited-node multicast address prefix (prefix length = 104) More...
 
static const Ipv6Address LINKLOCAL_PREFIX
 The link-local prefix (fe80::) More...
 
static const Ipv6Address LL_MANET_ROUTERS
 Link-local MANET routers multicast address. More...
 
static const Ipv6Address ALL_OSPF_ROUTERS_MCAST
 OSPF multicast address for listening. More...
 
static const Ipv6Address ALL_OSPF_DESIGNATED_ROUTERS_MCAST
 OSPF designated routers. More...
 
 Ipv6Address ()
 Constructor. More...
 
 Ipv6Address (uint64_t hi, uint64_t lo)
 Constructs an Ipv6 address from two 64-bit integers. More...
 
 Ipv6Address (uint32_t segment0, uint32_t segment1, uint32_t segment2, uint32_t segment3)
 Constructs an Ipv6 address from four 32-bit integers. More...
 
 Ipv6Address (const char *addr)
 Constructor. More...
 
bool operator< (const Ipv6Address &addr) const
 
bool operator> (const Ipv6Address &addr) const
 
bool operator== (const Ipv6Address &addr) const
 
bool operator!= (const Ipv6Address &addr) const
 
int compare (const Ipv6Address &addr) const
 Returns -1, 0 or 1. More...
 
bool tryParse (const char *addr)
 Tries parsing an Ipv6 address string into the object. More...
 
bool tryParseAddrWithPrefix (const char *addr, int &prefixLen)
 Expects a string in the "<address>/<prefixlength>" syntax, parses the address into the object (see tryParse(), and returns the prefix length (a 0..128 integer) in the second argument. More...
 
void set (const char *addr)
 Sets the Ipv6 address. More...
 
std::string str () const
 Returns the textual representation of the address in the standard notation. More...
 
void set (uint32_t d0, uint32_t d1, uint32_t d2, uint32_t d3)
 Sets the Ipv6 address from four 32-bit integers. More...
 
uint32_t * words ()
 Returns a pointer to the internal binary representation of the address: four 32-bit words, most significant word first. More...
 
const uint32_t * words () const
 Returns a pointer to the internal binary representation of the address: four 32-bit words, most significant word first. More...
 
Scope getScope () const
 Get the Ipv6 address scope. More...
 
Ipv6Address getPrefix (int prefixLength) const
 Get the Ipv6 first prefixLength bits of the address, with the rest set to zero. More...
 
Ipv6Address getSuffix (int prefixLength) const
 Get the last 128-prefixLength bits of the address, with the first bits set to zero. More...
 
const Ipv6AddresssetPrefix (const Ipv6Address &fromAddr, int prefixLength)
 Overwrites the first prefixLength bits of the address with the bits from the address passed as argument. More...
 
const Ipv6AddresssetSuffix (const Ipv6Address &fromAddr, int prefixLength)
 Overwrites the last 128-prefixLength bits of the address with the bits from address passed as argument. More...
 
Ipv6Address formSolicitedNodeMulticastAddress () const
 Returns the solicited-node multicast address for this address. More...
 
bool isSolicitedNodeMulticastAddress () const
 
Ipv6Address formSubnetRouterAnycastAddress (int prefixLength) const
 Returns the subnet-router anycast address for this address by setting its suffix (the last 128-prefixLength bits) to all-zeroes. More...
 
bool matches (const Ipv6Address &prefix, int prefixLength) const
 Returns true if the address matches the given prefix. More...
 
bool isUnspecified () const
 Check if the Ipv6 Address is undefined. More...
 
bool isMulticast () const
 Utility function based on getScope() More...
 
bool isUnicast () const
 Utility function based on getScope() More...
 
bool isLoopback () const
 Utility function based on getScope() More...
 
bool isLinkLocal () const
 Utility function based on getScope() More...
 
bool isSiteLocal () const
 Utility function based on getScope() More...
 
bool isGlobal () const
 Utility function based on getScope() More...
 
int getMulticastScope () const
 Get the 4-bit scope field of an Ipv6 multicast address. More...
 
MacAddress mapToMulticastMacAddress () const
 
static const char * scopeName (Scope s)
 Return the string representation of the given scope. More...
 
static void constructMask (int prefixLength, uint32_t *mask)
 Construct a 128-bit mask based on the prefix length. More...
 
static Ipv6Address constructMask (int prefixLength)
 
static Ipv6Address formLinkLocalAddress (const InterfaceToken &ident)
 Forms a link-local address using the given interface identifier. More...
 

Detailed Description

Stores a 128-bit Ipv6 address in an efficient way.

Complies to RFC 3513, "Internet Protocol Version 6 (Ipv6) Addressing Architecture."

Member Enumeration Documentation

◆ Scope

Ipv6 address scope (RFC 3513)

Enumerator
UNSPECIFIED 
LOOPBACK 
MULTICAST 
LINK 
SITE 
GLOBAL 
42  {
44  LOOPBACK,
45  MULTICAST,
46  LINK,
47  SITE,
48  GLOBAL
49  };

Constructor & Destructor Documentation

◆ Ipv6Address() [1/4]

inet::Ipv6Address::Ipv6Address ( )
inline

Constructor.

Initializes the Ipv6 address to ::0 (all-zeroes).

93 { d[0] = d[1] = d[2] = d[3] = 0; }

Referenced by getPrefix(), and getSuffix().

◆ Ipv6Address() [2/4]

inet::Ipv6Address::Ipv6Address ( uint64_t  hi,
uint64_t  lo 
)
inline

Constructs an Ipv6 address from two 64-bit integers.

99  {
100  uint32_t mask = 0xFFFFFFFF;
101  d[0] = (hi >> 32) & mask;
102  d[1] = hi & mask;
103  d[2] = (lo >> 32) & mask;
104  d[3] = lo & mask;
105  }

◆ Ipv6Address() [3/4]

inet::Ipv6Address::Ipv6Address ( uint32_t  segment0,
uint32_t  segment1,
uint32_t  segment2,
uint32_t  segment3 
)
inline

Constructs an Ipv6 address from four 32-bit integers.

The most significant word should be passed in the first argument.

112  {
113  d[0] = segment0;
114  d[1] = segment1;
115  d[2] = segment2;
116  d[3] = segment3;
117  }

◆ Ipv6Address() [4/4]

inet::Ipv6Address::Ipv6Address ( const char *  addr)
inlineexplicit

Constructor.

Sets the address from the given text representation. See documentation of tryParse() for supported syntax.

123 { set(addr); }

Member Function Documentation

◆ compare()

int inet::Ipv6Address::compare ( const Ipv6Address addr) const
inline

Returns -1, 0 or 1.

139  {
140  return d[0] < addr.d[0] ? -1 : d[0] > addr.d[0] ? 1 :
141  d[1] < addr.d[1] ? -1 : d[1] > addr.d[1] ? 1 :
142  d[2] < addr.d[2] ? -1 : d[2] > addr.d[2] ? 1 :
143  d[3] < addr.d[3] ? -1 : d[3] > addr.d[3] ? 1 : 0;
144  }

◆ constructMask() [1/2]

Ipv6Address inet::Ipv6Address::constructMask ( int  prefixLength)
static
293 {
294  Ipv6Address ret;
295  constructMask(prefixLength, ret.d);
296  return ret;
297 }

◆ constructMask() [2/2]

void inet::Ipv6Address::constructMask ( int  prefixLength,
uint32_t *  mask 
)
static

Construct a 128-bit mask based on the prefix length.

Mask should point to an array of four 32-bit words, most significant word first.

255 {
256  ASSERT(prefixLength >= 0 && prefixLength <= 128 && mask != nullptr);
257 
258  // create a mask based on the prefix length.
259  if (prefixLength == 0) {
260  mask[0] = mask[1] = mask[2] = mask[3] = 0x00000000;
261  }
262  else if (prefixLength <= 32) {
263  int num_of_shifts = 32 - prefixLength;
264  mask[0] = 0xFFFFFFFFU << num_of_shifts;
265  mask[1] = 0x00000000;
266  mask[2] = 0x00000000;
267  mask[3] = 0x00000000;
268  }
269  else if (prefixLength <= 64) {
270  int num_of_shifts = 64 - prefixLength;
271  mask[0] = 0xFFFFFFFFU;
272  mask[1] = 0xFFFFFFFFU << num_of_shifts;
273  mask[2] = 0x00000000;
274  mask[3] = 0x00000000;
275  }
276  else if (prefixLength <= 96) {
277  int num_of_shifts = 96 - prefixLength;
278  mask[0] = 0xFFFFFFFFU;
279  mask[1] = 0xFFFFFFFFU;
280  mask[2] = 0xFFFFFFFFU << num_of_shifts;
281  mask[3] = 0x00000000;
282  }
283  else {
284  int num_of_shifts = 128 - prefixLength;
285  mask[0] = 0xFFFFFFFFU;
286  mask[1] = 0xFFFFFFFFU;
287  mask[2] = 0xFFFFFFFFU;
288  mask[3] = 0xFFFFFFFFU << num_of_shifts;
289  }
290 }

Referenced by constructMask(), getPrefix(), getSuffix(), matches(), setPrefix(), and setSuffix().

◆ doTryParse()

bool inet::Ipv6Address::doTryParse ( const char *&  addr)
protected
65 {
66  if (!strcmp(addr, "<unspec>")) {
67  addr += 8;
68  d[0] = d[1] = d[2] = d[3] = 0;
69  return true;
70  }
71 
72  // parse and store 16-bit units
73  uint16_t groups[8];
74  int numGroups = parseGroups(addr, groups);
75 
76  // if address string contains "::", parse and store second half too
77  if (*addr == ':' && *(addr + 1) == ':') {
78  addr += 2;
79  uint16_t suffixGroups[8];
80  int numSuffixGroups = parseGroups(addr, suffixGroups);
81 
82  // merge suffixGroups[] into groups[]
83  if (numGroups + numSuffixGroups > 8)
84  return false; // too many
85  for (int i = numGroups; i < 8; i++) {
86  int j = i - 8 + numSuffixGroups;
87  groups[i] = j < 0 ? 0 : suffixGroups[j];
88  }
89  numGroups = 8;
90  }
91 
92  if (numGroups != 8)
93  return false; // too few
94 
95  // copy groups to d[]
96  for (unsigned int i = 0; i < 4; i++)
97  d[i] = ((uint32_t)(groups[2 * i]) << 16) + groups[2 * i + 1];
98 
99  return true;
100 }

Referenced by tryParse(), and tryParseAddrWithPrefix().

◆ formLinkLocalAddress()

Ipv6Address inet::Ipv6Address::formLinkLocalAddress ( const InterfaceToken ident)
static

Forms a link-local address using the given interface identifier.

349 {
350  Ipv6Address suffix(0, 0, ident.normal(), ident.low());
352  linkLocalAddr.setSuffix(suffix, 128 - ident.length());
353  return linkLocalAddr;
354 }

Referenced by inet::Ipv6NeighbourDiscovery::assignLinkLocalAddress(), inet::Ipv6RoutingTable::assignRequiredNodeAddresses(), and inet::Ipv6FlatNetworkConfigurator::configureAdvPrefixes().

◆ formSolicitedNodeMulticastAddress()

Ipv6Address inet::Ipv6Address::formSolicitedNodeMulticastAddress ( ) const
inline

Returns the solicited-node multicast address for this address.

This function replaces the prefix with FF02:0:0:0:0:1:FF00:0/104.

248  {
249  return Ipv6Address(*this).setPrefix(SOLICITED_NODE_PREFIX, 104);
250  };

Referenced by inet::Ipv6NeighbourDiscovery::initiateAddressResolution(), inet::Ipv6NeighbourDiscovery::initiateDad(), inet::Ipv6NeighbourDiscovery::processArTimeout(), and inet::Ipv6NeighbourDiscovery::processDadTimeout().

◆ formSubnetRouterAnycastAddress()

Ipv6Address inet::Ipv6Address::formSubnetRouterAnycastAddress ( int  prefixLength) const
inline

Returns the subnet-router anycast address for this address by setting its suffix (the last 128-prefixLength bits) to all-zeroes.

See section 2.6.1 of RFC 3513.

263  {
264  return Ipv6Address(*this).setSuffix(UNSPECIFIED_ADDRESS, prefixLength);
265  }

◆ getMulticastScope()

int inet::Ipv6Address::getMulticastScope ( ) const

Get the 4-bit scope field of an Ipv6 multicast address.

369 {
370  if ((d[0] & MULTICAST_MASK) != MULTICAST_PREFIX)
371  throw cRuntimeError("Ipv6Address::getMulticastScope(): %s is not a multicast address", str().c_str());
372  return (d[0] >> 16) & 0x0F;
373 }

◆ getPrefix()

Ipv6Address inet::Ipv6Address::getPrefix ( int  prefixLength) const

◆ getScope()

Ipv6Address::Scope inet::Ipv6Address::getScope ( ) const

Get the Ipv6 address scope.

198 {
199  // Mask the given Ipv6 address with the different mask types
200  // to get only the Ipv6 address scope. Compare the masked
201  // address with the different prefixes.
202 
203  if ((d[0] & LINK_LOCAL_MASK) == LINK_LOCAL_PREFIX) {
204  return LINK;
205  }
206  else if ((d[0] & SITE_LOCAL_MASK) == SITE_LOCAL_PREFIX) {
207  return SITE;
208  }
209  else if ((d[0] & MULTICAST_MASK) == MULTICAST_PREFIX) {
210  return MULTICAST;
211  }
212  else if (d[0] == 0x00000000 && d[1] == 0x00000000 && d[2] == 0x00000000) {
213  if (d[3] == 0x00000000) {
214  return UNSPECIFIED;
215  }
216  else if (d[3] == 0x00000001) {
217  return LOOPBACK;
218  }
219  else {
220  return GLOBAL; // actually an "Ipv4-compatible Ipv6 address"
221  }
222  }
223  else {
224  return GLOBAL;
225  }
226 }

Referenced by inet::Ipv6InterfaceData::addrLess(), inet::eigrp::EigrpIpv6Pdm::checkNeighborshipRules(), inet::sctp::SctpAssociation::getAddressLevel(), inet::L3AddressResolver::getIpv6AddressFrom(), inet::eigrp::EigrpDeviceConfigurator::loadEigrpInterfaces6Config(), and inet::xMIPv6::validateType2RH().

◆ getSuffix()

Ipv6Address inet::Ipv6Address::getSuffix ( int  prefixLength) const

Get the last 128-prefixLength bits of the address, with the first bits set to zero.

310 {
311  // First we construct a mask.
312  uint32_t mask[4];
313  constructMask(prefixLength, mask);
314 
315  // Now we mask each Ipv6 address segment, inverse it
316  // and create a new Ipv6 Address!
317  return Ipv6Address(d[0] & ~mask[0], d[1] & ~mask[1], d[2] & ~mask[2], d[3] & ~mask[3]);
318 }

◆ isGlobal()

◆ isLinkLocal()

◆ isLoopback()

bool inet::Ipv6Address::isLoopback ( ) const
inline

Utility function based on getScope()

289 { return getScope() == LOOPBACK; }

◆ isMulticast()

◆ isSiteLocal()

bool inet::Ipv6Address::isSiteLocal ( ) const
inline

Utility function based on getScope()

295 { return getScope() == SITE; }

◆ isSolicitedNodeMulticastAddress()

bool inet::Ipv6Address::isSolicitedNodeMulticastAddress ( ) const
inline
253  {
254  return matches(SOLICITED_NODE_PREFIX, 104);
255  }

◆ isUnicast()

◆ isUnspecified()

◆ mapToMulticastMacAddress()

MacAddress inet::Ipv6Address::mapToMulticastMacAddress ( ) const
376 {
377  ASSERT(isMulticast());
378 
379  MacAddress macAddress;
380  macAddress.setAddressByte(0, 0x33);
381  macAddress.setAddressByte(1, 0x33);
382  macAddress.setAddressByte(2, (d[3] >> 24) & 0xFF);
383  macAddress.setAddressByte(3, (d[3] >> 16) & 0xFF);
384  macAddress.setAddressByte(4, (d[3] >> 8) & 0xFF);
385  macAddress.setAddressByte(5, (d[3] >> 0) & 0xFF);
386  return macAddress;
387 }

Referenced by inet::L3Address::mapToMulticastMacAddress().

◆ matches()

bool inet::Ipv6Address::matches ( const Ipv6Address prefix,
int  prefixLength 
) const

Returns true if the address matches the given prefix.

357 {
358  // first we construct a mask.
359  uint32_t mask[4];
360  constructMask(prefixLength, mask);
361 
362  // xor the bits of the 2 addresses, and the result should be zero wherever
363  // the mask has 1 bits
364  return (((d[0] ^ prefix.d[0]) & mask[0]) | ((d[1] ^ prefix.d[1]) & mask[1])
365  | ((d[2] ^ prefix.d[2]) & mask[2]) | ((d[3] ^ prefix.d[3]) & mask[3])) == 0;
366 }

Referenced by inet::Ipv6NeighbourDiscovery::createAndSendNsPacket(), inet::Ipv6RoutingTable::doLongestPrefixMatch(), inet::Ipv6RoutingTable::isLocalAddress(), inet::InterfaceTable::isNeighborAddress(), inet::Ipv6RoutingTable::isPrefixPresent(), inet::L3Address::matches(), inet::Ipv6NeighbourDiscovery::processRaPrefixInfoForAddrAutoConf(), and inet::Ipv6NeighbourDiscovery::validateNsPacket().

◆ operator!=()

bool inet::Ipv6Address::operator!= ( const Ipv6Address addr) const
inline
133 { return !operator==(addr); }

◆ operator<()

bool inet::Ipv6Address::operator< ( const Ipv6Address addr) const
inline
125 { return compare(addr) < 0; }

◆ operator==()

bool inet::Ipv6Address::operator== ( const Ipv6Address addr) const
inline
129  {
130  return d[3] == addr.d[3] && d[2] == addr.d[2] && d[1] == addr.d[1] && d[0] == addr.d[0]; // d[3] differs most often, compare that first
131  }

◆ operator>()

bool inet::Ipv6Address::operator> ( const Ipv6Address addr) const
inline
126 { return compare(addr) > 0; }

◆ scopeName()

const char * inet::Ipv6Address::scopeName ( Scope  s)
static

Return the string representation of the given scope.

229 {
230  switch (scope) {
231  case UNSPECIFIED:
232  return "unspec";
233 
234  case LOOPBACK:
235  return "loopback";
236 
237  case MULTICAST:
238  return "mcast";
239 
240  case LINK:
241  return "link";
242 
243  case SITE:
244  return "site";
245 
246  case GLOBAL:
247  return "global";
248 
249  default:
250  return "???";
251  }
252 }

Referenced by inet::Ipv6InterfaceData::str().

◆ set() [1/2]

void inet::Ipv6Address::set ( const char *  addr)

Sets the Ipv6 address.

Given a string.

136 {
137  if (!tryParse(addr))
138  throw cRuntimeError("Ipv6Address: cannot interpret address string `%s'", addr);
139 }

Referenced by inet::Ipv6RoutingTable::configureTunnelFromXml(), and inet::eigrp::EigrpIpv6Pdm::getDestIpAddress().

◆ set() [2/2]

void inet::Ipv6Address::set ( uint32_t  d0,
uint32_t  d1,
uint32_t  d2,
uint32_t  d3 
)
inline

Sets the Ipv6 address from four 32-bit integers.

The most significant word should be passed in the first argument.

181  {
182  d[0] = d0;
183  d[1] = d1;
184  d[2] = d2;
185  d[3] = d3;
186  }

◆ setPrefix()

const Ipv6Address & inet::Ipv6Address::setPrefix ( const Ipv6Address fromAddr,
int  prefixLength 
)

Overwrites the first prefixLength bits of the address with the bits from the address passed as argument.

Return value is the object itself.

321 {
322  // first we construct a mask.
323  uint32_t mask[4];
324  constructMask(prefixLength, mask);
325 
326  // combine the addresses
327  d[0] = (d[0] & ~mask[0]) | (fromAddr.d[0] & mask[0]);
328  d[1] = (d[1] & ~mask[1]) | (fromAddr.d[1] & mask[1]);
329  d[2] = (d[2] & ~mask[2]) | (fromAddr.d[2] & mask[2]);
330  d[3] = (d[3] & ~mask[3]) | (fromAddr.d[3] & mask[3]);
331  return *this;
332 }

Referenced by formSolicitedNodeMulticastAddress(), and inet::Ipv6NeighbourDiscovery::processRaPrefixInfoForAddrAutoConf().

◆ setSuffix()

const Ipv6Address & inet::Ipv6Address::setSuffix ( const Ipv6Address fromAddr,
int  prefixLength 
)

Overwrites the last 128-prefixLength bits of the address with the bits from address passed as argument.

Return value is the object itself.

335 {
336  // first we construct a mask.
337  uint32_t mask[4];
338  constructMask(prefixLength, mask);
339 
340  // combine the addresses
341  d[0] = (d[0] & mask[0]) | (fromAddr.d[0] & ~mask[0]);
342  d[1] = (d[1] & mask[1]) | (fromAddr.d[1] & ~mask[1]);
343  d[2] = (d[2] & mask[2]) | (fromAddr.d[2] & ~mask[2]);
344  d[3] = (d[3] & mask[3]) | (fromAddr.d[3] & ~mask[3]);
345  return *this;
346 }

Referenced by formLinkLocalAddress(), and formSubnetRouterAnycastAddress().

◆ str()

std::string inet::Ipv6Address::str ( ) const

Returns the textual representation of the address in the standard notation.

169 {
170  if (isUnspecified())
171  return std::string("<unspec>");
172 
173  // convert to 16-bit grops
174  uint16_t groups[8] = {
175  uint16_t(d[0] >> 16), uint16_t(d[0] & 0xffff), uint16_t(d[1] >> 16), uint16_t(d[1] & 0xffff),
176  uint16_t(d[2] >> 16), uint16_t(d[2] & 0xffff), uint16_t(d[3] >> 16), uint16_t(d[3] & 0xffff)
177  };
178 
179  // find longest sequence of zeros in groups[]
180  int start, end;
181  findGap(groups, start, end);
182  if (start == 0 && end == 8)
183  return "::0"; // the unspecified address is a special case
184 
185  // print groups, replacing gap with "::"
186  std::stringstream os;
187  os << std::hex;
188  for (int i = 0; i < start; i++)
189  os << (i == 0 ? "" : ":") << groups[i];
190  if (start != end)
191  os << "::";
192  for (int j = end; j < 8; j++)
193  os << (j == end ? "" : ":") << groups[j];
194  return os.str();
195 }

Referenced by inet::Ipv6InterfaceData::addMulticastListener(), inet::PacketFilter::DynamicExpressionResolver::callMethod(), inet::ospfv3::Ospfv3Area::detailedInfo(), inet::Ipv6RoutingTable::doLongestPrefixMatch(), inet::Ipv6RoutingTable::getInterfaceByAddress(), getMulticastScope(), inet::Ipv6::handleMessageFromHL(), inet::Ipv6RoutingTable::isLocalAddress(), inet::Ipv6InterfaceData::joinMulticastGroup(), inet::Ipv6InterfaceData::leaveMulticastGroup(), inet::Ipv6RoutingTable::lookupDestCache(), inet::Ipv6NeighbourDiscovery::reachabilityConfirmed(), inet::Ipv6NeighbourDiscovery::resolveNeighbour(), inet::L3Address::str(), inet::ospfv3::Ipv6AddressRange::str(), and inet::InterfaceTable::updateLinkDisplayString().

◆ tryParse()

bool inet::Ipv6Address::tryParse ( const char *  addr)

Tries parsing an Ipv6 address string into the object.

Returns true if the string contains a well-formed Ipv6 address, and false otherwise. All RFC 3513 notations are accepted (e.g. FEDC:BA98:7654:3210:FEDC:BA98:7654:3210, FF01::101, ::1), plus also "<unspec>" as a synonym for the unspecified address (all-zeroes).

103 {
104  if (!addr)
105  return false;
106  if (!doTryParse(addr))
107  return false;
108  if (*addr != 0)
109  return false; // illegal trailing character
110  return true;
111 }

Referenced by set(), inet::L3Address::tryParse(), and inet::L3AddressResolver::tryParse().

◆ tryParseAddrWithPrefix()

bool inet::Ipv6Address::tryParseAddrWithPrefix ( const char *  addr,
int &  prefixLen 
)

Expects a string in the "<address>/<prefixlength>" syntax, parses the address into the object (see tryParse(), and returns the prefix length (a 0..128 integer) in the second argument.

The return value is true if the operation was successful, and false if it was not (e.g. no slash in the input string, invalid address syntax, prefix length is out of range, etc.).

114 {
115  if (!addr)
116  return false;
117  if (!doTryParse(addr))
118  return false;
119  if (*addr != '/')
120  return false; // no '/' after address
121  addr++;
122 
123  // parse prefix
124  char *e;
125  prefixLen = strtoul(addr, &e, 10);
126  if (addr == e)
127  return false; // no number after '/'
128  if (*e != 0)
129  return false; // garbage after number
130  if (prefixLen < 0 || prefixLen > 128)
131  return false; // wrong len value
132  return true;
133 }

Referenced by inet::Ipv6RoutingTable::configureInterfaceFromXml(), inet::eigrp::EigrpDeviceConfigurator::loadEigrpInterfaces6Config(), and inet::ospfv3::Ospfv3Process::parseConfig().

◆ words() [1/2]

uint32_t* inet::Ipv6Address::words ( )
inline

Returns a pointer to the internal binary representation of the address: four 32-bit words, most significant word first.

192 { return d; }

Referenced by inet::doPacking(), inet::doUnpacking(), inet::eigrp::EigrpIpv6Pdm::getDestIpAddress(), inet::getNetmaskLength(), inet::getPrefix(), inet::maskedAddrAreEqual(), inet::sctp::SctpHeaderSerializer::serialize(), inet::L3Address::set(), and inet::MemoryOutputStream::writeIpv6Address().

◆ words() [2/2]

const uint32_t* inet::Ipv6Address::words ( ) const
inline

Returns a pointer to the internal binary representation of the address: four 32-bit words, most significant word first.

198 { return d; }

Member Data Documentation

◆ ALL_NODES_1

const Ipv6Address inet::Ipv6Address::ALL_NODES_1
static

◆ ALL_NODES_2

◆ ALL_OSPF_DESIGNATED_ROUTERS_MCAST

◆ ALL_OSPF_ROUTERS_MCAST

◆ ALL_ROUTERS_1

const Ipv6Address inet::Ipv6Address::ALL_ROUTERS_1
static

All-routers multicast address, scope 1 (interface-local)

Referenced by inet::Ipv6RoutingTable::isLocalAddress().

◆ ALL_ROUTERS_2

const Ipv6Address inet::Ipv6Address::ALL_ROUTERS_2
static

◆ ALL_ROUTERS_5

const Ipv6Address inet::Ipv6Address::ALL_ROUTERS_5
static

All-routers multicast address, scope 5 (site-local)

Referenced by inet::Ipv6RoutingTable::isLocalAddress().

◆ d

◆ LINKLOCAL_PREFIX

const Ipv6Address inet::Ipv6Address::LINKLOCAL_PREFIX
static

◆ LL_MANET_ROUTERS

const Ipv6Address inet::Ipv6Address::LL_MANET_ROUTERS
static

Link-local MANET routers multicast address.

Referenced by inet::Ipv6AddressType::getLinkLocalManetRoutersMulticastAddress().

◆ LOOPBACK_ADDRESS

const Ipv6Address inet::Ipv6Address::LOOPBACK_ADDRESS
static

The loopback address.

Referenced by inet::Icmpv6::sendErrorMessage().

◆ SOLICITED_NODE_PREFIX

const Ipv6Address inet::Ipv6Address::SOLICITED_NODE_PREFIX
static

The solicited-node multicast address prefix (prefix length = 104)

Referenced by inet::Ipv6RoutingTable::isLocalAddress(), and inet::Ipv6NeighbourDiscovery::validateNsPacket().

◆ UNSPECIFIED_ADDRESS


The documentation for this class was generated from the following files:
inet::Ipv6Address::UNSPECIFIED
@ UNSPECIFIED
Definition: Ipv6Address.h:43
inet::Ipv6Address::getScope
Scope getScope() const
Get the Ipv6 address scope.
Definition: Ipv6Address.cc:197
inet::Ipv6Address::setSuffix
const Ipv6Address & setSuffix(const Ipv6Address &fromAddr, int prefixLength)
Overwrites the last 128-prefixLength bits of the address with the bits from address passed as argumen...
Definition: Ipv6Address.cc:334
inet::LINK_LOCAL_PREFIX
const uint32_t LINK_LOCAL_PREFIX
Definition: Ipv6Address.cc:15
inet::MULTICAST_PREFIX
const uint32_t MULTICAST_PREFIX
Definition: Ipv6Address.cc:17
inet::Ipv6Address::LINK
@ LINK
Definition: Ipv6Address.h:46
inet::Ipv6Address::LOOPBACK
@ LOOPBACK
Definition: Ipv6Address.h:44
inet::utils::hex
std::string hex(uint16_t l)
Definition: INETUtils.cc:28
inet::Ipv6Address::SITE
@ SITE
Definition: Ipv6Address.h:47
inet::Ipv6Address::doTryParse
bool doTryParse(const char *&addr)
Definition: Ipv6Address.cc:64
inet::units::constants::e
const value< double, units::C > e(1.602176487e-19)
inet::Ipv6Address::set
void set(const char *addr)
Sets the Ipv6 address.
Definition: Ipv6Address.cc:135
inet::Ipv6Address::operator==
bool operator==(const Ipv6Address &addr) const
Definition: Ipv6Address.h:128
inet::Ipv6Address::Ipv6Address
Ipv6Address()
Constructor.
Definition: Ipv6Address.h:93
inet::Ipv6Address::str
std::string str() const
Returns the textual representation of the address in the standard notation.
Definition: Ipv6Address.cc:168
inet::Ipv6Address::MULTICAST
@ MULTICAST
Definition: Ipv6Address.h:45
inet::Ipv6Address::LINKLOCAL_PREFIX
static const Ipv6Address LINKLOCAL_PREFIX
The link-local prefix (fe80::)
Definition: Ipv6Address.h:78
inet::Ipv6Address::UNSPECIFIED_ADDRESS
static const Ipv6Address UNSPECIFIED_ADDRESS
The unspecified address.
Definition: Ipv6Address.h:54
inet::Ipv6Address::isMulticast
bool isMulticast() const
Utility function based on getScope()
Definition: Ipv6Address.h:283
inet::LINK_LOCAL_MASK
const uint32_t LINK_LOCAL_MASK
Definition: Ipv6Address.cc:20
inet::MULTICAST_MASK
const uint32_t MULTICAST_MASK
Definition: Ipv6Address.cc:22
inet::Ipv6Address::tryParse
bool tryParse(const char *addr)
Tries parsing an Ipv6 address string into the object.
Definition: Ipv6Address.cc:102
inet::Ipv6Address::isUnspecified
bool isUnspecified() const
Check if the Ipv6 Address is undefined.
Definition: Ipv6Address.h:280
inet::Ipv6Address::constructMask
static void constructMask(int prefixLength, uint32_t *mask)
Construct a 128-bit mask based on the prefix length.
Definition: Ipv6Address.cc:254
inet::Ipv6Address::d
uint32_t d[4]
Definition: Ipv6Address.h:32
inet::SITE_LOCAL_PREFIX
const uint32_t SITE_LOCAL_PREFIX
Definition: Ipv6Address.cc:16
inet::Ipv6Address::matches
bool matches(const Ipv6Address &prefix, int prefixLength) const
Returns true if the address matches the given prefix.
Definition: Ipv6Address.cc:356
inet::Ipv6Address::GLOBAL
@ GLOBAL
Definition: Ipv6Address.h:48
inet::Ipv6Address::SOLICITED_NODE_PREFIX
static const Ipv6Address SOLICITED_NODE_PREFIX
The solicited-node multicast address prefix (prefix length = 104)
Definition: Ipv6Address.h:75
inet::Ipv6Address::compare
int compare(const Ipv6Address &addr) const
Returns -1, 0 or 1.
Definition: Ipv6Address.h:138
inet::SITE_LOCAL_MASK
const uint32_t SITE_LOCAL_MASK
Definition: Ipv6Address.cc:21