comparison udp.c @ 2750:b3a11a0966af libavformat

Use the same code to set local_port in the IPv4-only case and in the protocol-independet case
author lucabe
date Thu, 15 Nov 2007 13:34:56 +0000
parents 1435f0dbfb4b
children d174591c742b
comparison
equal deleted inserted replaced
2749:2a6baeedf776 2750:b3a11a0966af
337 } 337 }
338 338
339 if(!ff_network_init()) 339 if(!ff_network_init())
340 return AVERROR(EIO); 340 return AVERROR(EIO);
341 341
342 if (s->is_multicast && !(h->flags & URL_WRONLY))
343 s->local_port = port;
342 #ifndef CONFIG_IPV6 344 #ifndef CONFIG_IPV6
343 udp_fd = socket(AF_INET, SOCK_DGRAM, 0); 345 udp_fd = socket(AF_INET, SOCK_DGRAM, 0);
344 if (udp_fd < 0) 346 if (udp_fd < 0)
345 goto fail; 347 goto fail;
346 348
347 my_addr.sin_family = AF_INET; 349 my_addr.sin_family = AF_INET;
348 my_addr.sin_addr.s_addr = htonl (INADDR_ANY); 350 my_addr.sin_addr.s_addr = htonl (INADDR_ANY);
349 if (s->is_multicast && !(h->flags & URL_WRONLY)) { 351 my_addr.sin_port = htons(s->local_port);
350 /* special case: the bind must be done on the multicast address port */
351 my_addr.sin_port = s->dest_addr.sin_port;
352 } else {
353 my_addr.sin_port = htons(s->local_port);
354 }
355 352
356 if (s->reuse_socket) 353 if (s->reuse_socket)
357 if (setsockopt (udp_fd, SOL_SOCKET, SO_REUSEADDR, &(s->reuse_socket), sizeof(s->reuse_socket)) != 0) 354 if (setsockopt (udp_fd, SOL_SOCKET, SO_REUSEADDR, &(s->reuse_socket), sizeof(s->reuse_socket)) != 0)
358 goto fail; 355 goto fail;
359 356
363 360
364 len = sizeof(my_addr1); 361 len = sizeof(my_addr1);
365 getsockname(udp_fd, (struct sockaddr *)&my_addr1, &len); 362 getsockname(udp_fd, (struct sockaddr *)&my_addr1, &len);
366 s->local_port = ntohs(my_addr1.sin_port); 363 s->local_port = ntohs(my_addr1.sin_port);
367 #else 364 #else
368 if (s->is_multicast && !(h->flags & URL_WRONLY))
369 s->local_port = port;
370 udp_fd = udp_ipv6_set_local(h); 365 udp_fd = udp_ipv6_set_local(h);
371 if (udp_fd < 0) 366 if (udp_fd < 0)
372 goto fail; 367 goto fail;
373 #endif /* CONFIG_IPV6 */ 368 #endif /* CONFIG_IPV6 */
374 if (s->is_multicast) { 369 if (s->is_multicast) {