comparison udp.c @ 3221:e17b25e8a34e libavformat

Remove the "multicast=" tag from UDP and RTP URLs
author lucabe
date Tue, 15 Apr 2008 11:23:07 +0000
parents 41d68d056417
children 956fc24819df
comparison
equal deleted inserted replaced
3220:a0ccee85d6ad 3221:e17b25e8a34e
24 #include "os_support.h" 24 #include "os_support.h"
25 25
26 #ifndef IPV6_ADD_MEMBERSHIP 26 #ifndef IPV6_ADD_MEMBERSHIP
27 #define IPV6_ADD_MEMBERSHIP IPV6_JOIN_GROUP 27 #define IPV6_ADD_MEMBERSHIP IPV6_JOIN_GROUP
28 #define IPV6_DROP_MEMBERSHIP IPV6_LEAVE_GROUP 28 #define IPV6_DROP_MEMBERSHIP IPV6_LEAVE_GROUP
29 #endif
30 #ifndef IN_MULTICAST
31 #define IN_MULTICAST(a) ((((uint32_t)(a)) & 0xf0000000) == 0xe0000000)
32 #endif
33 #ifndef IN6_IS_ADDR_MULTICAST
34 #define IN6_IS_ADDR_MULTICAST(a) (((uint8_t *) (a))[0] == 0xff)
29 #endif 35 #endif
30 36
31 typedef struct { 37 typedef struct {
32 int udp_fd; 38 int udp_fd;
33 int ttl; 39 int ttl;
157 freeaddrinfo(res0); 163 freeaddrinfo(res0);
158 164
159 return addr_len; 165 return addr_len;
160 } 166 }
161 167
168 static int is_multicast_address(struct sockaddr_storage *addr)
169 {
170 if (addr->ss_family == AF_INET) {
171 return IN_MULTICAST(ntohl(((struct sockaddr_in *)addr)->sin_addr.s_addr));
172 }
173 if (addr->ss_family == AF_INET6) {
174 return IN6_IS_ADDR_MULTICAST(&((struct sockaddr_in6 *)addr)->sin6_addr);
175 }
176
177 return 0;
178 }
179
162 static int udp_socket_create(UDPContext *s, struct sockaddr_storage *addr, int *addr_len) 180 static int udp_socket_create(UDPContext *s, struct sockaddr_storage *addr, int *addr_len)
163 { 181 {
164 int udp_fd = -1; 182 int udp_fd = -1;
165 struct addrinfo *res0 = NULL, *res = NULL; 183 struct addrinfo *res0 = NULL, *res = NULL;
166 int family = AF_UNSPEC; 184 int family = AF_UNSPEC;
217 addr->sin_port = htons(port); 235 addr->sin_port = htons(port);
218 236
219 return sizeof(struct sockaddr_in); 237 return sizeof(struct sockaddr_in);
220 } 238 }
221 239
240 static int is_multicast_address(struct sockaddr_in *addr)
241 {
242 return IN_MULTICAST(ntohl(addr->sin_addr.s_addr));
243 }
244
222 static int udp_socket_create(UDPContext *s, struct sockaddr_in *addr, int *addr_len) 245 static int udp_socket_create(UDPContext *s, struct sockaddr_in *addr, int *addr_len)
223 { 246 {
224 int fd; 247 int fd;
225 248
226 fd = socket(AF_INET, SOCK_DGRAM, 0); 249 fd = socket(AF_INET, SOCK_DGRAM, 0);
246 * If no filename is given to av_open_input_file because you want to 269 * If no filename is given to av_open_input_file because you want to
247 * get the local port first, then you must call this function to set 270 * get the local port first, then you must call this function to set
248 * the remote server address. 271 * the remote server address.
249 * 272 *
250 * url syntax: udp://host:port[?option=val...] 273 * url syntax: udp://host:port[?option=val...]
251 * option: 'multicast=1' : enable multicast 274 * option: 'ttl=n' : set the ttl value (for multicast only)
252 * 'ttl=n' : set the ttl value (for multicast only)
253 * 'localport=n' : set the local port 275 * 'localport=n' : set the local port
254 * 'pkt_size=n' : set max packet size 276 * 'pkt_size=n' : set max packet size
255 * 'reuse=1' : enable reusing the socket 277 * 'reuse=1' : enable reusing the socket
256 * 278 *
257 * @param s1 media file context 279 * @param s1 media file context
269 /* set the destination address */ 291 /* set the destination address */
270 s->dest_addr_len = udp_set_url(&s->dest_addr, hostname, port); 292 s->dest_addr_len = udp_set_url(&s->dest_addr, hostname, port);
271 if (s->dest_addr_len < 0) { 293 if (s->dest_addr_len < 0) {
272 return AVERROR(EIO); 294 return AVERROR(EIO);
273 } 295 }
296 s->is_multicast = is_multicast_address(&s->dest_addr);
274 297
275 return 0; 298 return 0;
276 } 299 }
277 300
278 /** 301 /**
325 348
326 h->priv_data = s; 349 h->priv_data = s;
327 s->ttl = 16; 350 s->ttl = 16;
328 p = strchr(uri, '?'); 351 p = strchr(uri, '?');
329 if (p) { 352 if (p) {
330 s->is_multicast = find_info_tag(buf, sizeof(buf), "multicast", p);
331 s->reuse_socket = find_info_tag(buf, sizeof(buf), "reuse", p); 353 s->reuse_socket = find_info_tag(buf, sizeof(buf), "reuse", p);
332 if (find_info_tag(buf, sizeof(buf), "ttl", p)) { 354 if (find_info_tag(buf, sizeof(buf), "ttl", p)) {
333 s->ttl = strtol(buf, NULL, 10); 355 s->ttl = strtol(buf, NULL, 10);
334 } 356 }
335 if (find_info_tag(buf, sizeof(buf), "localport", p)) { 357 if (find_info_tag(buf, sizeof(buf), "localport", p)) {
344 url_split(NULL, 0, NULL, 0, hostname, sizeof(hostname), &port, NULL, 0, uri); 366 url_split(NULL, 0, NULL, 0, hostname, sizeof(hostname), &port, NULL, 0, uri);
345 367
346 /* XXX: fix url_split */ 368 /* XXX: fix url_split */
347 if (hostname[0] == '\0' || hostname[0] == '?') { 369 if (hostname[0] == '\0' || hostname[0] == '?') {
348 /* only accepts null hostname if input */ 370 /* only accepts null hostname if input */
349 if (s->is_multicast || (flags & URL_WRONLY)) 371 if (flags & URL_WRONLY)
350 goto fail; 372 goto fail;
351 } else { 373 } else {
352 udp_set_remote_url(h, uri); 374 udp_set_remote_url(h, uri);
353 } 375 }
354 376