|
|
|
@ -52,11 +52,7 @@ typedef struct { |
|
|
|
|
int is_multicast; |
|
|
|
|
int local_port; |
|
|
|
|
int reuse_socket; |
|
|
|
|
#if !CONFIG_IPV6 |
|
|
|
|
struct sockaddr_in dest_addr; |
|
|
|
|
#else |
|
|
|
|
struct sockaddr_storage dest_addr; |
|
|
|
|
#endif |
|
|
|
|
int dest_addr_len; |
|
|
|
|
} UDPContext; |
|
|
|
|
|
|
|
|
@ -72,7 +68,7 @@ static int udp_set_multicast_ttl(int sockfd, int mcastTTL, struct sockaddr *addr |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
#endif |
|
|
|
|
#if CONFIG_IPV6 |
|
|
|
|
#if defined(IPPROTO_IPV6) && defined(IPV6_MULTICAST_HOPS) |
|
|
|
|
if (addr->sa_family == AF_INET6) { |
|
|
|
|
if (setsockopt(sockfd, IPPROTO_IPV6, IPV6_MULTICAST_HOPS, &mcastTTL, sizeof(mcastTTL)) < 0) { |
|
|
|
|
av_log(NULL, AV_LOG_ERROR, "setsockopt(IPV6_MULTICAST_HOPS): %s\n", strerror(errno)); |
|
|
|
@ -96,7 +92,7 @@ static int udp_join_multicast_group(int sockfd, struct sockaddr *addr) { |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
#endif |
|
|
|
|
#if CONFIG_IPV6 |
|
|
|
|
#if HAVE_STRUCT_IPV6_MREQ |
|
|
|
|
if (addr->sa_family == AF_INET6) { |
|
|
|
|
struct ipv6_mreq mreq6; |
|
|
|
|
|
|
|
|
@ -124,7 +120,7 @@ static int udp_leave_multicast_group(int sockfd, struct sockaddr *addr) { |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
#endif |
|
|
|
|
#if CONFIG_IPV6 |
|
|
|
|
#if HAVE_STRUCT_IPV6_MREQ |
|
|
|
|
if (addr->sa_family == AF_INET6) { |
|
|
|
|
struct ipv6_mreq mreq6; |
|
|
|
|
|
|
|
|
@ -139,7 +135,6 @@ static int udp_leave_multicast_group(int sockfd, struct sockaddr *addr) { |
|
|
|
|
return 0; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
#if CONFIG_IPV6 |
|
|
|
|
static struct addrinfo* udp_ipv6_resolve_host(const char *hostname, int port, int type, int family, int flags) { |
|
|
|
|
struct addrinfo hints, *res = 0; |
|
|
|
|
int error; |
|
|
|
@ -182,9 +177,11 @@ static int is_multicast_address(struct sockaddr_storage *addr) |
|
|
|
|
if (addr->ss_family == AF_INET) { |
|
|
|
|
return IN_MULTICAST(ntohl(((struct sockaddr_in *)addr)->sin_addr.s_addr)); |
|
|
|
|
} |
|
|
|
|
#if HAVE_STRUCT_SOCKADDR_IN6 |
|
|
|
|
if (addr->ss_family == AF_INET6) { |
|
|
|
|
return IN6_IS_ADDR_MULTICAST(&((struct sockaddr_in6 *)addr)->sin6_addr); |
|
|
|
|
} |
|
|
|
|
#endif |
|
|
|
|
|
|
|
|
|
return 0; |
|
|
|
|
} |
|
|
|
@ -236,46 +233,6 @@ static int udp_port(struct sockaddr_storage *addr, int addr_len) |
|
|
|
|
return strtol(sbuf, NULL, 10); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
#else |
|
|
|
|
|
|
|
|
|
static int udp_set_url(struct sockaddr_in *addr, const char *hostname, int port) |
|
|
|
|
{ |
|
|
|
|
/* set the destination address */ |
|
|
|
|
if (resolve_host(&addr->sin_addr, hostname) < 0) |
|
|
|
|
return AVERROR(EIO); |
|
|
|
|
addr->sin_family = AF_INET; |
|
|
|
|
addr->sin_port = htons(port); |
|
|
|
|
|
|
|
|
|
return sizeof(struct sockaddr_in); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
static int is_multicast_address(struct sockaddr_in *addr) |
|
|
|
|
{ |
|
|
|
|
return IN_MULTICAST(ntohl(addr->sin_addr.s_addr)); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
static int udp_socket_create(UDPContext *s, struct sockaddr_in *addr, int *addr_len) |
|
|
|
|
{ |
|
|
|
|
int fd; |
|
|
|
|
|
|
|
|
|
fd = socket(AF_INET, SOCK_DGRAM, 0); |
|
|
|
|
if (fd < 0) |
|
|
|
|
return -1; |
|
|
|
|
|
|
|
|
|
addr->sin_family = AF_INET; |
|
|
|
|
addr->sin_addr.s_addr = htonl (INADDR_ANY); |
|
|
|
|
addr->sin_port = htons(s->local_port); |
|
|
|
|
*addr_len = sizeof(struct sockaddr_in); |
|
|
|
|
|
|
|
|
|
return fd; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
static int udp_port(struct sockaddr_in *addr, int len) |
|
|
|
|
{ |
|
|
|
|
return ntohs(addr->sin_port); |
|
|
|
|
} |
|
|
|
|
#endif /* CONFIG_IPV6 */ |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* If no filename is given to av_open_input_file because you want to |
|
|
|
@ -345,11 +302,7 @@ static int udp_open(URLContext *h, const char *uri, int flags) |
|
|
|
|
int is_output; |
|
|
|
|
const char *p; |
|
|
|
|
char buf[256]; |
|
|
|
|
#if !CONFIG_IPV6 |
|
|
|
|
struct sockaddr_in my_addr; |
|
|
|
|
#else |
|
|
|
|
struct sockaddr_storage my_addr; |
|
|
|
|
#endif |
|
|
|
|
int len; |
|
|
|
|
|
|
|
|
|
h->is_streamed = 1; |
|
|
|
|