Skip to content

Commit

Permalink
udp-server: set REUSEADDR socket option when joining multicast group
Browse files Browse the repository at this point in the history
  • Loading branch information
DanMesh committed Mar 1, 2024
1 parent 86b6aea commit 517e91a
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions include/mav/UDPServer.h
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,12 @@ namespace mav {
}

void joinMulticastGroup(const std::string& multicast_group, const std::string& local_address="") const {
int reuse = 1;
if (setsockopt(_socket, SOL_SOCKET, SO_REUSEADDR, &reuse, sizeof(reuse)) < 0) {
::close(_socket);
throw NetworkError("Could not join multicast group (could not enable SO_REUSEADDR)", errno);
}

struct ip_mreq mreq{};
mreq.imr_multiaddr.s_addr = inet_addr(multicast_group.c_str());
mreq.imr_interface.s_addr = local_address.empty() ? INADDR_ANY : inet_addr(local_address.c_str());
Expand Down

0 comments on commit 517e91a

Please sign in to comment.