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...
 

Public Member Functions

 IPv6Address ()
 Constructor. More...
 
 IPv6Address (uint64 hi, uint64 lo)
 Constructs an IPv6 address from two 64-bit integers. More...
 
 IPv6Address (uint32 segment0, uint32 segment1, uint32 segment2, uint32 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 d0, uint32 d1, uint32 d2, uint32 d3)
 Sets the IPv6 address from four 32-bit integers. More...
 
uint32words ()
 Returns a pointer to the internal binary representation of the address: four 32-bit words, most significant word first. More...
 
const uint32words () 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...
 

Static Public Member Functions

static const char * scopeName (Scope s)
 Return the string representation of the given scope. More...
 
static void constructMask (int prefixLength, uint32 *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...
 

Static Public Attributes

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...
 

Protected Member Functions

bool doTryParse (const char *&addr)
 

Private Attributes

uint32 d [4]
 

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

IPv6 address scope (RFC 3513)

Enumerator
UNSPECIFIED 
LOOPBACK 
MULTICAST 
LINK 
SITE 
GLOBAL 
54  {
56  LOOPBACK,
57  MULTICAST,
58  LINK,
59  SITE,
60  GLOBAL
61  };
Definition: IPv6Address.h:59
Definition: IPv6Address.h:57
Definition: IPv6Address.h:58
Definition: IPv6Address.h:56
Definition: IPv6Address.h:60
Definition: IPv6Address.h:55

Constructor & Destructor Documentation

inet::IPv6Address::IPv6Address ( )
inline

Constructor.

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

Referenced by getPrefix(), and getSuffix().

99 { d[0] = d[1] = d[2] = d[3] = 0; }
uint32 d[4]
Definition: IPv6Address.h:44
inet::IPv6Address::IPv6Address ( uint64  hi,
uint64  lo 
)
inline

Constructs an IPv6 address from two 64-bit integers.

105  {
106  uint32 mask = 0xFFFFFFFF;
107  d[0] = (hi >> 32) & mask;
108  d[1] = hi & mask;
109  d[2] = (lo >> 32) & mask;
110  d[3] = lo & mask;
111  }
uint32 d[4]
Definition: IPv6Address.h:44
uint32_t uint32
Definition: Compat.h:30
inet::IPv6Address::IPv6Address ( uint32  segment0,
uint32  segment1,
uint32  segment2,
uint32  segment3 
)
inline

Constructs an IPv6 address from four 32-bit integers.

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

118  {
119  d[0] = segment0;
120  d[1] = segment1;
121  d[2] = segment2;
122  d[3] = segment3;
123  }
uint32 d[4]
Definition: IPv6Address.h:44
inet::IPv6Address::IPv6Address ( const char *  addr)
inlineexplicit

Constructor.

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

129 { set(addr); }

Member Function Documentation

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

Returns -1, 0 or 1.

145  {
146  return d[0] < addr.d[0] ? -1 : d[0] > addr.d[0] ? 1 :
147  d[1] < addr.d[1] ? -1 : d[1] > addr.d[1] ? 1 :
148  d[2] < addr.d[2] ? -1 : d[2] > addr.d[2] ? 1 :
149  d[3] < addr.d[3] ? -1 : d[3] > addr.d[3] ? 1 : 0;
150  }
uint32 d[4]
Definition: IPv6Address.h:44
void inet::IPv6Address::constructMask ( int  prefixLength,
uint32 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.

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

264 {
265  ASSERT(prefixLength >= 0 && prefixLength <= 128 && mask != nullptr);
266 
267  // create a mask based on the prefix length.
268  if (prefixLength == 0) {
269  mask[0] = mask[1] = mask[2] = mask[3] = 0x00000000;
270  }
271  else if (prefixLength <= 32) {
272  int num_of_shifts = 32 - prefixLength;
273  mask[0] = 0xFFFFFFFFU << num_of_shifts;
274  mask[1] = 0x00000000;
275  mask[2] = 0x00000000;
276  mask[3] = 0x00000000;
277  }
278  else if (prefixLength <= 64) {
279  int num_of_shifts = 64 - prefixLength;
280  mask[0] = 0xFFFFFFFFU;
281  mask[1] = 0xFFFFFFFFU << num_of_shifts;
282  mask[2] = 0x00000000;
283  mask[3] = 0x00000000;
284  }
285  else if (prefixLength <= 96) {
286  int num_of_shifts = 96 - prefixLength;
287  mask[0] = 0xFFFFFFFFU;
288  mask[1] = 0xFFFFFFFFU;
289  mask[2] = 0xFFFFFFFFU << num_of_shifts;
290  mask[3] = 0x00000000;
291  }
292  else {
293  int num_of_shifts = 128 - prefixLength;
294  mask[0] = 0xFFFFFFFFU;
295  mask[1] = 0xFFFFFFFFU;
296  mask[2] = 0xFFFFFFFFU;
297  mask[3] = 0xFFFFFFFFU << num_of_shifts;
298  }
299 }
IPv6Address inet::IPv6Address::constructMask ( int  prefixLength)
static
302 {
303  IPv6Address ret;
304  constructMask(prefixLength, ret.d);
305  return ret;
306 }
IPv6Address()
Constructor.
Definition: IPv6Address.h:99
static void constructMask(int prefixLength, uint32 *mask)
Construct a 128-bit mask based on the prefix length.
Definition: IPv6Address.cc:263
bool inet::IPv6Address::doTryParse ( const char *&  addr)
protected

Referenced by tryParse(), and tryParseAddrWithPrefix().

74 {
75  if (!strcmp(addr, "<unspec>")) {
76  addr += 8;
77  d[0] = d[1] = d[2] = d[3] = 0;
78  return true;
79  }
80 
81  // parse and store 16-bit units
82  uint16_t groups[8];
83  int numGroups = parseGroups(addr, groups);
84 
85  // if address string contains "::", parse and store second half too
86  if (*addr == ':' && *(addr + 1) == ':') {
87  addr += 2;
88  uint16_t suffixGroups[8];
89  int numSuffixGroups = parseGroups(addr, suffixGroups);
90 
91  // merge suffixGroups[] into groups[]
92  if (numGroups + numSuffixGroups > 8)
93  return false; // too many
94  for (int i = numGroups; i < 8; i++) {
95  int j = i - 8 + numSuffixGroups;
96  groups[i] = j < 0 ? 0 : suffixGroups[j];
97  }
98  numGroups = 8;
99  }
100 
101  if (numGroups != 8)
102  return false; // too few
103 
104  // copy groups to d[]
105  for (unsigned int i = 0; i < 4; i++)
106  d[i] = ((uint32_t)(groups[2 * i]) << 16) + groups[2 * i + 1];
107 
108  return true;
109 }
uint32 d[4]
Definition: IPv6Address.h:44
IPv6Address inet::IPv6Address::formLinkLocalAddress ( const InterfaceToken ident)
static

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

Referenced by inet::IPv6NeighbourDiscovery::assignLinkLocalAddress(), inet::IPv6RoutingTable::assignRequiredNodeAddresses(), and inet::FlatNetworkConfigurator6::configureAdvPrefixes().

358 {
359  IPv6Address suffix(0, 0, ident.normal(), ident.low());
361  linkLocalAddr.setSuffix(suffix, 128 - ident.length());
362  return linkLocalAddr;
363 }
IPv6Address()
Constructor.
Definition: IPv6Address.h:99
static const IPv6Address LINKLOCAL_PREFIX
The link-local prefix (fe80::)
Definition: IPv6Address.h:90
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:343
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.

Referenced by inet::IPv6NeighbourDiscovery::initiateAddressResolution(), inet::IPv6NeighbourDiscovery::initiateDAD(), inet::IPv6NeighbourDiscovery::processARTimeout(), and inet::IPv6NeighbourDiscovery::processDADTimeout().

254  {
255  return IPv6Address(*this).setPrefix(SOLICITED_NODE_PREFIX, 104);
256  };
IPv6Address()
Constructor.
Definition: IPv6Address.h:99
static const IPv6Address SOLICITED_NODE_PREFIX
The solicited-node multicast address prefix (prefix length = 104)
Definition: IPv6Address.h:87
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.

269  {
270  return IPv6Address(*this).setSuffix(UNSPECIFIED_ADDRESS, prefixLength);
271  }
IPv6Address()
Constructor.
Definition: IPv6Address.h:99
static const IPv6Address UNSPECIFIED_ADDRESS
The unspecified address.
Definition: IPv6Address.h:66
int inet::IPv6Address::getMulticastScope ( ) const

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

378 {
379  if ((d[0] & MULTICAST_MASK) != MULTICAST_PREFIX)
380  throw cRuntimeError("IPv6Address::getMulticastScope(): %s is not a multicast address", str().c_str());
381  return (d[0] >> 16) & 0x0F;
382 }
uint32 d[4]
Definition: IPv6Address.h:44
const uint32 MULTICAST_PREFIX
Definition: IPv6Address.cc:28
std::string str() const
Returns the textual representation of the address in the standard notation.
Definition: IPv6Address.cc:177
const uint32 MULTICAST_MASK
Definition: IPv6Address.cc:33
IPv6Address inet::IPv6Address::getPrefix ( int  prefixLength) const

Get the IPv6 first prefixLength bits of the address, with the rest set to zero.

309 {
310  // First we construct a mask.
311  uint32 mask[4];
312  constructMask(prefixLength, mask);
313 
314  // Now we mask each IPv6 address segment and create a new IPv6 Address!
315  return IPv6Address(d[0] & mask[0], d[1] & mask[1], d[2] & mask[2], d[3] & mask[3]);
316 }
IPv6Address()
Constructor.
Definition: IPv6Address.h:99
uint32 d[4]
Definition: IPv6Address.h:44
static void constructMask(int prefixLength, uint32 *mask)
Construct a 128-bit mask based on the prefix length.
Definition: IPv6Address.cc:263
uint32_t uint32
Definition: Compat.h:30
IPv6Address::Scope inet::IPv6Address::getScope ( ) const

Get the IPv6 address scope.

Referenced by inet::IPv6InterfaceData::addrLess(), inet::sctp::SCTPAssociation::getAddressLevel(), inet::L3AddressResolver::getIPv6AddressFrom(), inet::IPv6NeighbourDiscovery::processRAPrefixInfoForAddrAutoConf(), and inet::xMIPv6::validateType2RH().

207 {
208  //Mask the given IPv6 address with the different mask types
209  //to get only the IPv6 address scope. Compare the masked
210  //address with the different prefixes.
211 
212  if ((d[0] & LINK_LOCAL_MASK) == LINK_LOCAL_PREFIX) {
213  return LINK;
214  }
215  else if ((d[0] & SITE_LOCAL_MASK) == SITE_LOCAL_PREFIX) {
216  return SITE;
217  }
218  else if ((d[0] & MULTICAST_MASK) == MULTICAST_PREFIX) {
219  return MULTICAST;
220  }
221  else if (d[0] == 0x00000000 && d[1] == 0x00000000 && d[2] == 0x00000000) {
222  if (d[3] == 0x00000000) {
223  return UNSPECIFIED;
224  }
225  else if (d[3] == 0x00000001) {
226  return LOOPBACK;
227  }
228  else {
229  return GLOBAL; // actually an "IPv4-compatible IPv6 address"
230  }
231  }
232  else {
233  return GLOBAL;
234  }
235 }
Definition: IPv6Address.h:59
Definition: IPv6Address.h:57
const uint32 LINK_LOCAL_PREFIX
Definition: IPv6Address.cc:26
uint32 d[4]
Definition: IPv6Address.h:44
Definition: IPv6Address.h:58
const uint32 MULTICAST_PREFIX
Definition: IPv6Address.cc:28
const uint32 LINK_LOCAL_MASK
Definition: IPv6Address.cc:31
Definition: IPv6Address.h:56
Definition: IPv6Address.h:60
const uint32 SITE_LOCAL_PREFIX
Definition: IPv6Address.cc:27
const uint32 SITE_LOCAL_MASK
Definition: IPv6Address.cc:32
const uint32 MULTICAST_MASK
Definition: IPv6Address.cc:33
Definition: IPv6Address.h:55
IPv6Address inet::IPv6Address::getSuffix ( int  prefixLength) const

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

319 {
320  // First we construct a mask.
321  uint32 mask[4];
322  constructMask(prefixLength, mask);
323 
324  // Now we mask each IPv6 address segment, inverse it
325  // and create a new IPv6 Address!
326  return IPv6Address(d[0] & ~mask[0], d[1] & ~mask[1], d[2] & ~mask[2], d[3] & ~mask[3]);
327 }
IPv6Address()
Constructor.
Definition: IPv6Address.h:99
uint32 d[4]
Definition: IPv6Address.h:44
static void constructMask(int prefixLength, uint32 *mask)
Construct a 128-bit mask based on the prefix length.
Definition: IPv6Address.cc:263
uint32_t uint32
Definition: Compat.h:30
bool inet::IPv6Address::isGlobal ( ) const
inline
bool inet::IPv6Address::isLinkLocal ( ) const
inline
bool inet::IPv6Address::isLoopback ( ) const
inline

Utility function based on getScope()

Referenced by inet::IPv6::routePacket().

295 { return getScope() == LOOPBACK; }
Scope getScope() const
Get the IPv6 address scope.
Definition: IPv6Address.cc:206
Definition: IPv6Address.h:56
bool inet::IPv6Address::isSiteLocal ( ) const
inline

Utility function based on getScope()

301 { return getScope() == SITE; }
Definition: IPv6Address.h:59
Scope getScope() const
Get the IPv6 address scope.
Definition: IPv6Address.cc:206
bool inet::IPv6Address::isSolicitedNodeMulticastAddress ( ) const
inline

Referenced by inet::IPv6::fragmentAndSend().

259  {
260  return matches(SOLICITED_NODE_PREFIX, 104);
261  }
static const IPv6Address SOLICITED_NODE_PREFIX
The solicited-node multicast address prefix (prefix length = 104)
Definition: IPv6Address.h:87
bool matches(const IPv6Address &prefix, int prefixLength) const
Returns true if the address matches the given prefix.
Definition: IPv6Address.cc:365
bool inet::IPv6Address::isUnicast ( ) const
inline

Utility function based on getScope()

Referenced by inet::IPv6Tunneling::createTunnel(), inet::L3Address::isUnicast(), inet::IPv6NeighbourDiscovery::processNSForTentativeAddress(), inet::xMIPv6::validateBUMessage(), and inet::xMIPv6::validateType2RH().

292 { return getScope() != MULTICAST && getScope() != UNSPECIFIED; }
Definition: IPv6Address.h:57
Scope getScope() const
Get the IPv6 address scope.
Definition: IPv6Address.cc:206
Definition: IPv6Address.h:55
bool inet::IPv6Address::matches ( const IPv6Address prefix,
int  prefixLength 
) const

Returns true if the address matches the given prefix.

Referenced by inet::IPv6NeighbourDiscovery::createAndSendNSPacket(), inet::IPv6RoutingTable::doLongestPrefixMatch(), inet::IPv6RoutingTable::isLocalAddress(), inet::InterfaceTable::isNeighborAddress(), inet::IPv6RoutingTable::isOnLinkAddress(), inet::IPv6RoutingTable::isPrefixPresent(), inet::MultiFieldClassifier::Filter::matches(), inet::L3Address::matches(), inet::IPv6NeighbourDiscovery::processRAPrefixInfo(), inet::IPv6NeighbourDiscovery::processRAPrefixInfoForAddrAutoConf(), and inet::IPv6NeighbourDiscovery::validateNSPacket().

366 {
367  // first we construct a mask.
368  uint32 mask[4];
369  constructMask(prefixLength, mask);
370 
371  // xor the bits of the 2 addresses, and the result should be zero wherever
372  // the mask has 1 bits
373  return (((d[0] ^ prefix.d[0]) & mask[0]) | ((d[1] ^ prefix.d[1]) & mask[1])
374  | ((d[2] ^ prefix.d[2]) & mask[2]) | ((d[3] ^ prefix.d[3]) & mask[3])) == 0;
375 }
uint32 d[4]
Definition: IPv6Address.h:44
static void constructMask(int prefixLength, uint32 *mask)
Construct a 128-bit mask based on the prefix length.
Definition: IPv6Address.cc:263
uint32_t uint32
Definition: Compat.h:30
bool inet::IPv6Address::operator!= ( const IPv6Address addr) const
inline
139 { return !operator==(addr); }
bool operator==(const IPv6Address &addr) const
Definition: IPv6Address.h:134
bool inet::IPv6Address::operator< ( const IPv6Address addr) const
inline
131 { return compare(addr) < 0; }
int compare(const IPv6Address &addr) const
Returns -1, 0 or 1.
Definition: IPv6Address.h:144
bool inet::IPv6Address::operator== ( const IPv6Address addr) const
inline
135  {
136  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
137  }
uint32 d[4]
Definition: IPv6Address.h:44
bool inet::IPv6Address::operator> ( const IPv6Address addr) const
inline
132 { return compare(addr) > 0; }
int compare(const IPv6Address &addr) const
Returns -1, 0 or 1.
Definition: IPv6Address.h:144
const char * inet::IPv6Address::scopeName ( Scope  s)
static

Return the string representation of the given scope.

Referenced by inet::IPv6InterfaceData::info().

238 {
239  switch (scope) {
240  case UNSPECIFIED:
241  return "unspec";
242 
243  case LOOPBACK:
244  return "loopback";
245 
246  case MULTICAST:
247  return "mcast";
248 
249  case LINK:
250  return "link";
251 
252  case SITE:
253  return "site";
254 
255  case GLOBAL:
256  return "global";
257 
258  default:
259  return "???";
260  }
261 }
Definition: IPv6Address.h:59
Definition: IPv6Address.h:57
Definition: IPv6Address.h:58
Definition: IPv6Address.h:56
Definition: IPv6Address.h:60
Definition: IPv6Address.h:55
void inet::IPv6Address::set ( const char *  addr)

Sets the IPv6 address.

Given a string.

Referenced by inet::IPv6RoutingTable::configureTunnelFromXML(), and inet::serializer::IPv6Serializer::deserialize().

145 {
146  if (!tryParse(addr))
147  throw cRuntimeError("IPv6Address: cannot interpret address string `%s'", addr);
148 }
bool tryParse(const char *addr)
Tries parsing an IPv6 address string into the object.
Definition: IPv6Address.cc:111
void inet::IPv6Address::set ( uint32  d0,
uint32  d1,
uint32  d2,
uint32  d3 
)
inline

Sets the IPv6 address from four 32-bit integers.

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

187  {
188  d[0] = d0;
189  d[1] = d1;
190  d[2] = d2;
191  d[3] = d3;
192  }
uint32 d[4]
Definition: IPv6Address.h:44
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.

Referenced by inet::IPv6InterfaceData::autoConfRouterGlobalScopeAddress(), formSolicitedNodeMulticastAddress(), inet::IPv6NeighbourDiscovery::processRAPacket(), inet::IPv6NeighbourDiscovery::processRAPrefixInfo(), and inet::IPv6NeighbourDiscovery::processRAPrefixInfoForAddrAutoConf().

330 {
331  // first we construct a mask.
332  uint32 mask[4];
333  constructMask(prefixLength, mask);
334 
335  // combine the addresses
336  d[0] = (d[0] & ~mask[0]) | (fromAddr.d[0] & mask[0]);
337  d[1] = (d[1] & ~mask[1]) | (fromAddr.d[1] & mask[1]);
338  d[2] = (d[2] & ~mask[2]) | (fromAddr.d[2] & mask[2]);
339  d[3] = (d[3] & ~mask[3]) | (fromAddr.d[3] & mask[3]);
340  return *this;
341 }
uint32 d[4]
Definition: IPv6Address.h:44
static void constructMask(int prefixLength, uint32 *mask)
Construct a 128-bit mask based on the prefix length.
Definition: IPv6Address.cc:263
uint32_t uint32
Definition: Compat.h:30
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.

Referenced by formLinkLocalAddress(), and formSubnetRouterAnycastAddress().

344 {
345  // first we construct a mask.
346  uint32 mask[4];
347  constructMask(prefixLength, mask);
348 
349  // combine the addresses
350  d[0] = (d[0] & mask[0]) | (fromAddr.d[0] & ~mask[0]);
351  d[1] = (d[1] & mask[1]) | (fromAddr.d[1] & ~mask[1]);
352  d[2] = (d[2] & mask[2]) | (fromAddr.d[2] & ~mask[2]);
353  d[3] = (d[3] & mask[3]) | (fromAddr.d[3] & ~mask[3]);
354  return *this;
355 }
uint32 d[4]
Definition: IPv6Address.h:44
static void constructMask(int prefixLength, uint32 *mask)
Construct a 128-bit mask based on the prefix length.
Definition: IPv6Address.cc:263
uint32_t uint32
Definition: Compat.h:30
std::string inet::IPv6Address::str ( ) const

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

Referenced by inet::IPv6InterfaceData::addMulticastListener(), inet::IPv6RoutingTable::doLongestPrefixMatch(), inet::PacketDump::dumpIPv6(), inet::IPv6::encapsulate(), inet::IPv6RoutingTable::getInterfaceByAddress(), getMulticastScope(), inet::IPv6RoutingTable::isLocalAddress(), inet::IPv6InterfaceData::joinMulticastGroup(), inet::IPv6InterfaceData::leaveMulticastGroup(), inet::IPv6RoutingTable::lookupDestCache(), inet::operator<<(), inet::IPv6NeighbourDiscovery::reachabilityConfirmed(), inet::IPv6NeighbourDiscovery::resolveNeighbour(), inet::L3Address::str(), and inet::InterfaceTable::updateLinkDisplayString().

178 {
179  if (isUnspecified())
180  return std::string("<unspec>");
181 
182  // convert to 16-bit grops
183  uint16_t groups[8] = {
184  uint16_t(d[0] >> 16), uint16_t(d[0] & 0xffff), uint16_t(d[1] >> 16), uint16_t(d[1] & 0xffff),
185  uint16_t(d[2] >> 16), uint16_t(d[2] & 0xffff), uint16_t(d[3] >> 16), uint16_t(d[3] & 0xffff)
186  };
187 
188  // find longest sequence of zeros in groups[]
189  int start, end;
190  findGap(groups, start, end);
191  if (start == 0 && end == 8)
192  return "::0"; // the unspecified address is a special case
193 
194  // print groups, replacing gap with "::"
195  std::stringstream os;
196  os << std::hex;
197  for (int i = 0; i < start; i++)
198  os << (i == 0 ? "" : ":") << groups[i];
199  if (start != end)
200  os << "::";
201  for (int j = end; j < 8; j++)
202  os << (j == end ? "" : ":") << groups[j];
203  return os.str();
204 }
uint32 d[4]
Definition: IPv6Address.h:44
bool isUnspecified() const
Check if the IPv6 Address is undefined.
Definition: IPv6Address.h:286
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).

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

112 {
113  if (!addr)
114  return false;
115  if (!doTryParse(addr))
116  return false;
117  if (*addr != 0)
118  return false; // illegal trailing character
119  return true;
120 }
bool doTryParse(const char *&addr)
Definition: IPv6Address.cc:73
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.).

Referenced by inet::IPv6RoutingTable::configureInterfaceFromXML().

123 {
124  if (!addr)
125  return false;
126  if (!doTryParse(addr))
127  return false;
128  if (*addr != '/')
129  return false; // no '/' after address
130  addr++;
131 
132  // parse prefix
133  char *e;
134  prefixLen = strtoul(addr, &e, 10);
135  if (addr == e)
136  return false; // no number after '/'
137  if (*e != 0)
138  return false; // garbage after number
139  if (prefixLen < 0 || prefixLen > 128)
140  return false; // wrong len value
141  return true;
142 }
const value< double, units::C > e(1.602176487e-19)
bool doTryParse(const char *&addr)
Definition: IPv6Address.cc:73
uint32* inet::IPv6Address::words ( )
inline

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

Referenced by inet::serializer::SCTPSerializer::deserialize(), inet::doPacking(), inet::doUnpacking(), inet::serializer::IPv6Serializer::serialize(), inet::L3Address::set(), and inet::serializer::Buffer::writeIPv6Address().

198 { return d; }
uint32 d[4]
Definition: IPv6Address.h:44
const uint32* inet::IPv6Address::words ( ) const
inline

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

204 { return d; }
uint32 d[4]
Definition: IPv6Address.h:44

Member Data Documentation

const IPv6Address inet::IPv6Address::ALL_NODES_1
static
const IPv6Address inet::IPv6Address::ALL_ROUTERS_1
static

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

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

const IPv6Address inet::IPv6Address::ALL_ROUTERS_2
static
const IPv6Address inet::IPv6Address::ALL_ROUTERS_5
static

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

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

const IPv6Address inet::IPv6Address::LINKLOCAL_PREFIX
static

The link-local prefix (fe80::)

Referenced by inet::IPv6RoutingTable::configureInterfaceForIPv6(), and formLinkLocalAddress().

const IPv6Address inet::IPv6Address::LL_MANET_ROUTERS
static

Link-local MANET routers multicast address.

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

const IPv6Address inet::IPv6Address::LOOPBACK_ADDRESS
static

The loopback address.

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

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().


The documentation for this class was generated from the following files: