/usr/include/ns3.17/ns3/ipv6-address.h is in libns3-dev 3.17+dfsg-1build1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/*
* Copyright (c) 2007-2008 Louis Pasteur University
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
* published by the Free Software Foundation;
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
* Author: Sebastien Vincent <vincent@clarinet.u-strasbg.fr>
*/
#ifndef IPV6_ADDRESS_H
#define IPV6_ADDRESS_H
#include <stdint.h>
#include <cstring>
#include <ostream>
#include "ns3/attribute-helper.h"
#include "ns3/address.h"
#include "ns3/ipv4-address.h"
namespace ns3 {
class Ipv6Prefix;
class Mac48Address;
/**
* \ingroup address
* \class Ipv6Address
* \brief Describes an IPv6 address.
* \see Ipv6Prefix
*/
class Ipv6Address
{
public:
/**
* \brief Default constructor.
*/
Ipv6Address ();
/**
* \brief Constructs an Ipv6Address by parsing the input C-string.
* \param address the C-string containing the IPv6 address (e.g. 2001:660:4701::1).
*/
Ipv6Address (char const* address);
/**
* \brief Constructs an Ipv6Address by using the input 16 bytes.
* \param address the 128-bit address
* \warning the parameter must point on a 16 bytes integer array!
*/
Ipv6Address (uint8_t address[16]);
/**
* \brief Copy constructor.
* \param addr Ipv6Address object
*/
Ipv6Address (Ipv6Address const & addr);
/**
* \brief Copy constructor.
* \param addr Ipv6Address pointer
*/
Ipv6Address (Ipv6Address const* addr);
/**
* \brief Destructor.
*/
~Ipv6Address ();
/**
* \brief Sets an Ipv6Address by parsing the input C-string.
* \param address the C-string containing the IPv6 address (e.g. 2001:660:4701::1).
*/
void Set (char const* address);
/**
* \brief Set an Ipv6Address by using the input 16 bytes.
*
* \param address the 128-bit address
* \warning the parameter must point on a 16 bytes integer array!
*/
void Set (uint8_t address[16]);
/**
* \brief Comparison operation between two Ipv6Addresses.
*
* \param other the IPv6 address to which to compare thisaddress
* \return true if the addresses are equal, false otherwise
*/
bool IsEqual (const Ipv6Address& other) const;
/**
* \brief Serialize this address to a 16-byte buffer.
* \param buf the output buffer to which this address gets overwritten with this
* Ipv6Address
*/
void Serialize (uint8_t buf[16]) const;
/**
* \brief Deserialize this address.
* \param buf buffer to read address from
* \return an Ipv6Address
*/
static Ipv6Address Deserialize (const uint8_t buf[16]);
/**
* \brief Make the solicited IPv6 address.
* \param addr the IPv6 address
* \return Solicited IPv6 address
*/
static Ipv6Address MakeSolicitedAddress (Ipv6Address addr);
/**
* \brief Make the Ipv4-mapped IPv6 address.
* \param addr the IPv4 address
* \return Ipv4-mapped IPv6 address
*/
static Ipv6Address MakeIpv4MappedAddress (Ipv4Address addr);
/**
* \brief Return the Ipv4 address.
* \return Ipv4 address
*/
Ipv4Address GetIpv4MappedAddress () const;
/**
* \brief Make the autoconfigured IPv6 address with Mac48Address.
* \param addr the MAC address (48 bits).
* \param prefix the IPv6 prefix
* \return autoconfigured IPv6 address
*/
static Ipv6Address MakeAutoconfiguredAddress (Mac48Address addr, Ipv6Address prefix);
/**
* \brief Make the autoconfigured link-local IPv6 address with Mac48Address.
* \param mac the MAC address (48 bits).
* \return autoconfigured link-local IPv6 address
*/
static Ipv6Address MakeAutoconfiguredLinkLocalAddress (Mac48Address mac);
/**
* \brief Print this address to the given output stream.
*
* The print format is in the typical "2001:660:4701::1".
* \param os the output stream to which this Ipv6Address is printed
*/
void Print (std::ostream& os) const;
/**
* \brief If the IPv6 address is localhost (::1).
* \return true if localhost, false otherwise
*/
bool IsLocalhost () const;
/**
* \brief If the IPv6 address is multicast (ff00::/8).
* \return true if multicast, false otherwise
*/
bool IsMulticast () const;
/**
* \brief If the IPv6 address is link-local multicast (ff02::/16).
* \return true if link-local multicast, false otherwise
*/
bool IsLinkLocalMulticast () const;
/**
* \brief If the IPv6 address is "all nodes multicast" (ff02::1/8).
* \return true if "all nodes multicast", false otherwise
*/
bool IsAllNodesMulticast () const;
/**
* \brief If the IPv6 address is "all routers multicast" (ff02::2/8).
* \return true if "all routers multicast", false otherwise
*/
bool IsAllRoutersMulticast () const;
/**
* \brief If the IPv6 address is "all hosts multicast" (ff02::3/8).
* \return true if "all hosts multicast", false otherwise
*/
bool IsAllHostsMulticast () const;
/**
* \brief If the IPv6 address is a link-local address (fe80::/64).
* \return true if the address is link-local, false otherwise
*/
bool IsLinkLocal () const;
/**
* \brief If the IPv6 address is a Solicited multicast address.
* \return true if it is, false otherwise
*/
bool IsSolicitedMulticast () const;
/**
* \brief If the IPv6 address is the "Any" address.
* \return true if it is, false otherwise
*/
bool IsAny () const;
/**
* \brief Combine this address with a prefix.
* \param prefix a IPv6 prefix
* \return an IPv6 address that is this address combined
* (bitwise AND) with a prefix, yielding an IPv6 network address.
*/
Ipv6Address CombinePrefix (Ipv6Prefix const & prefix);
/**
* \brief If the Address matches the type.
* \param address other address
* \return true if the type matches, false otherwise
*/
static bool IsMatchingType (const Address& address);
/**
* \brief If the address is an IPv4-mapped address
* \return true if address is an IPv4-mapped address, otherwise false.
*/
bool IsIpv4MappedAddress();
/**
* \brief Convert to Address object
*/
operator Address () const;
/**
* \brief Convert the Address object into an Ipv6Address ones.
* \param address address to convert
* \return an Ipv6Address
*/
static Ipv6Address ConvertFrom (const Address& address);
/**
* \brief Get the 0 (::) Ipv6Address.
* \return the :: Ipv6Address representation
*/
static Ipv6Address GetZero ();
/**
* \brief Get the "any" (::) Ipv6Address.
* \return the "any" (::) Ipv6Address
*/
static Ipv6Address GetAny ();
/**
* \brief Get the "all nodes multicast" address.
* \return the "ff02::2/8" Ipv6Address representation
*/
static Ipv6Address GetAllNodesMulticast ();
/**
* \brief Get the "all routers multicast" address.
* \return the "ff02::2/8" Ipv6Address representation
*/
static Ipv6Address GetAllRoutersMulticast ();
/**
* \brief Get the "all hosts multicast" address.
* \return the "ff02::3/8" Ipv6Address representation
*/
static Ipv6Address GetAllHostsMulticast ();
/**
* \brief Get the loopback address.
* \return the "::1/128" Ipv6Address representation.
*/
static Ipv6Address GetLoopback ();
/**
* \brief Get the "all-1" IPv6 address (ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff).
* \return all-1 Ipv6Address representation
*/
static Ipv6Address GetOnes ();
/**
* \brief Get the bytes corresponding to the address.
* \param buf buffer to store the data
* \return bytes of the address
*/
void GetBytes (uint8_t buf[16]) const;
private:
/**
* \brief convert the IPv6Address object to an Address object.
* \return the Address object corresponding to this object.
*/
Address ConvertTo (void) const;
/**
* \brief Return the Type of address.
* \return type of address
*/
static uint8_t GetType (void);
/**
* \brief The address representation on 128 bits (16 bytes).
*/
uint8_t m_address[16];
friend bool operator == (Ipv6Address const &a, Ipv6Address const &b);
friend bool operator != (Ipv6Address const &a, Ipv6Address const &b);
friend bool operator < (Ipv6Address const &a, Ipv6Address const &b);
};
/**
* \ingroup address
* \class Ipv6Prefix
* \brief Describes an IPv6 prefix. It is just a bitmask like Ipv4Mask.
* \see Ipv6Address
*/
class Ipv6Prefix
{
public:
/**
* \brief Default constructor.
*/
Ipv6Prefix ();
/**
* \brief Constructs an Ipv6Prefix by using the input 16 bytes.
* \param prefix the 128-bit prefix
*/
Ipv6Prefix (uint8_t prefix[16]);
/**
* \brief Constructs an Ipv6Prefix by using the input string.
* \param prefix the 128-bit prefix
*/
Ipv6Prefix (char const* prefix);
/**
* \brief Constructs an Ipv6Prefix by using the input number of bits.
* \param prefix number of bits of the prefix (0 - 128)
* \note A valid number of bits is between 0 and 128).
*/
Ipv6Prefix (uint8_t prefix);
/**
* \brief Copy constructor.
* \param prefix Ipv6Prefix object
*/
Ipv6Prefix (Ipv6Prefix const& prefix);
/**
* \brief Copy constructor.
* \param prefix Ipv6Prefix pointer
*/
Ipv6Prefix (Ipv6Prefix const* prefix);
/**
* \brief Destructor.
*/
~Ipv6Prefix ();
/**
* \brief If the Address match the type.
* \param a a first address
* \param b a second address
* \return true if the type match, false otherwise
*/
bool IsMatch (Ipv6Address a, Ipv6Address b) const;
/**
* \brief Get the bytes corresponding to the prefix.
* \param buf buffer to store the data
*/
void GetBytes (uint8_t buf[16]) const;
/**
* \brief Get prefix length.
* \return prefix length
*/
uint8_t GetPrefixLength () const;
/**
* \brief Comparison operation between two Ipv6Prefix.
* \param other the IPv6 prefix to which to compare this prefix
* \return true if the prefixes are equal, false otherwise
*/
bool IsEqual (const Ipv6Prefix& other) const;
/**
* \brief Print this address to the given output stream.
*
* The print format is in the typical "2001:660:4701::1".
* \param os the output stream to which this Ipv6Address is printed
*/
void Print (std::ostream &os) const;
/**
* \brief Get the loopback prefix ( /128).
* \return a Ipv6Prefix corresponding to loopback prefix
*/
static Ipv6Prefix GetLoopback ();
/**
* \brief Get the "all-1" IPv6 mask (ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff).
* \return /128 Ipv6Prefix representation
*/
static Ipv6Prefix GetOnes ();
/**
* \brief Get the zero prefix ( /0).
* \return an Ipv6Prefix
*/
static Ipv6Prefix GetZero ();
private:
/**
* \brief The prefix representation.
*/
uint8_t m_prefix[16];
};
/**
* \class ns3::Ipv6AddressValue
* \brief Hold objects of type ns3::Ipv6Address
*/
ATTRIBUTE_HELPER_HEADER (Ipv6Address);
/**
* \class ns3::Ipv6PrefixValue
* \brief Hold objects of type ns3::Ipv6Prefix
*/
ATTRIBUTE_HELPER_HEADER (Ipv6Prefix);
std::ostream& operator << (std::ostream& os, Ipv6Address const& address);
std::ostream& operator<< (std::ostream& os, Ipv6Prefix const& prefix);
std::istream & operator >> (std::istream &is, Ipv6Address &address);
std::istream & operator >> (std::istream &is, Ipv6Prefix &prefix);
inline bool operator == (const Ipv6Address& a, const Ipv6Address& b)
{
return (!std::memcmp (a.m_address, b.m_address, 16));
}
inline bool operator != (const Ipv6Address& a, const Ipv6Address& b)
{
return std::memcmp (a.m_address, b.m_address, 16);
}
inline bool operator < (const Ipv6Address& a, const Ipv6Address& b)
{
return (std::memcmp (a.m_address, b.m_address, 16) < 0);
}
/**
* \class Ipv6AddressHash
* \brief Hash function class for IPv6 addresses.
*/
class Ipv6AddressHash : public std::unary_function<Ipv6Address, size_t>
{
public:
/**
* \brief Unary operator to hash IPv6 address.
* \param x IPv6 address to hash
*/
size_t operator () (Ipv6Address const &x) const;
};
bool operator == (Ipv6Prefix const &a, Ipv6Prefix const &b);
bool operator != (Ipv6Prefix const &a, Ipv6Prefix const &b);
} /* namespace ns3 */
#endif /* IPV6_ADDRESS_H */
|