Revision 9087a46d

View differences:

libavformat/udp.c
313 313
    char buf[256];
314 314
    struct sockaddr_storage my_addr;
315 315
    int len;
316
    int reuse_specified = 0;
316 317

  
317 318
    h->is_streamed = 1;
318 319
    h->max_packet_size = 1472;
......
329 330

  
330 331
    p = strchr(uri, '?');
331 332
    if (p) {
332
        s->reuse_socket = find_info_tag(buf, sizeof(buf), "reuse", p);
333
        if (find_info_tag(buf, sizeof(buf), "reuse", p)) {
334
            const char *endptr=NULL;
335
            s->reuse_socket = strtol(buf, &endptr, 10);
336
            /* assume if no digits were found it is a request to enable it */
337
            if (buf == endptr)
338
                s->reuse_socket = 1;
339
            reuse_specified = 1;
340
        }
333 341
        if (find_info_tag(buf, sizeof(buf), "ttl", p)) {
334 342
            s->ttl = strtol(buf, NULL, 10);
335 343
        }
......
366 374
    if (udp_fd < 0)
367 375
        goto fail;
368 376

  
369
    if (s->reuse_socket)
377
    /* Follow the requested reuse option, unless it's multicast in which
378
     * case enable reuse unless explicitely disabled.
379
     */
380
    if (s->reuse_socket || (s->is_multicast && !reuse_specified)) {
381
        s->reuse_socket = 1;
370 382
        if (setsockopt (udp_fd, SOL_SOCKET, SO_REUSEADDR, &(s->reuse_socket), sizeof(s->reuse_socket)) != 0)
371 383
            goto fail;
384
    }
372 385

  
373 386
    /* the bind is needed to give a port to the socket now */
374 387
    /* if multicast, try the multicast address bind first */

Also available in: Unified diff