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

emulation on host: enable and fix multicast udp server #7386

Merged
merged 1 commit into from
Jun 16, 2020
Merged
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
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