allow Ipv4Mask constructor to accept a string /32, /24 etc. in constructor

This commit is contained in:
Tom Henderson committed 2009-08-22 15:32:30 -07:00
1 parent 291bd3db0c
commit aafcc03403
3 files changed
+28 -3

No files matched your search

+11 -1
View File
@@ -28,6 +28,7 @@ namespace ns3 {
#define ASCII_DOT (0x2e)
#define ASCII_ZERO (0x30)
#define ASCII_SLASH (0x2f)
static uint32_t
AsciiToIpv4Host (char const *address)
@@ -63,9 +64,18 @@ Ipv4Mask::Ipv4Mask ()
Ipv4Mask::Ipv4Mask (uint32_t mask)
: m_mask (mask)
{}
Ipv4Mask::Ipv4Mask (char const *mask)
{
m_mask = AsciiToIpv4Host (mask);
if (*mask == ASCII_SLASH)
{
m_mask = static_cast<uint32_t> (atoi (++mask));
NS_ASSERT (m_mask <= 32);
}
else
{
m_mask = AsciiToIpv4Host (mask);
}
}
bool
+15
View File
@@ -198,11 +198,26 @@ private:
* \ingroup address
*
* \brief a class to represent an Ipv4 address mask
*
* The constructor takes arguments according to a few formats.
* Ipv4Mask ("255.255.255.255"), Ipv4Mask ("/32"), and Ipv4Mask (0xffffffff)
* are all equivalent.
*/
class Ipv4Mask {
public:
/**
* Will initialize to a garbage value (0x66666666)
*/
Ipv4Mask ();
/**
* param mask bitwise integer representation of the mask
*
* For example, the integer input 0xffffff00 yields a 24-bit mask
*/
Ipv4Mask (uint32_t mask);
/**
* \param mask String constant either in "255.255.255.0" or "/24" format
*/
Ipv4Mask (char const *mask);
/**
* \param a first address to compare