# HG changeset patch # User henry # Date 1228670949 0 # Node ID 7f9fb963926c1800bcdee437dc3f5ab875bf4136 # Parent 52a514815c9a5e5cc05c55fdac6fa36e2d524d46 bind to the multicast address if possible diff -r 52a514815c9a -r 7f9fb963926c udp.c --- a/udp.c Sun Dec 07 01:53:31 2008 +0000 +++ b/udp.c Sun Dec 07 17:29:09 2008 +0000 @@ -336,7 +336,7 @@ static int udp_open(URLContext *h, const char *uri, int flags) { char hostname[1024]; - int port, udp_fd = -1, tmp; + int port, udp_fd = -1, tmp, bind_ret = -1; UDPContext *s = NULL; int is_output; const char *p; @@ -404,7 +404,13 @@ goto fail; /* the bind is needed to give a port to the socket now */ - if (bind(udp_fd,(struct sockaddr *)&my_addr, len) < 0) + /* if multicast, try the multicast address bind first */ + if (s->is_multicast && !(h->flags & URL_WRONLY)) { + 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 */ + if (bind_ret < 0 && bind(udp_fd,(struct sockaddr *)&my_addr, len) < 0) goto fail; len = sizeof(my_addr);