rtp-sap: make the receive socket listen only to the configured sap.ip

In line also with da8e207de9,
make sure that the rtp-sap receive socket listens only to the configured
sap.ip in unicast mode, instead of accepting all packets on the port.

This additionally fixes breakage that was inadvertently introduced in
f2f204d604. Because the
`struct sockaddr_storage *sa` argument in `make_recv_socket` points
to `impl->sap_addr`, changing the address to INADDR_ANY in the unicast
code path would also silently cause the sender socket to try to
connect to INADDR_ANY and fail.
This commit is contained in:
George Kiagiadakis 2024-09-24 20:17:34 +03:00 committed by Wim Taymans
parent 88dff1c021
commit fbbe983a05

View file

@ -455,6 +455,8 @@ static int make_recv_socket(struct sockaddr_storage *sa, socklen_t salen,
{
int af, fd, val, res;
struct ifreq req;
struct sockaddr_storage ba = *sa;
bool do_connect = false;
char addr[128];
af = sa->ss_family;
@ -488,7 +490,11 @@ static int make_recv_socket(struct sockaddr_storage *sa, socklen_t salen,
pw_log_info("join IPv4 group: %s iface:%d", addr, req.ifr_ifindex);
res = setsockopt(fd, IPPROTO_IP, IP_ADD_MEMBERSHIP, &mr4, sizeof(mr4));
} else {
sa4->sin_addr.s_addr = INADDR_ANY;
struct sockaddr_in *ba4 = (struct sockaddr_in*)&ba;
if (ba4->sin_addr.s_addr != INADDR_ANY) {
ba4->sin_addr.s_addr = INADDR_ANY;
do_connect = true;
}
}
} else if (af == AF_INET6) {
struct sockaddr_in6 *sa6 = (struct sockaddr_in6*)sa;
@ -501,7 +507,8 @@ static int make_recv_socket(struct sockaddr_storage *sa, socklen_t salen,
pw_log_info("join IPv6 group: %s iface:%d", addr, req.ifr_ifindex);
res = setsockopt(fd, IPPROTO_IPV6, IPV6_JOIN_GROUP, &mr6, sizeof(mr6));
} else {
sa6->sin6_addr = in6addr_any;
struct sockaddr_in6 *ba6 = (struct sockaddr_in6*)&ba;
ba6->sin6_addr = in6addr_any;
}
} else {
res = -EINVAL;
@ -514,11 +521,18 @@ static int make_recv_socket(struct sockaddr_storage *sa, socklen_t salen,
goto error;
}
if (bind(fd, (struct sockaddr*)sa, salen) < 0) {
if (bind(fd, (struct sockaddr*)&ba, salen) < 0) {
res = -errno;
pw_log_error("bind() failed: %m");
goto error;
}
if (do_connect) {
if (connect(fd, (struct sockaddr*)sa, salen) < 0) {
res = -errno;
pw_log_error("connect() failed: %m");
goto error;
}
}
return fd;
error:
close(fd);