diff options
Diffstat (limited to 'libavformat/udp.c')
-rw-r--r-- | libavformat/udp.c | 14 |
1 files changed, 9 insertions, 5 deletions
diff --git a/libavformat/udp.c b/libavformat/udp.c index d3e4d906a7..cfc5ae51db 100644 --- a/libavformat/udp.c +++ b/libavformat/udp.c @@ -473,13 +473,16 @@ static int udp_open(URLContext *h, const char *uri, int flags) goto fail; } - /* the bind is needed to give a port to the socket now */ - /* if multicast, try the multicast address bind first */ - if (s->is_multicast && (h->flags & AVIO_FLAG_READ)) { + /* If multicast, try binding the multicast address first, to avoid + * receiving UDP packets from other sources aimed at the same UDP + * port. This fails on windows. This makes sending to the same address + * using sendto() fail, so only do it if we're opened in read-only mode. */ + if (s->is_multicast && !(h->flags & AVIO_FLAG_WRITE)) { bind_ret = bind(udp_fd,(struct sockaddr *)&s->dest_addr, len); } /* bind to the local address if not multicast or if the multicast * bind failed */ + /* the bind is needed to give a port to the socket now */ if (bind_ret < 0 && bind(udp_fd,(struct sockaddr *)&my_addr, len) < 0) { av_log(h, AV_LOG_ERROR, "bind failed: %s\n", strerror(errno)); goto fail; @@ -490,11 +493,12 @@ static int udp_open(URLContext *h, const char *uri, int flags) s->local_port = udp_port(&my_addr, len); if (s->is_multicast) { - if (!(h->flags & AVIO_FLAG_READ)) { + if (h->flags & AVIO_FLAG_WRITE) { /* output */ if (udp_set_multicast_ttl(udp_fd, s->ttl, (struct sockaddr *)&s->dest_addr) < 0) goto fail; - } else { + } + if (h->flags & AVIO_FLAG_READ) { /* input */ if (udp_join_multicast_group(udp_fd, (struct sockaddr *)&s->dest_addr) < 0) goto fail; |