]> git.ipfire.org Git - thirdparty/kea.git/commitdiff
[1485] IOAddress.getAddress() removed.
authorTomek Mrugalski <tomasz@isc.org>
Tue, 21 Jan 2014 18:50:41 +0000 (19:50 +0100)
committerTomek Mrugalski <tomasz@isc.org>
Tue, 21 Jan 2014 18:50:41 +0000 (19:50 +0100)
src/lib/asiolink/io_address.cc
src/lib/asiolink/io_address.h
src/lib/asiolink/tests/io_address_unittest.cc

index 798672503c1ece805c9d50e59d131cb9fdbfd48b..6a6ac1855ec4eacd02da342eebc6c2fde3006598 100644 (file)
@@ -100,14 +100,25 @@ IOAddress::getFamily() const {
     }
 }
 
-const asio::ip::address&
-IOAddress::getAddress() const {
-    return asio_address_;
+bool
+IOAddress::isV6LinkLocal() const {
+    if (!asio_address_.is_v6()) {
+        return (false);
+    }
+    return (asio_address_.to_v6().is_link_local());
+}
+
+bool
+IOAddress::isV6Multicast() const {
+    if (!asio_address_.is_v6()) {
+        return (false);
+    }
+    return (asio_address_.to_v6().is_multicast());
 }
 
 IOAddress::operator uint32_t() const {
-    if (getAddress().is_v4()) {
-        return (getAddress().to_v4().to_ulong());
+    if (asio_address_.is_v4()) {
+        return (asio_address_.to_v4().to_ulong());
     } else {
         isc_throw(BadValue, "Can't convert " << toText()
                   << " address to IPv4.");
index 8b18bf65d31897b664c217053cb367dc9973fb19..b44c6e3c54bdf8bbfc557fcc1d599a13f1ac7925 100644 (file)
@@ -91,14 +91,6 @@ public:
     /// \return A string representation of the address.
     std::string toText() const;
 
-    /// \brief Returns const reference to the underlying address object.
-    ///
-    /// This is useful, when access to interface offerted by
-    //  asio::ip::address_v4 and asio::ip::address_v6 is beneficial.
-    /// 
-    /// \return A const reference to asio::ip::address object
-    const asio::ip::address& getAddress() const;
-
     /// \brief Returns the address family
     ///
     /// \return AF_INET for IPv4 or AF_INET6 for IPv6.
@@ -118,6 +110,16 @@ public:
         return (asio_address_.is_v6());
     }
 
+    /// \brief checks whether and address is IPv6 and is link-local
+    ///
+    /// \return true if the address is IPv6 link-local, false otherwise
+    bool isV6LinkLocal() const;
+
+    /// \brief checks whether and address is IPv6 and is multicast
+    ///
+    /// \return true if the address is IPv6 multicast, false otherwise
+    bool isV6Multicast() const;
+
     /// \brief Creates an address from over wire data.
     ///
     /// \param family AF_NET for IPv4 or AF_NET6 for IPv6.
index 5486d5c7af29df63845730382d01625e6136c2e8..50f40278caf2a7410b110997b447011c097be2a2 100644 (file)
@@ -182,3 +182,37 @@ TEST(IOAddressTest, LeftShiftOperator) {
     oss << addr;
     EXPECT_EQ(addr.toText(), oss.str());
 }
+
+// test v6-specific operations
+TEST(IOAddressTest, v6specific) {
+    IOAddress addr1("192.0.2.5"); // IPv4
+    IOAddress addr2("::");  // IPv6
+    IOAddress addr3("2001:db8::1"); // global IPv6
+    IOAddress addr4("fe80::1234");  // link-local
+    IOAddress addr5("ff02::1:2");   // multicast
+
+    EXPECT_TRUE (addr1.isV4());
+    EXPECT_FALSE(addr1.isV6());
+    EXPECT_FALSE(addr1.isV6LinkLocal());
+    EXPECT_FALSE(addr1.isV6Multicast());
+
+    EXPECT_FALSE(addr2.isV4());
+    EXPECT_TRUE (addr2.isV6());
+    EXPECT_FALSE(addr2.isV6LinkLocal());
+    EXPECT_FALSE(addr2.isV6Multicast());
+
+    EXPECT_FALSE(addr3.isV4());
+    EXPECT_TRUE (addr3.isV6());
+    EXPECT_FALSE(addr3.isV6LinkLocal());
+    EXPECT_FALSE(addr3.isV6Multicast());
+
+    EXPECT_FALSE(addr4.isV4());
+    EXPECT_TRUE (addr4.isV6());
+    EXPECT_TRUE (addr4.isV6LinkLocal());
+    EXPECT_FALSE(addr4.isV6Multicast());
+
+    EXPECT_FALSE(addr5.isV4());
+    EXPECT_TRUE (addr5.isV6());
+    EXPECT_FALSE(addr5.isV6LinkLocal());
+    EXPECT_TRUE (addr5.isV6Multicast());
+}