Fix connection issue when several network interfaces are connected on the same network

This commit is contained in:
Guillaume Meunier
2025-04-27 16:03:27 +02:00
parent 0ce7662f58
commit 5cf1697c5d
3 changed files with 4 additions and 9 deletions
+2 -7
View File
@@ -80,14 +80,9 @@ wivrn::UDP::UDP(int fd)
this->fd = fd;
}
void wivrn::UDP::bind(int port)
void wivrn::UDP::bind(sockaddr_in6 address)
{
sockaddr_in6 bind_addr{};
bind_addr.sin6_family = AF_INET6;
bind_addr.sin6_addr = IN6ADDR_ANY_INIT;
bind_addr.sin6_port = htons(port);
if (::bind(fd, (sockaddr *)&bind_addr, sizeof(bind_addr)) < 0)
if (::bind(fd, (sockaddr *)&address, sizeof(address)) < 0)
throw std::system_error{errno, std::generic_category()};
}
+1 -1
View File
@@ -127,7 +127,7 @@ public:
void connect(in6_addr address, int port);
void connect(in_addr address, int port);
void bind(int port);
void bind(sockaddr_in6 address);
void subscribe_multicast(in6_addr address);
void unsubscribe_multicast(in6_addr address);
void set_receive_buffer_size(int size);
+1 -1
View File
@@ -94,7 +94,7 @@ void wivrn::wivrn_connection::init(std::stop_token stop_token, std::function<voi
else
{
stream = decltype(stream)();
stream.bind(port);
stream.bind(server_address);
}
auto receive = [&](std::optional<std::chrono::seconds> timeout = std::nullopt, bool allow_stream_socket = false) {