Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed a bug that caused a deadlock when binding to an IP that is not assigned to any network interface. #15

Merged
merged 1 commit into from
Apr 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions tests/udpcap_test/src/udpcap_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,30 @@ TEST(udpcap, RAIIWithSomebodyWaiting)
// Delete the socket
}

// Test the return value of a bind with an invalid address
TEST(udpcap, BindInvalidAddress)
{
// Create a udpcap socket
Udpcap::UdpcapSocket udpcap_socket;
ASSERT_TRUE(udpcap_socket.isValid());

// bind the socket
const bool success = udpcap_socket.bind(Udpcap::HostAddress("256.0.0.1"), 14000);
ASSERT_FALSE(success);
}

// Test the return value of a bind with a valid address that however doesn't belong to any network interface
TEST(udpcap, BindInvalidAddress2)
{
// Create a udpcap socket
Udpcap::UdpcapSocket udpcap_socket;
ASSERT_TRUE(udpcap_socket.isValid());

// bind the socket
const bool success = udpcap_socket.bind(Udpcap::HostAddress("239.0.0.1"), 14000); // This is a multicast address that cannot be bound to
ASSERT_FALSE(success);
}

// Receive a simple Hello World Message
TEST(udpcap, SimpleReceive)
{
Expand Down
5 changes: 0 additions & 5 deletions udpcap/src/udpcap_socket_private.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,6 @@ namespace Udpcap
if (!openPcapDevice_nolock(GetLoopbackDeviceName()))
{
LOG_DEBUG(std::string("Bind error: Unable to bind to ") + GetLoopbackDeviceName());
close();
return false;
}
}
Expand All @@ -121,7 +120,6 @@ namespace Udpcap
if (devices.empty())
{
LOG_DEBUG("Bind error: No devices found");
close();
return false;
}

Expand All @@ -143,7 +141,6 @@ namespace Udpcap
if (dev.first.empty())
{
LOG_DEBUG("Bind error: No local device with address " + local_address.toString());
close();
return false;
}

Expand All @@ -152,7 +149,6 @@ namespace Udpcap
if (!openPcapDevice_nolock(dev.first))
{
LOG_DEBUG(std::string("Bind error: Unable to bind to ") + dev.first);
close();
return false;
}

Expand All @@ -162,7 +158,6 @@ namespace Udpcap
if (!openPcapDevice_nolock(GetLoopbackDeviceName()))
{
LOG_DEBUG(std::string("Bind error: Unable to open ") + GetLoopbackDeviceName());
close();
return false;
}
}
Expand Down
2 changes: 1 addition & 1 deletion udpcap/version.cmake
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
set(UDPCAP_VERSION_MAJOR 2)
set(UDPCAP_VERSION_MINOR 0)
set(UDPCAP_VERSION_PATCH 0)
set(UDPCAP_VERSION_PATCH 1)