Fix connection issue when several network interfaces are connected on the same network
This commit is contained in:
@@ -80,14 +80,9 @@ wivrn::UDP::UDP(int fd)
|
|||||||
this->fd = fd;
|
this->fd = fd;
|
||||||
}
|
}
|
||||||
|
|
||||||
void wivrn::UDP::bind(int port)
|
void wivrn::UDP::bind(sockaddr_in6 address)
|
||||||
{
|
{
|
||||||
sockaddr_in6 bind_addr{};
|
if (::bind(fd, (sockaddr *)&address, sizeof(address)) < 0)
|
||||||
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)
|
|
||||||
throw std::system_error{errno, std::generic_category()};
|
throw std::system_error{errno, std::generic_category()};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -127,7 +127,7 @@ public:
|
|||||||
|
|
||||||
void connect(in6_addr address, int port);
|
void connect(in6_addr address, int port);
|
||||||
void connect(in_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 subscribe_multicast(in6_addr address);
|
||||||
void unsubscribe_multicast(in6_addr address);
|
void unsubscribe_multicast(in6_addr address);
|
||||||
void set_receive_buffer_size(int size);
|
void set_receive_buffer_size(int size);
|
||||||
|
|||||||
@@ -94,7 +94,7 @@ void wivrn::wivrn_connection::init(std::stop_token stop_token, std::function<voi
|
|||||||
else
|
else
|
||||||
{
|
{
|
||||||
stream = decltype(stream)();
|
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) {
|
auto receive = [&](std::optional<std::chrono::seconds> timeout = std::nullopt, bool allow_stream_socket = false) {
|
||||||
|
|||||||
Reference in New Issue
Block a user