diff --git a/include/tins/ip_address.h b/include/tins/ip_address.h index b0058fb..8db32ec 100644 --- a/include/tins/ip_address.h +++ b/include/tins/ip_address.h @@ -32,10 +32,10 @@ #include #include +#include #include #include #include -#include namespace Tins { /** @@ -181,6 +181,15 @@ public: * \brief Returns true if this is a broadcast IPv4 address. */ bool is_broadcast() const; + + /** + * \brief Returns the size of an IPv4 Address. + * + * This returns the value of IPv4Address::address_size + */ + size_t size() const { + return address_size; + } /** * \brief Writes this address to a std::ostream. diff --git a/include/tins/ipv6_address.h b/include/tins/ipv6_address.h index 9689ffd..43d4995 100644 --- a/include/tins/ipv6_address.h +++ b/include/tins/ipv6_address.h @@ -196,6 +196,15 @@ public: * ff00::/8, false otherwise. */ bool is_multicast() const; + + /** + * \brief Returns the size of an IPv6 Address. + * + * This returns the value of IPv6Address::address_size + */ + size_t size() const { + return address_size; + } /** * \brief Writes this address in hex-notation to a std::ostream. diff --git a/tests/src/ip_address_test.cpp b/tests/src/ip_address_test.cpp index 32a6a62..e43b186 100644 --- a/tests/src/ip_address_test.cpp +++ b/tests/src/ip_address_test.cpp @@ -111,3 +111,8 @@ TEST(IPAddressTest, Mask) { IPv4Address("192.255.1.2") & IPv4Address("255.128.0.0") ); } + +TEST(IPv4AddressTest, Size) { + EXPECT_EQ(4, IPv4Address("127.0.0.1").size()); + EXPECT_EQ(4, IPv4Address().size()); +} diff --git a/tests/src/ipv6_address_test.cpp b/tests/src/ipv6_address_test.cpp index ac001dc..50a77f8 100644 --- a/tests/src/ipv6_address_test.cpp +++ b/tests/src/ipv6_address_test.cpp @@ -124,6 +124,11 @@ TEST(IPv6AddressTest, MaskAddress) { ); } +TEST(IPv6AddressTest, Size) { + EXPECT_EQ(16, IPv6Address("dead:beef::1").size()); + EXPECT_EQ(16, IPv6Address().size()); +} + #if TINS_IS_CXX11 TEST(IPv6AddressTest, HashTest) {