Skip to content

Commit

Permalink
Merge pull request #44 from Auterion/multicast-reuseaddr
Browse files Browse the repository at this point in the history
Set REUSEADDR socket option when joining multicast group
  • Loading branch information
ThomasDebrunner authored Mar 14, 2024
2 parents ad35187 + 517e91a commit d238f66
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 d238f66

Please sign in to comment.