A Discrete-Event Network Simulator
API
ipv4-address.h
Go to the documentation of this file.
1/*
2 * Copyright (c) 2005 INRIA
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License version 2 as
6 * published by the Free Software Foundation;
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License
14 * along with this program; if not, write to the Free Software
15 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
16 *
17 * Author: Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
18 */
19
20#ifndef IPV4_ADDRESS_H
21#define IPV4_ADDRESS_H
22
23#include "ns3/address.h"
24#include "ns3/attribute-helper.h"
25#include "ns3/deprecated.h"
26
27#include <ostream>
28#include <stdint.h>
29
30namespace ns3
31{
32
33class Ipv4Mask;
34
43{
44 public:
60 Ipv4Address(const char* address);
65 uint32_t Get() const;
70 void Set(uint32_t address);
80 void Set(const char* address);
87 void Serialize(uint8_t buf[4]) const;
94 static Ipv4Address Deserialize(const uint8_t buf[4]);
101 void Print(std::ostream& os) const;
102
106 bool IsInitialized() const;
110 bool IsAny() const;
114 bool IsLocalhost() const;
118 bool IsBroadcast() const;
122 bool IsMulticast() const;
126 bool IsLocalMulticast() const;
137 Ipv4Address CombineMask(const Ipv4Mask& mask) const;
162 bool IsSubnetDirectedBroadcast(const Ipv4Mask& mask) const;
169 static bool IsMatchingType(const Address& address);
175 operator Address() const;
184 static Ipv4Address ConvertFrom(const Address& address);
188 static Ipv4Address GetZero();
192 static Ipv4Address GetAny();
196 static Ipv4Address GetBroadcast();
200 static Ipv4Address GetLoopback();
201
202 private:
207 Address ConvertTo() const;
208
214 static uint8_t GetType();
217
225 friend bool operator==(const Ipv4Address& a, const Ipv4Address& b);
226
234 friend bool operator!=(const Ipv4Address& a, const Ipv4Address& b);
235
243 friend bool operator<(const Ipv4Address& a, const Ipv4Address& b);
244};
245
258{
259 public:
263 Ipv4Mask();
269 Ipv4Mask(uint32_t mask);
273 Ipv4Mask(const char* mask);
280 bool IsMatch(Ipv4Address a, Ipv4Address b) const;
285 uint32_t Get() const;
290 void Set(uint32_t mask);
295 uint32_t GetInverse() const;
302 void Print(std::ostream& os) const;
306 uint16_t GetPrefixLength() const;
310 static Ipv4Mask GetLoopback();
314 static Ipv4Mask GetZero();
318 static Ipv4Mask GetOnes();
319
327 friend bool operator==(const Ipv4Mask& a, const Ipv4Mask& b);
328
336 friend bool operator!=(const Ipv4Mask& a, const Ipv4Mask& b);
337
338 private:
340};
341
344
352std::ostream& operator<<(std::ostream& os, const Ipv4Address& address);
360std::ostream& operator<<(std::ostream& os, const Ipv4Mask& mask);
368std::istream& operator>>(std::istream& is, Ipv4Address& address);
376std::istream& operator>>(std::istream& is, Ipv4Mask& mask);
377
378inline bool
380{
381 return (a.m_address == b.m_address);
382}
383
384inline bool
386{
387 return (a.m_address != b.m_address);
388}
389
390inline bool
391operator<(const Ipv4Address& a, const Ipv4Address& b)
392{
393 return (a.m_address < b.m_address);
394}
395
402{
403 public:
412 size_t operator()(const Ipv4Address& x) const;
413};
414
415inline bool
416operator==(const Ipv4Mask& a, const Ipv4Mask& b)
417{
418 return (a.m_mask == b.m_mask);
419}
420
421inline bool
422operator!=(const Ipv4Mask& a, const Ipv4Mask& b)
423{
424 return (a.m_mask != b.m_mask);
425}
426
427} // namespace ns3
428
429#endif /* IPV4_ADDRESS_H */
a polymophic address class
Definition: address.h:92
Class providing an hash for IPv4 addresses.
Definition: ipv4-address.h:402
size_t operator()(const Ipv4Address &x) const
Returns the hash of an IPv4 address.
Ipv4 addresses are stored in host order in this class.
Definition: ipv4-address.h:43
void Print(std::ostream &os) const
Print this address to the given output stream.
static Ipv4Address GetLoopback()
Ipv4Address GetSubnetDirectedBroadcast(const Ipv4Mask &mask) const
Generate subnet-directed broadcast address corresponding to mask.
bool IsMulticast() const
friend bool operator!=(const Ipv4Address &a, const Ipv4Address &b)
Not equal to operator.
Definition: ipv4-address.h:385
friend bool operator<(const Ipv4Address &a, const Ipv4Address &b)
Less than to operator.
Definition: ipv4-address.h:391
static Ipv4Address ConvertFrom(const Address &address)
static Ipv4Address GetZero()
static bool IsMatchingType(const Address &address)
void Set(uint32_t address)
input address is in host order.
bool IsSubnetDirectedBroadcast(const Ipv4Mask &mask) const
Generate subnet-directed broadcast address corresponding to mask.
bool IsLocalhost() const
static Ipv4Address GetBroadcast()
void Serialize(uint8_t buf[4]) const
Serialize this address to a 4-byte buffer.
Ipv4Address CombineMask(const Ipv4Mask &mask) const
Combine this address with a network mask.
bool IsAny() const
uint32_t Get() const
Get the host-order 32-bit IP address.
static Ipv4Address Deserialize(const uint8_t buf[4])
static uint8_t GetType()
Get the underlying address type (automatically assigned).
friend bool operator==(const Ipv4Address &a, const Ipv4Address &b)
Equal to operator.
Definition: ipv4-address.h:379
bool m_initialized
IPv4 address has been explicitly initialized to a valid value.
Definition: ipv4-address.h:216
uint32_t m_address
IPv4 address.
Definition: ipv4-address.h:215
Address ConvertTo() const
Convert to an Address type.
bool IsBroadcast() const
static Ipv4Address GetAny()
bool IsInitialized() const
bool IsLocalMulticast() const
a class to represent an Ipv4 address mask
Definition: ipv4-address.h:258
uint32_t m_mask
IP mask.
Definition: ipv4-address.h:339
friend bool operator!=(const Ipv4Mask &a, const Ipv4Mask &b)
Not equal to operator.
Definition: ipv4-address.h:422
static Ipv4Mask GetOnes()
void Set(uint32_t mask)
input mask is in host order.
Ipv4Mask()
Will initialize to a garbage value (0x66666666)
Definition: ipv4-address.cc:84
friend bool operator==(const Ipv4Mask &a, const Ipv4Mask &b)
Equal to operator.
Definition: ipv4-address.h:416
uint16_t GetPrefixLength() const
uint32_t Get() const
Get the host-order 32-bit IP mask.
void Print(std::ostream &os) const
Print this mask to the given output stream.
uint32_t GetInverse() const
Return the inverse mask in host order.
bool IsMatch(Ipv4Address a, Ipv4Address b) const
static Ipv4Mask GetLoopback()
static Ipv4Mask GetZero()
address
Definition: first.py:40
Every class exported by the ns3 library is enclosed in the ns3 namespace.
bool operator!=(Callback< R, Args... > a, Callback< R, Args... > b)
Inequality test.
Definition: callback.h:665
bool operator==(const EventId &a, const EventId &b)
Definition: event-id.h:157
ATTRIBUTE_HELPER_HEADER(ValueClassTest)
std::ostream & operator<<(std::ostream &os, const Angles &a)
Definition: angles.cc:129
std::istream & operator>>(std::istream &is, Angles &a)
Definition: angles.cc:153
bool operator<(const EventId &a, const EventId &b)
Definition: event-id.h:170