From 291bd3db0c817ed752cd140c043de5bc502a7245 Mon Sep 17 00:00:00 2001 From: Antti Makela Date: Sat, 22 Aug 2009 14:58:27 -0700 Subject: [PATCH] [bug 634] patch to grab prefix length from Ipv4Mask --- src/node/ipv4-address.cc | 14 ++++++++++++++ src/node/ipv4-address.h | 4 ++++ 2 files changed, 18 insertions(+) diff --git a/src/node/ipv4-address.cc b/src/node/ipv4-address.cc index 28d26838d..d55e187f8 100644 --- a/src/node/ipv4-address.cc +++ b/src/node/ipv4-address.cc @@ -133,6 +133,20 @@ Ipv4Mask::GetOnes (void) return ones; } +uint16_t +Ipv4Mask::GetPrefixLength (void) const +{ + uint16_t tmp = 0; + uint32_t mask = m_mask; + while (mask != 0 ) + { + mask = mask << 1; + tmp++; + } + return tmp; +} + + Ipv4Address::Ipv4Address () : m_address (0x66666666) {} diff --git a/src/node/ipv4-address.h b/src/node/ipv4-address.h index ad6a0c5e9..1f3a9cfb7 100644 --- a/src/node/ipv4-address.h +++ b/src/node/ipv4-address.h @@ -237,6 +237,10 @@ public: * \param os The output stream to which this Ipv4Address is printed */ void Print (std::ostream &os) const; + /** + * \return the prefix length of mask (the yy in x.x.x.x/yy notation) + */ + uint16_t GetPrefixLength (void) const; /** * \return the 255.0.0.0 mask corresponding to a typical loopback address */