From 5cf1697c5d5193e9b2e9d294998b9c011e2c0d96 Mon Sep 17 00:00:00 2001 From: Guillaume Meunier Date: Sun, 27 Apr 2025 16:03:27 +0200 Subject: [PATCH] Fix connection issue when several network interfaces are connected on the same network --- common/wivrn_sockets.cpp | 9 ++------- common/wivrn_sockets.h | 2 +- server/driver/wivrn_connection.cpp | 2 +- 3 files changed, 4 insertions(+), 9 deletions(-) diff --git a/common/wivrn_sockets.cpp b/common/wivrn_sockets.cpp index 139eac3a..52ee823e 100644 --- a/common/wivrn_sockets.cpp +++ b/common/wivrn_sockets.cpp @@ -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()}; } diff --git a/common/wivrn_sockets.h b/common/wivrn_sockets.h index 41899939..ebaeeb04 100644 --- a/common/wivrn_sockets.h +++ b/common/wivrn_sockets.h @@ -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); diff --git a/server/driver/wivrn_connection.cpp b/server/driver/wivrn_connection.cpp index d04be0b3..1c09c6f1 100644 --- a/server/driver/wivrn_connection.cpp +++ b/server/driver/wivrn_connection.cpp @@ -94,7 +94,7 @@ void wivrn::wivrn_connection::init(std::stop_token stop_token, std::function timeout = std::nullopt, bool allow_stream_socket = false) {