Skip to content

Commit

Permalink
Bind the UDP receive port to the desired address (#302)
Browse files Browse the repository at this point in the history
Binding to INADDR_ANY causes us to receive datagrams destined for our
port to any address, which can be problematic if, for example, there
are different LCM publishers using different multicast addresses and
the same port.

This reverts commit 6b9099a,
reapplying 7606629 but with a WIN32
guard now to retain the INADDR_ANY behavior on windows, as well as
newly applying the same fix to mpudpm.

Co-authored-by: Sam Creasey <sam.creasey@tri.global>
  • Loading branch information
2 people authored and ashuang committed Dec 6, 2019
1 parent f8543c7 commit 2327020
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
6 changes: 6 additions & 0 deletions lcm/lcm_mpudpm.c
Original file line number Diff line number Diff line change
Expand Up @@ -1387,7 +1387,13 @@ static mpudpm_socket_t *add_recv_socket(lcm_mpudpm_t *lcm, uint16_t port)
struct sockaddr_in addr;
memset(&addr, 0, sizeof(addr));
addr.sin_family = AF_INET;
#ifndef WIN32
addr.sin_addr = lcm->params.mc_addr;
#else
// On WIN32 if we try to bind to mc_addr, we get WSAEADDRNOTAVAIL.
// See https://github.com/lcm-proj/lcm/issues/258.
addr.sin_addr.s_addr = INADDR_ANY;
#endif
addr.sin_port = htons(port);

// allow other applications on the local machine to also bind to this
Expand Down
6 changes: 6 additions & 0 deletions lcm/lcm_udpm.c
Original file line number Diff line number Diff line change
Expand Up @@ -895,7 +895,13 @@ static int _setup_recv_parts(lcm_udpm_t *lcm)
struct sockaddr_in addr;
memset(&addr, 0, sizeof(addr));
addr.sin_family = AF_INET;
#ifndef WIN32
addr.sin_addr = lcm->params.mc_addr;
#else
// On WIN32 if we try to bind to mc_addr, we get WSAEADDRNOTAVAIL.
// See https://github.com/lcm-proj/lcm/issues/258.
addr.sin_addr.s_addr = INADDR_ANY;
#endif
addr.sin_port = lcm->params.mc_port;

// allow other applications on the local machine to also bind to this
Expand Down

0 comments on commit 2327020

Please sign in to comment.