A Discrete-Event Network Simulator
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
Go to the documentation of this file.
1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2 /*
3  * Copyright (c) 2005 INRIA
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
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: Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
19  */
21 #ifndef IPV4_ADDRESS_H
22 #define IPV4_ADDRESS_H
24 #include <stdint.h>
25 #include <ostream>
26 #include "ns3/address.h"
27 #include "ns3/attribute-helper.h"
29 namespace ns3 {
31 class Ipv4Mask;
38 class Ipv4Address {
39 public:
40  Ipv4Address ();
45  explicit Ipv4Address (uint32_t address);
55  Ipv4Address (char const *address);
60  uint32_t Get (void) const;
65  void Set (uint32_t address);
75  void Set (char const *address);
81  bool IsEqual (const Ipv4Address &other) const
82  {
83  return m_address == other.m_address;
84  }
91  void Serialize (uint8_t buf[4]) const;
98  static Ipv4Address Deserialize (const uint8_t buf[4]);
105  void Print (std::ostream &os) const;
109  bool IsBroadcast (void) const;
113  bool IsMulticast (void) const;
117  bool IsLocalMulticast (void) const;
128  Ipv4Address CombineMask (Ipv4Mask const &mask) const;
140  Ipv4Address GetSubnetDirectedBroadcast (Ipv4Mask const &mask) const;
153  bool IsSubnetDirectedBroadcast (Ipv4Mask const &mask) const;
160  static bool IsMatchingType (const Address &address);
166  operator Address () const;
175  static Ipv4Address ConvertFrom (const Address &address);
179  static Ipv4Address GetZero (void);
183  static Ipv4Address GetAny (void);
187  static Ipv4Address GetBroadcast (void);
191  static Ipv4Address GetLoopback (void);
193 private:
198  Address ConvertTo (void) const;
205  static uint8_t GetType (void);
206  uint32_t m_address;
208  friend bool operator == (Ipv4Address const &a, Ipv4Address const &b);
209  friend bool operator != (Ipv4Address const &a, Ipv4Address const &b);
210  friend bool operator < (Ipv4Address const &a, Ipv4Address const &b);
211 };
222 class Ipv4Mask {
223 public:
227  Ipv4Mask ();
233  Ipv4Mask (uint32_t mask);
237  Ipv4Mask (char const *mask);
244  bool IsMatch (Ipv4Address a, Ipv4Address b) const;
249  bool IsEqual (Ipv4Mask other) const;
254  uint32_t Get (void) const;
259  void Set (uint32_t mask);
263  uint32_t GetInverse (void) const;
270  void Print (std::ostream &os) const;
274  uint16_t GetPrefixLength (void) const;
278  static Ipv4Mask GetLoopback (void);
282  static Ipv4Mask GetZero (void);
286  static Ipv4Mask GetOnes (void);
288 private:
289  uint32_t m_mask;
290 };
311 std::ostream& operator<< (std::ostream& os, Ipv4Address const& address);
319 std::ostream& operator<< (std::ostream& os, Ipv4Mask const& mask);
327 std::istream & operator >> (std::istream &is, Ipv4Address &address);
335 std::istream & operator >> (std::istream &is, Ipv4Mask &mask);
344 inline bool operator == (const Ipv4Address &a, const Ipv4Address &b)
345 {
346  return (a.m_address == b.m_address);
347 }
355 inline bool operator != (const Ipv4Address &a, const Ipv4Address &b)
356 {
357  return (a.m_address != b.m_address);
358 }
366 inline bool operator < (const Ipv4Address &a, const Ipv4Address &b)
367 {
368  return (a.m_address < b.m_address);
369 }
376 class Ipv4AddressHash : public std::unary_function<Ipv4Address, size_t> {
377 public:
383  size_t operator() (Ipv4Address const &x) const;
384 };
393 bool operator == (Ipv4Mask const &a, Ipv4Mask const &b);
401 bool operator != (Ipv4Mask const &a, Ipv4Mask const &b);
403 } // namespace ns3
405 #endif /* IPV4_ADDRESS_H */
Will initialize to a garbage value (0x66666666)
Definition: ipv4-address.cc:69
static Ipv4Address Deserialize(const uint8_t buf[4])
std::istream & operator>>(std::istream &is, Angles &a)
initialize a struct Angles from input
Definition: angles.cc:49
static Ipv4Mask GetOnes(void)
static Ipv4Address GetAny(void)
size_t operator()(Ipv4Address const &x) const
Returns the hash of the address.
friend bool operator<(Ipv4Address const &a, Ipv4Address const &b)
Less than operator.
Definition: ipv4-address.h:366
bool IsMatch(Ipv4Address a, Ipv4Address b) const
a class to represent an Ipv4 address mask
Definition: ipv4-address.h:222
uint32_t m_address
IPv4 address.
Definition: ipv4-address.h:206
bool IsLocalMulticast(void) const
bool IsMulticast(void) const
Ipv4Address CombineMask(Ipv4Mask const &mask) const
Combine this address with a network mask.
Ipv4Address GetSubnetDirectedBroadcast(Ipv4Mask const &mask) const
Generate subnet-directed broadcast address corresponding to mask.
a polymophic address class
Definition: address.h:86
bool IsSubnetDirectedBroadcast(Ipv4Mask const &mask) const
Generate subnet-directed broadcast address corresponding to mask.
uint32_t Get(void) const
Get the host-order 32-bit IP address.
static Ipv4Mask GetZero(void)
bool IsBroadcast(void) const
void Serialize(uint8_t buf[4]) const
Serialize this address to a 4-byte buffer.
void Print(std::ostream &os) const
Print this address to the given output stream.
static bool IsMatchingType(const Address &address)
static Ipv4Address GetBroadcast(void)
bool operator<(const int64x64_t &lhs, const int64x64_t &rhs)
Less than operator.
Definition: int64x64-128.h:327
std::ostream & operator<<(std::ostream &os, const Angles &a)
print a struct Angles to output
Definition: angles.cc:43
bool operator!=(Callback< R, T1, T2, T3, T4, T5, T6, T7, T8, T9 > a, Callback< R, T1, T2, T3, T4, T5, T6, T7, T8, T9 > b)
Inequality test.
Definition: callback.h:1217
bool IsEqual(const Ipv4Address &other) const
Comparison operation between two Ipv4Addresses.
Definition: ipv4-address.h:81
void Set(uint32_t mask)
input mask is in host order.
static Ipv4Address GetZero(void)
static Ipv4Address GetLoopback(void)
void Print(std::ostream &os) const
Print this mask to the given output stream.
static Ipv4Mask GetLoopback(void)
Address ConvertTo(void) const
Convert to an Address type.
uint32_t m_mask
IP mask.
Definition: ipv4-address.h:289
void Set(uint32_t address)
input address is in host order.
Ipv4 addresses are stored in host order in this class.
Definition: ipv4-address.h:38
friend bool operator==(Ipv4Address const &a, Ipv4Address const &b)
Equal to operator.
Definition: ipv4-address.h:344
bool IsEqual(Ipv4Mask other) const
bool operator==(const EventId &a, const EventId &b)
Definition: event-id.cc:89
static uint8_t GetType(void)
Get the underlying address type (automatically assigned).
uint32_t Get(void) const
Get the host-order 32-bit IP mask.
friend bool operator!=(Ipv4Address const &a, Ipv4Address const &b)
Not equal to operator.
Definition: ipv4-address.h:355
static Ipv4Address ConvertFrom(const Address &address)
tuple address
Definition: first.py:37
uint32_t GetInverse(void) const
Return the inverse mask in host order.
uint16_t GetPrefixLength(void) const
Class providing an hash for IPv4 addresses.
Definition: ipv4-address.h:376