comparison udp.c @ 2740:e23eaab1a894 libavformat

Give better names to multicast functions (they are not IPv6-only)
author lucabe
date Wed, 14 Nov 2007 07:43:51 +0000
parents 091af9f47edf
children 3c9be240de12
comparison
equal deleted inserted replaced
2739:091af9f47edf 2740:e23eaab1a894
43 } UDPContext; 43 } UDPContext;
44 44
45 #define UDP_TX_BUF_SIZE 32768 45 #define UDP_TX_BUF_SIZE 32768
46 #define UDP_MAX_PKT_SIZE 65536 46 #define UDP_MAX_PKT_SIZE 65536
47 47
48 static int udp_ipv6_set_multicast_ttl(int sockfd, int mcastTTL, struct sockaddr *addr) { 48 static int udp_set_multicast_ttl(int sockfd, int mcastTTL, struct sockaddr *addr) {
49 #ifdef IP_MULTICAST_TTL 49 #ifdef IP_MULTICAST_TTL
50 if (addr->sa_family == AF_INET) { 50 if (addr->sa_family == AF_INET) {
51 if (setsockopt(sockfd, IPPROTO_IP, IP_MULTICAST_TTL, &mcastTTL, sizeof(mcastTTL)) < 0) { 51 if (setsockopt(sockfd, IPPROTO_IP, IP_MULTICAST_TTL, &mcastTTL, sizeof(mcastTTL)) < 0) {
52 perror("setsockopt(IP_MULTICAST_TTL)"); 52 perror("setsockopt(IP_MULTICAST_TTL)");
53 return -1; 53 return -1;
63 } 63 }
64 #endif 64 #endif
65 return 0; 65 return 0;
66 } 66 }
67 67
68 static int udp_ipv6_join_multicast_group(int sockfd, struct sockaddr *addr) { 68 static int udp_join_multicast_group(int sockfd, struct sockaddr *addr) {
69 #ifdef IP_ADD_MEMBERSHIP 69 #ifdef IP_ADD_MEMBERSHIP
70 if (addr->sa_family == AF_INET) { 70 if (addr->sa_family == AF_INET) {
71 struct ip_mreq mreq; 71 struct ip_mreq mreq;
72 72
73 mreq.imr_multiaddr.s_addr = ((struct sockaddr_in *)addr)->sin_addr.s_addr; 73 mreq.imr_multiaddr.s_addr = ((struct sockaddr_in *)addr)->sin_addr.s_addr;
91 } 91 }
92 #endif 92 #endif
93 return 0; 93 return 0;
94 } 94 }
95 95
96 static int udp_ipv6_leave_multicast_group(int sockfd, struct sockaddr *addr) { 96 static int udp_leave_multicast_group(int sockfd, struct sockaddr *addr) {
97 #ifdef IP_DROP_MEMBERSHIP 97 #ifdef IP_DROP_MEMBERSHIP
98 if (addr->sa_family == AF_INET) { 98 if (addr->sa_family == AF_INET) {
99 struct ip_mreq mreq; 99 struct ip_mreq mreq;
100 100
101 mreq.imr_multiaddr.s_addr = ((struct sockaddr_in *)addr)->sin_addr.s_addr; 101 mreq.imr_multiaddr.s_addr = ((struct sockaddr_in *)addr)->sin_addr.s_addr;
368 goto fail; 368 goto fail;
369 #endif /* CONFIG_IPV6 */ 369 #endif /* CONFIG_IPV6 */
370 if (s->is_multicast) { 370 if (s->is_multicast) {
371 if (h->flags & URL_WRONLY) { 371 if (h->flags & URL_WRONLY) {
372 /* output */ 372 /* output */
373 if (udp_ipv6_set_multicast_ttl(udp_fd, s->ttl, (struct sockaddr *)&s->dest_addr) < 0) 373 if (udp_set_multicast_ttl(udp_fd, s->ttl, (struct sockaddr *)&s->dest_addr) < 0)
374 goto fail; 374 goto fail;
375 } else { 375 } else {
376 /* input */ 376 /* input */
377 if (udp_ipv6_join_multicast_group(udp_fd, (struct sockaddr *)&s->dest_addr) < 0) 377 if (udp_join_multicast_group(udp_fd, (struct sockaddr *)&s->dest_addr) < 0)
378 goto fail; 378 goto fail;
379 } 379 }
380 } 380 }
381 381
382 if (is_output) { 382 if (is_output) {
451 static int udp_close(URLContext *h) 451 static int udp_close(URLContext *h)
452 { 452 {
453 UDPContext *s = h->priv_data; 453 UDPContext *s = h->priv_data;
454 454
455 if (s->is_multicast && !(h->flags & URL_WRONLY)) 455 if (s->is_multicast && !(h->flags & URL_WRONLY))
456 udp_ipv6_leave_multicast_group(s->udp_fd, (struct sockaddr *)&s->dest_addr); 456 udp_leave_multicast_group(s->udp_fd, (struct sockaddr *)&s->dest_addr);
457 closesocket(s->udp_fd); 457 closesocket(s->udp_fd);
458 ff_network_close(); 458 ff_network_close();
459 av_free(s); 459 av_free(s);
460 return 0; 460 return 0;
461 } 461 }