A Discrete-Event Network Simulator
API
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
ipv6-address.h
Go to the documentation of this file.
1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2 /*
3  * Copyright (c) 2007-2008 Louis Pasteur University
4  *
5  * This program is free software; you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License version 2 as
7  * published by the Free Software Foundation;
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program; if not, write to the Free Software
16  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17  *
18  * Author: Sebastien Vincent <vincent@clarinet.u-strasbg.fr>
19  */
20 
21 #ifndef IPV6_ADDRESS_H
22 #define IPV6_ADDRESS_H
23 
24 #include <stdint.h>
25 #include <cstring>
26 
27 #include <ostream>
28 
29 #include "ns3/attribute-helper.h"
30 #include "ns3/address.h"
31 #include "ns3/ipv4-address.h"
32 
33 namespace ns3 {
34 
35 class Ipv6Prefix;
36 class Mac16Address;
37 class Mac48Address;
38 class Mac64Address;
39 
47 {
48 public:
52  Ipv6Address ();
53 
58  Ipv6Address (char const* address);
59 
65  Ipv6Address (uint8_t address[16]);
66 
71  Ipv6Address (Ipv6Address const & addr);
72 
77  Ipv6Address (Ipv6Address const* addr);
78 
82  ~Ipv6Address ();
83 
88  void Set (char const* address);
89 
96  void Set (uint8_t address[16]);
97 
104  bool IsEqual (const Ipv6Address& other) const;
105 
111  void Serialize (uint8_t buf[16]) const;
112 
118  static Ipv6Address Deserialize (const uint8_t buf[16]);
119 
126 
133 
139 
147 
155 
163 
170 
177 
184 
191  void Print (std::ostream& os) const;
192 
197  bool IsLocalhost () const;
198 
203  bool IsMulticast () const;
204 
209  bool IsLinkLocalMulticast () const;
210 
215  bool IsAllNodesMulticast () const;
216 
221  bool IsAllRoutersMulticast () const;
222 
227  bool IsAllHostsMulticast () const;
228 
233  bool IsLinkLocal () const;
234 
239  bool IsSolicitedMulticast () const;
240 
245  bool IsAny () const;
246 
251  bool IsDocumentation () const;
252 
259  Ipv6Address CombinePrefix (Ipv6Prefix const & prefix);
260 
266  static bool IsMatchingType (const Address& address);
267 
272  bool IsIpv4MappedAddress();
273 
277  operator Address () const;
278 
284  static Ipv6Address ConvertFrom (const Address& address);
285 
290  static Ipv6Address GetZero ();
291 
296  static Ipv6Address GetAny ();
297 
303 
309 
315 
320  static Ipv6Address GetLoopback ();
321 
326  static Ipv6Address GetOnes ();
327 
333  void GetBytes (uint8_t buf[16]) const;
334 
335 private:
340  Address ConvertTo (void) const;
341 
346  static uint8_t GetType (void);
347 
351  uint8_t m_address[16];
352 
353  friend bool operator == (Ipv6Address const &a, Ipv6Address const &b);
354  friend bool operator != (Ipv6Address const &a, Ipv6Address const &b);
355  friend bool operator < (Ipv6Address const &a, Ipv6Address const &b);
356 };
357 
365 {
366 public:
370  Ipv6Prefix ();
371 
376  Ipv6Prefix (uint8_t prefix[16]);
377 
382  Ipv6Prefix (char const* prefix);
383 
389  Ipv6Prefix (uint8_t prefix);
390 
395  Ipv6Prefix (Ipv6Prefix const& prefix);
396 
401  Ipv6Prefix (Ipv6Prefix const* prefix);
402 
406  ~Ipv6Prefix ();
407 
414  bool IsMatch (Ipv6Address a, Ipv6Address b) const;
415 
420  void GetBytes (uint8_t buf[16]) const;
421 
426  uint8_t GetPrefixLength () const;
427 
433  bool IsEqual (const Ipv6Prefix& other) const;
434 
441  void Print (std::ostream &os) const;
442 
447  static Ipv6Prefix GetLoopback ();
448 
453  static Ipv6Prefix GetOnes ();
454 
459  static Ipv6Prefix GetZero ();
460 
461 private:
465  uint8_t m_prefix[16];
466 };
467 
473 
479 
480 std::ostream& operator << (std::ostream& os, Ipv6Address const& address);
481 std::ostream& operator<< (std::ostream& os, Ipv6Prefix const& prefix);
482 std::istream & operator >> (std::istream &is, Ipv6Address &address);
483 std::istream & operator >> (std::istream &is, Ipv6Prefix &prefix);
484 
485 inline bool operator == (const Ipv6Address& a, const Ipv6Address& b)
486 {
487  return (!std::memcmp (a.m_address, b.m_address, 16));
488 }
489 
490 inline bool operator != (const Ipv6Address& a, const Ipv6Address& b)
491 {
492  return std::memcmp (a.m_address, b.m_address, 16);
493 }
494 
495 inline bool operator < (const Ipv6Address& a, const Ipv6Address& b)
496 {
497  return (std::memcmp (a.m_address, b.m_address, 16) < 0);
498 }
499 
504 class Ipv6AddressHash : public std::unary_function<Ipv6Address, size_t>
505 {
506 public:
511  size_t operator () (Ipv6Address const &x) const;
512 };
513 
514 bool operator == (Ipv6Prefix const &a, Ipv6Prefix const &b);
515 bool operator != (Ipv6Prefix const &a, Ipv6Prefix const &b);
516 
517 } /* namespace ns3 */
518 
519 #endif /* IPV6_ADDRESS_H */
520