11#include "ns3/assert.h"
20#include <sys/socket.h>
44 auto plen =
static_cast<uint32_t>(std::atoi(++mask));
48 m_mask = 0xffffffff << (32 - plen);
57 if (inet_pton(AF_INET, mask, &
m_mask) <= 0)
59 NS_ABORT_MSG(
"Error, can not build an IPv4 mask from an invalid string: " << mask);
97 os << ((
m_mask >> 24) & 0xff) <<
"." << ((
m_mask >> 16) & 0xff) <<
"." << ((
m_mask >> 8) & 0xff)
98 <<
"." << ((
m_mask >> 0) & 0xff);
105 static Ipv4Mask loopback(
"255.0.0.0");
121 static Ipv4Mask ones(
"255.255.255.255");
149 if (inet_pton(AF_INET, address, &
m_address) <= 0)
151 NS_ABORT_MSG(
"Error, can not build an IPv4 address from an invalid string: " << address);
164 if (inet_pton(AF_INET, addressStr.c_str(), &buffer) <= 0)
166 NS_LOG_WARN(
"Error, can not build an IPv4 address from an invalid string: " << addressStr);
190 if (inet_pton(AF_INET, address, &
m_address) <= 0)
192 NS_ABORT_MSG(
"Error, can not build an IPv4 address from an invalid string: " << address);
212 "Trying to get subnet-directed broadcast address with an all-ones netmask");
274 return (
m_address & 0xffffff00) == 0xe0000000;
282 return (
m_address & 0xffff0000) == 0xa9fe0000;
301 ipv4.m_address |= buf[0];
302 ipv4.m_address <<= 8;
303 ipv4.m_address |= buf[1];
304 ipv4.m_address <<= 8;
305 ipv4.m_address |= buf[2];
306 ipv4.m_address <<= 8;
307 ipv4.m_address |= buf[3];
324 return address.CheckCompatible(
GetType(), 4);
395 return std::hash<uint32_t>()(
x.Get());
cairo_uint64_t x
_cairo_uint_96by64_32x64_divrem:
a polymophic address class
static uint8_t Register(const std::string &kind, uint8_t length)
Allocate a new type id for a new type of address.
size_t operator()(const Ipv4Address &x) const
Returns the hash of an IPv4 address.
Ipv4 addresses are stored in host order in this class.
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.
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.
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.
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).
uint32_t m_address
IPv4 address.
Address ConvertTo() const
Convert to an Address type.
static Ipv4Address GetAny()
static bool CheckCompatible(const std::string &addressStr)
Checks if the string contains an Ipv4Address.
bool IsInitialized() const
bool IsLocalMulticast() const
bool IsLinkLocal() const
If the IPv4 address is an APIPA address (169.254/16).
a class to represent an Ipv4 address mask
static Ipv4Mask GetOnes()
void Set(uint32_t mask)
input mask is in host order.
Ipv4Mask()
Will initialize to a zero-length mask, which will match any address.
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()
#define NS_ASSERT(condition)
At runtime, in debugging builds, if this condition is not true, the program prints the source file,...
#define NS_ASSERT_MSG(condition, message)
At runtime, in debugging builds, if this condition is not true, the program prints the message to out...
#define ATTRIBUTE_HELPER_CPP(type)
Define the attribute value, accessor and checkers for class type.
#define NS_ABORT_MSG(msg)
Unconditional abnormal program termination with a message.
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
#define NS_LOG_FUNCTION_NOARGS()
Output the name of the function.
#define NS_LOG_FUNCTION(parameters)
If log level LOG_FUNCTION is enabled, this macro will output all input parameters separated by ",...
#define NS_LOG_WARN(msg)
Use NS_LOG to output a message of level LOG_WARN.
Every class exported by the ns3 library is enclosed in the ns3 namespace.
std::ostream & operator<<(std::ostream &os, const Angles &a)
std::istream & operator>>(std::istream &is, Angles &a)