// make sure the ifr.ifr_name has enough room to receive the network
     // interface name
     size_t network_interface_name_limit = sizeof(ifr.ifr_name);
-    if ( network_interface_name_limit > SourceNetworkInterfaceName.size() )
+    if ( network_interface_name_limit <= SourceNetworkInterfaceName.size() )
     {
-        strncpy( ifr.ifr_name, SourceNetworkInterfaceName.c_str(), network_interface_name_limit );
-        ifr.ifr_addr.sa_family = AF_INET; // TODO change to AF_INET6 when IPv6
+        GlobalLogger.error() << "Error: network interface name truncated" << endl;
+        return 0;
+    }
 
-        int ioctl_resp = ioctl( Socket.native(), SIOCGIFADDR, &ifr );
-        if ( ioctl_resp == 0)
-        {
-            const sockaddr_in *source_sockaddr = reinterpret_cast<const sockaddr_in *>( &ifr.ifr_addr );
-            uint32_t source_ipv4_address = htonl( source_sockaddr->sin_addr.s_addr );
+    strncpy( ifr.ifr_name, SourceNetworkInterfaceName.c_str(), network_interface_name_limit );
+    ifr.ifr_addr.sa_family = AF_INET; // TODO change to AF_INET6 when IPv6
 
-            return source_ipv4_address;
-        }
-    }
-    else
+    int ioctl_resp = ioctl( Socket.native(), SIOCGIFADDR, &ifr );
+    if ( ioctl_resp != 0)
     {
-        GlobalLogger.error() << "Error: network interface name truncated" << endl;
+        GlobalLogger.error() << "Error: could not retrieve IP address from network interface" << endl;
+        return 0;
     }
 
-    return 0;
+    const sockaddr_in *source_sockaddr = reinterpret_cast<const sockaddr_in *>( &ifr.ifr_addr );
+    uint32_t source_ipv4_address = htonl( source_sockaddr->sin_addr.s_addr );
+
+    return source_ipv4_address;
 }
 
 uint32_t TcpPinger::get_destination_address() const