MCPcopy Create free account
hub / github.com/FFmpeg/FFmpeg / udp_socket_create

Function udp_socket_create

libavformat/udp.c:363–403  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

361}
362
363static int udp_socket_create(URLContext *h, struct sockaddr_storage *addr,
364 socklen_t *addr_len, const char *localaddr)
365{
366 UDPContext *s = h->priv_data;
367 int udp_fd = -1;
368 struct addrinfo *res0, *res;
369 int family = AF_UNSPEC;
370
371 if (((struct sockaddr *) &s->dest_addr)->sa_family)
372 family = ((struct sockaddr *) &s->dest_addr)->sa_family;
373 res0 = ff_ip_resolve_host(h, (localaddr && localaddr[0]) ? localaddr : NULL,
374 s->local_port,
375 SOCK_DGRAM, family, AI_PASSIVE);
376 if (!res0)
377 goto fail;
378 for (res = res0; res; res=res->ai_next) {
379 if (s->udplite_coverage)
380 udp_fd = ff_socket(res->ai_family, SOCK_DGRAM, IPPROTO_UDPLITE, h);
381 else
382 udp_fd = ff_socket(res->ai_family, SOCK_DGRAM, 0, h);
383 if (udp_fd != -1) break;
384 ff_log_net_error(h, AV_LOG_ERROR, "socket");
385 }
386
387 if (udp_fd < 0)
388 goto fail;
389
390 memcpy(addr, res->ai_addr, res->ai_addrlen);
391 *addr_len = res->ai_addrlen;
392
393 freeaddrinfo(res0);
394
395 return udp_fd;
396
397 fail:
398 if (udp_fd >= 0)
399 closesocket(udp_fd);
400 if(res0)
401 freeaddrinfo(res0);
402 return -1;
403}
404
405static int udp_port(struct sockaddr_storage *addr, int addr_len)
406{

Callers 1

udp_openFunction · 0.85

Calls 3

ff_ip_resolve_hostFunction · 0.85
ff_socketFunction · 0.85
ff_log_net_errorFunction · 0.85

Tested by

no test coverage detected