Skip to content

Commit

Permalink
udp*: multicast join work with specific addresses
Browse files Browse the repository at this point in the history
Remove unused sockaddr size argument, and pass address using specific struct

Signed-off-by: Rafaël Carré <[email protected]>
  • Loading branch information
funman authored and richardcochran committed Jun 25, 2018
1 parent ee2a9d4 commit 5219b64
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 9 deletions.
8 changes: 3 additions & 5 deletions udp.c
Original file line number Diff line number Diff line change
Expand Up @@ -62,12 +62,10 @@ static int mcast_bind(int fd, int index)
return 0;
}

static int mcast_join(int fd, int index, const struct sockaddr *grp,
socklen_t grplen)
static int mcast_join(int fd, int index, const struct sockaddr_in *sa)
{
int err, off = 0;
struct ip_mreqn req;
struct sockaddr_in *sa = (struct sockaddr_in *) grp;

memset(&req, 0, sizeof(req));
memcpy(&req.imr_multiaddr, &sa->sin_addr, sizeof(struct in_addr));
Expand Down Expand Up @@ -129,12 +127,12 @@ static int open_socket(const char *name, struct in_addr mc_addr[2], short port,
goto no_option;
}
addr.sin_addr = mc_addr[0];
if (mcast_join(fd, index, (struct sockaddr *) &addr, sizeof(addr))) {
if (mcast_join(fd, index, &addr)) {
pr_err("mcast_join failed");
goto no_option;
}
addr.sin_addr = mc_addr[1];
if (mcast_join(fd, index, (struct sockaddr *) &addr, sizeof(addr))) {
if (mcast_join(fd, index, &addr)) {
pr_err("mcast_join failed");
goto no_option;
}
Expand Down
7 changes: 3 additions & 4 deletions udp6.c
Original file line number Diff line number Diff line change
Expand Up @@ -68,11 +68,10 @@ static int mc_bind(int fd, int index)
return 0;
}

static int mc_join(int fd, int index, const struct sockaddr *grp, socklen_t grplen)
static int mc_join(int fd, int index, const struct sockaddr_in6 *sa)
{
int err, off = 0;
struct ipv6_mreq req;
struct sockaddr_in6 *sa = (struct sockaddr_in6 *) grp;

memset(&req, 0, sizeof(req));
memcpy(&req.ipv6mr_multiaddr, &sa->sin6_addr, sizeof(struct in6_addr));
Expand Down Expand Up @@ -137,12 +136,12 @@ static int open_socket_ipv6(const char *name, struct in6_addr mc_addr[2], short
goto no_option;
}
addr.sin6_addr = mc_addr[0];
if (mc_join(fd, index, (struct sockaddr *) &addr, sizeof(addr))) {
if (mc_join(fd, index, &addr)) {
pr_err("mcast_join failed");
goto no_option;
}
addr.sin6_addr = mc_addr[1];
if (mc_join(fd, index, (struct sockaddr *) &addr, sizeof(addr))) {
if (mc_join(fd, index, &addr)) {
pr_err("mcast_join failed");
goto no_option;
}
Expand Down

0 comments on commit 5219b64

Please sign in to comment.