udp*: multicast join work with specific addresses

Remove unused sockaddr size argument, and pass address using specific struct

Signed-off-by: Rafaël Carré <funman@videolan.org>
master
Rafaël Carré 2018-06-25 15:06:33 +02:00 committed by Richard Cochran
parent ee2a9d4ac9
commit 5219b6417f
2 changed files with 6 additions and 9 deletions

8
udp.c
View File

@ -62,12 +62,10 @@ static int mcast_bind(int fd, int index)
return 0; return 0;
} }
static int mcast_join(int fd, int index, const struct sockaddr *grp, static int mcast_join(int fd, int index, const struct sockaddr_in *sa)
socklen_t grplen)
{ {
int err, off = 0; int err, off = 0;
struct ip_mreqn req; struct ip_mreqn req;
struct sockaddr_in *sa = (struct sockaddr_in *) grp;
memset(&req, 0, sizeof(req)); memset(&req, 0, sizeof(req));
memcpy(&req.imr_multiaddr, &sa->sin_addr, sizeof(struct in_addr)); memcpy(&req.imr_multiaddr, &sa->sin_addr, sizeof(struct in_addr));
@ -129,12 +127,12 @@ static int open_socket(const char *name, struct in_addr mc_addr[2], short port,
goto no_option; goto no_option;
} }
addr.sin_addr = mc_addr[0]; 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"); pr_err("mcast_join failed");
goto no_option; goto no_option;
} }
addr.sin_addr = mc_addr[1]; 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"); pr_err("mcast_join failed");
goto no_option; goto no_option;
} }

7
udp6.c
View File

@ -68,11 +68,10 @@ static int mc_bind(int fd, int index)
return 0; 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; int err, off = 0;
struct ipv6_mreq req; struct ipv6_mreq req;
struct sockaddr_in6 *sa = (struct sockaddr_in6 *) grp;
memset(&req, 0, sizeof(req)); memset(&req, 0, sizeof(req));
memcpy(&req.ipv6mr_multiaddr, &sa->sin6_addr, sizeof(struct in6_addr)); memcpy(&req.ipv6mr_multiaddr, &sa->sin6_addr, sizeof(struct in6_addr));
@ -137,12 +136,12 @@ static int open_socket_ipv6(const char *name, struct in6_addr mc_addr[2], short
goto no_option; goto no_option;
} }
addr.sin6_addr = mc_addr[0]; 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"); pr_err("mcast_join failed");
goto no_option; goto no_option;
} }
addr.sin6_addr = mc_addr[1]; 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"); pr_err("mcast_join failed");
goto no_option; goto no_option;
} }