RTP UDP: Resolve rather to IPv4-mapped addrs

This will cause that unless user requests explicitly IPv4, IPv6 socket
accepting also IPv4 traffic will be opened. This fixes potential issues
when host specifies IPv4 address (or hostname resolvable to IPv4), thus
opens IPv4 socket. But the other peer uses IPv6 address of the host
which causes that the host doesn't receive anything.
This commit is contained in:
Martin Pulec
2018-08-30 11:24:56 +02:00
parent 79ce6adb6d
commit e00b7b9472
6 changed files with 8 additions and 7 deletions

View File

@@ -706,7 +706,7 @@ int main(int argc, char **argv)
state.qhead = state.qtail = state.queue = qinit(qsize);
/* input socket */
if ((sock_in = udp_init_if("::1", NULL, params.port, 0, 255, false, false)) == NULL) {
if ((sock_in = udp_init_if("localhost", NULL, params.port, 0, 255, false, false)) == NULL) {
perror("input socket");
return 2;
}

View File

@@ -506,7 +506,7 @@ int main(int argc, char *argv[])
unsigned requested_mtu = 0;
const char *postprocess = NULL;
const char *requested_display = "none";
const char *requested_receiver = "::1";
const char *requested_receiver = "localhost";
const char *requested_encryption = NULL;
struct exporter *exporter = NULL;

View File

@@ -1268,7 +1268,8 @@ static int resolve_address(socket_udp *s, const char *addr, uint16_t tx_port)
memset(&hints, 0, sizeof(hints));
switch (s->local->mode) {
case 0:
hints.ai_family = AF_UNSPEC;
hints.ai_family = AF_INET6;
hints.ai_flags = AI_V4MAPPED | AI_ALL;
break;
case IPv4:
hints.ai_family = AF_INET;
@@ -1454,7 +1455,7 @@ static void udp_clean_async_state(socket_udp *s)
bool udp_is_ipv6(socket_udp *s)
{
return s->local->mode == IPv6;
return s->local->mode == IPv6 && !IN6_IS_ADDR_V4MAPPED(&((struct sockaddr_in6 *) &s->sock)->sin6_addr);
}
bool udp_port_pair_is_free(const char *addr, int force_ip_version, int even_port)

View File

@@ -1212,7 +1212,7 @@ rtp_t rtp_init_with_udp_socket(struct socket_udp_local *l, struct sockaddr *sa,
session->send_rtcp_to_origin = true;
session->rtp_socket = udp_init_with_local(l, sa, len);
session->rtcp_socket = udp_init_if("::1", NULL, 0, 0, ttl, true, false);
session->rtcp_socket = udp_init_if("localhost", NULL, 0, 0, ttl, true, false);
init_opt(session);

View File

@@ -612,7 +612,7 @@ vidcap_rtsp_init(const struct vidcap_params *params, void **state) {
s->should_exit = FALSE;
s->vrtsp_state->device = rtp_init_if("::1", s->vrtsp_state->mcast_if, s->vrtsp_state->port, 0, s->vrtsp_state->ttl, s->vrtsp_state->rtcp_bw,
s->vrtsp_state->device = rtp_init_if("localhost", s->vrtsp_state->mcast_if, s->vrtsp_state->port, 0, s->vrtsp_state->ttl, s->vrtsp_state->rtcp_bw,
0, rtp_recv_callback, (uint8_t *) s->vrtsp_state->participants, 0, true);
if (s->vrtsp_state->device != NULL) {

View File

@@ -116,7 +116,7 @@ static int vidcap_ug_input_init(const struct vidcap_params *cap_params, void **s
//RTP
params["mtu"].i = 9000; // doesn't matter anyway...
// should be localhost and RX TX ports the same (here dynamic) in order to work like a pipe
params["receiver"].ptr = (void *) "::1";
params["receiver"].ptr = (void *) "localhost";
if (isdigit(vidcap_params_get_fmt(cap_params)[0]))
params["rx_port"].i = atoi(vidcap_params_get_fmt(cap_params));
else