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

fix crash on macos on network interface change #225

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
16 changes: 13 additions & 3 deletions src/resolve_attempt_udp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#include <asio/ip/address.hpp>
#include <asio/ip/multicast.hpp>
#include <exception>
#include <iostream>
#include <loguru.hpp>
#include <sstream>

Expand All @@ -33,12 +34,15 @@ resolve_attempt_udp::resolve_attempt_udp(asio::io_context &io, const udp &protoc
e.what());
}
unicast_socket_.open(protocol);


try {
broadcast_socket_.open(protocol);
broadcast_socket_.set_option(asio::socket_base::broadcast(true));
} catch (std::exception &e) {
LOG_F(WARNING, "Cannot open UDP broadcast socket for resolves: %s", e.what());
}

try {
multicast_socket_.open(protocol);
multicast_socket_.set_option(
Expand Down Expand Up @@ -165,9 +169,15 @@ void resolve_attempt_udp::send_next_query(
// Mismatching protocols? Skip this round
if (mcit->addr.is_v4() != (proto == asio::ip::udp::v4()))
next = targets_.end();
else
multicast_socket_.set_option(mcit->addr.is_v4() ? outbound_interface(mcit->addr.to_v4())
: outbound_interface(mcit->ifindex));
else {
try {
multicast_socket_.set_option(mcit->addr.is_v4() ? outbound_interface(mcit->addr.to_v4())
: outbound_interface(mcit->ifindex));
} catch (std::exception &e) {
LOG_F(INFO, "Could not set multicast interface: %s", e.what());
next = targets_.end();
}
}
}
if (next != targets_.end()) {
udp::endpoint ep(*next++);
Expand Down