23 #include "ipv4-address.h"
24 #include "ns3/assert.h"
30 #define ASCII_DOT (0x2e)
31 #define ASCII_ZERO (0x30)
32 #define ASCII_SLASH (0x2f)
35 AsciiToIpv4Host (
char const *address)
42 while (*address != ASCII_DOT && *address != 0)
45 byte += *address - ASCII_ZERO;
79 if (*mask == ASCII_SLASH)
81 uint32_t plen =
static_cast<uint32_t
> (std::atoi (++mask));
85 m_mask = 0xffffffff << (32 - plen);
94 m_mask = AsciiToIpv4Host (mask);
102 if (other.m_mask == m_mask) {
113 if ((a.
Get () & m_mask) == (b.
Get () & m_mask)) {
143 os << ((m_mask >> 24) & 0xff) <<
"."
144 << ((m_mask >> 16) & 0xff) <<
"."
145 << ((m_mask >> 8) & 0xff) <<
"."
146 << ((m_mask >> 0) & 0xff);
177 uint32_t mask = m_mask;
187 Ipv4Address::Ipv4Address ()
188 : m_address (0x66666666)
192 Ipv4Address::Ipv4Address (uint32_t address)
197 Ipv4Address::Ipv4Address (
char const *address)
200 m_address = AsciiToIpv4Host (address);
219 m_address = AsciiToIpv4Host (address);
235 NS_ASSERT_MSG (
false,
"Trying to get subnet-directed broadcast address with an all-ones netmask");
257 return (m_address == 0xffffffffU);
268 return (m_address >= 0xe0000000 && m_address <= 0xefffffff);
276 return (m_address & 0xffffff00) == 0xe0000000;
283 buf[0] = (m_address >> 24) & 0xff;
284 buf[1] = (m_address >> 16) & 0xff;
285 buf[2] = (m_address >> 8) & 0xff;
286 buf[3] = (m_address >> 0) & 0xff;
294 ipv4.m_address |= buf[0];
295 ipv4.m_address <<= 8;
296 ipv4.m_address |= buf[1];
297 ipv4.m_address <<= 8;
298 ipv4.m_address |= buf[2];
299 ipv4.m_address <<= 8;
300 ipv4.m_address |= buf[3];
308 os << ((m_address >> 24) & 0xff) <<
"."
309 << ((m_address >> 16) & 0xff) <<
"."
310 << ((m_address >> 8) & 0xff) <<
"."
311 << ((m_address >> 0) & 0xff);
326 Ipv4Address::ConvertTo (
void)
const
331 return Address (GetType (), buf, 4);
345 Ipv4Address::GetType (
void)
381 size_t Ipv4AddressHash::operator() (
Ipv4Address const &x)
const
386 std::ostream&
operator<< (std::ostream& os, Ipv4Address
const& address)
391 std::ostream&
operator<< (std::ostream& os, Ipv4Mask
const& mask)
396 std::istream &
operator >> (std::istream &is, Ipv4Address &address)
400 address = Ipv4Address (str.c_str ());
403 std::istream &
operator >> (std::istream &is, Ipv4Mask &mask)
407 mask = Ipv4Mask (str.c_str ());
411 bool operator == (Ipv4Mask
const &a, Ipv4Mask
const &b)
413 return a.IsEqual (b);
415 bool operator != (Ipv4Mask
const &a, Ipv4Mask
const &b)
417 return !a.IsEqual (b);
static Ipv4Address Deserialize(const uint8_t buf[4])
std::istream & operator>>(std::istream &is, Angles &a)
static Ipv4Mask GetOnes(void)
static Ipv4Address GetAny(void)
#define NS_LOG_FUNCTION(parameters)
bool IsMatch(Ipv4Address a, Ipv4Address b) const
a class to represent an Ipv4 address mask
bool IsLocalMulticast(void) const
#define NS_ASSERT(condition)
#define NS_LOG_COMPONENT_DEFINE(name)
bool IsMulticast(void) const
Ipv4Address CombineMask(Ipv4Mask const &mask) const
Combine this address with a network mask.
#define NS_LOG_FUNCTION_NOARGS()
Ipv4Address GetSubnetDirectedBroadcast(Ipv4Mask const &mask) const
Generate subnet-directed broadcast address corresponding to mask.
a polymophic address class
bool CheckCompatible(uint8_t type, uint8_t len) const
bool IsSubnetDirectedBroadcast(Ipv4Mask const &mask) const
Generate subnet-directed broadcast address corresponding to mask.
static Ipv4Mask GetZero(void)
bool IsBroadcast(void) const
void Serialize(uint8_t buf[4]) const
void Print(std::ostream &os) const
Print this address to the given output stream.
static bool IsMatchingType(const Address &address)
static Ipv4Address GetBroadcast(void)
std::ostream & operator<<(std::ostream &os, const Angles &a)
#define ATTRIBUTE_HELPER_CPP(type)
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)
#define NS_ASSERT_MSG(condition, message)
void Set(uint32_t address)
Ipv4 addresses are stored in host order in this class.
uint32_t CopyTo(uint8_t buffer[MAX_SIZE]) const
bool IsEqual(Ipv4Mask other) const
static Ipv4Address ConvertFrom(const Address &address)
uint32_t GetInverse(void) const
Return the inverse mask in host order.
static uint8_t Register(void)
uint16_t GetPrefixLength(void) const