Skip to content

Commit

Permalink
emulation on host: lwIP always receive multicast packets, enable and …
Browse files Browse the repository at this point in the history
…fix multicast udp server (#7386)
  • Loading branch information
d-a-v committed Jun 16, 2020
1 parent 64f1f7b commit 448486a
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions tests/host/common/UdpContextSocket.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,8 @@ bool mockUDPListen (int sock, uint32_t dstaddr, uint16_t port, uint32_t mcast)
// Filling server information
servaddr.sin_family = AF_INET;
(void) dstaddr;
servaddr.sin_addr.s_addr = htonl(global_source_address);
//servaddr.sin_addr.s_addr = htonl(global_source_address);
servaddr.sin_addr.s_addr = htonl(INADDR_ANY);
servaddr.sin_port = htons(mockport);

// Bind the socket with the server address
Expand All @@ -89,15 +90,19 @@ bool mockUDPListen (int sock, uint32_t dstaddr, uint16_t port, uint32_t mcast)
else
mockverbose("UDP server on port %d (sock=%d)\n", mockport, sock);

if (!mcast)
mcast = inet_addr("224.0.0.1"); // all hosts group
if (mcast)
{
// https://web.cs.wpi.edu/~claypool/courses/4514-B99/samples/multicast.c
// https://stackoverflow.com/questions/12681097/c-choose-interface-for-udp-multicast-socket

struct ip_mreq mreq;
mreq.imr_multiaddr.s_addr = mcast;
mreq.imr_interface.s_addr = htonl(global_source_address);
if (global_ipv4_netfmt)
//mreq.imr_interface.s_addr = htonl(global_source_address);
mreq.imr_interface.s_addr = htonl(INADDR_ANY);

if (host_interface)
{
#if __APPLE__
int idx = if_nametoindex(host_interface);
Expand All @@ -115,6 +120,8 @@ bool mockUDPListen (int sock, uint32_t dstaddr, uint16_t port, uint32_t mcast)
fprintf(stderr, MOCK "can't join multicast group addr %08x\n", (int)mcast);
return false;
}
else
mockverbose("joined multicast group addr %08lx\n", ntohl(mcast));
}

return true;
Expand Down

0 comments on commit 448486a

Please sign in to comment.