]> git.ipfire.org Git - thirdparty/kea.git/commitdiff
[1959] Test opening socket from remote broadcast address on Linux only.
authorMarcin Siodelski <marcin@isc.org>
Wed, 12 Sep 2012 09:16:17 +0000 (11:16 +0200)
committerMarcin Siodelski <marcin@isc.org>
Wed, 12 Sep 2012 09:18:07 +0000 (11:18 +0200)
In order to run this test interface detection is required. Since it is
right now implemented on Linux only it had to be disabled on every other
OS.

src/lib/dhcp/iface_mgr.cc
src/lib/dhcp/tests/iface_mgr_unittest.cc

index 9c03794c2d30340a3a12ed89438f9d25aecc3906..be17b09b5d8e480c2298e5c1d7685d26a392595a 100644 (file)
@@ -513,6 +513,7 @@ IfaceMgr::getLocalAddress(const IOAddress& remote_addr, const uint16_t port) {
         }
         sock.set_option(asio::socket_base::broadcast(true), err_code);
         if (err_code) {
+            sock.close();
             isc_throw(Unexpected, "failed to enable broadcast on the socket");
         }
     }
@@ -520,6 +521,7 @@ IfaceMgr::getLocalAddress(const IOAddress& remote_addr, const uint16_t port) {
     // Try to connect to remote endpoint and check if attempt is successful.
     sock.connect(remote_endpoint->getASIOEndpoint(), err_code);
     if (err_code) {
+        sock.close();
         isc_throw(Unexpected,"failed to connect to remote endpoint.");
     }
 
@@ -528,6 +530,9 @@ IfaceMgr::getLocalAddress(const IOAddress& remote_addr, const uint16_t port) {
         sock.local_endpoint();
     asio::ip::address local_address(local_endpoint.address());
 
+    // Close the socket.
+    sock.close();
+
     // Return address of local endpoint.
     return IOAddress(local_address);
 }
index 7f8555c1fa92c3a083a1da4f02bcfa1cef8f645e..ad8dba905beb3deec7e4cc085ba3135c84fc7185 100644 (file)
@@ -407,6 +407,11 @@ TEST_F(IfaceMgrTest, socketsFromRemoteAddress) {
     EXPECT_GT(socket2, 0);
     close(socket2);
 
+    // The following test is currently disabled for OSes other than
+    // Linux because interface detection is not implemented on them.
+    // @todo enable this test for all OSes once interface detection
+    // is implemented.
+#if defined(OS_LINUX)
     // Open v4 socket to connect to broadcast address.
     int socket3  = 0;
     IOAddress bcastAddr("255.255.255.255");
@@ -415,6 +420,7 @@ TEST_F(IfaceMgrTest, socketsFromRemoteAddress) {
     );
     EXPECT_GT(socket3, 0);
     close(socket3);
+#endif
 }
 
 // TODO: disabled due to other naming on various systems