Browse Source

Simplify set_remote_url(), and remove some code duplication

Originally committed as revision 11016 to svn://svn.ffmpeg.org/ffmpeg/trunk
tags/v0.5
Luca Abeni 18 years ago
parent
commit
d05cb726bd
1 changed files with 24 additions and 16 deletions
  1. +24
    -16
      libavformat/udp.c

+ 24
- 16
libavformat/udp.c View File

@@ -145,18 +145,17 @@ static struct addrinfo* udp_ipv6_resolve_host(const char *hostname, int port, in
return res; return res;
} }


static int udp_ipv6_set_remote_url(URLContext *h, const char *uri) {
UDPContext *s = h->priv_data;
char hostname[256];
int port;
static int udp_set_url(struct sockaddr_storage *addr, const char *hostname, int port) {
struct addrinfo *res0; struct addrinfo *res0;
url_split(NULL, 0, NULL, 0, hostname, sizeof(hostname), &port, NULL, 0, uri);
int addr_len;

res0 = udp_ipv6_resolve_host(hostname, port, SOCK_DGRAM, AF_UNSPEC, 0); res0 = udp_ipv6_resolve_host(hostname, port, SOCK_DGRAM, AF_UNSPEC, 0);
if (res0 == 0) return AVERROR(EIO); if (res0 == 0) return AVERROR(EIO);
memcpy(&s->dest_addr, res0->ai_addr, res0->ai_addrlen);
s->dest_addr_len = res0->ai_addrlen;
memcpy(addr, res0->ai_addr, res0->ai_addrlen);
addr_len = res0->ai_addrlen;
freeaddrinfo(res0); freeaddrinfo(res0);
return 0;

return addr_len;
} }


static int udp_ipv6_set_local(URLContext *h) { static int udp_ipv6_set_local(URLContext *h) {
@@ -213,6 +212,19 @@ static int udp_ipv6_set_local(URLContext *h) {
return -1; return -1;
} }


#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);
}

#endif /* CONFIG_IPV6 */ #endif /* CONFIG_IPV6 */




@@ -234,9 +246,6 @@ static int udp_ipv6_set_local(URLContext *h) {
*/ */
int udp_set_remote_url(URLContext *h, const char *uri) int udp_set_remote_url(URLContext *h, const char *uri)
{ {
#ifdef CONFIG_IPV6
return udp_ipv6_set_remote_url(h, uri);
#else
UDPContext *s = h->priv_data; UDPContext *s = h->priv_data;
char hostname[256]; char hostname[256];
int port; int port;
@@ -244,13 +253,12 @@ int udp_set_remote_url(URLContext *h, const char *uri)
url_split(NULL, 0, NULL, 0, hostname, sizeof(hostname), &port, NULL, 0, uri); url_split(NULL, 0, NULL, 0, hostname, sizeof(hostname), &port, NULL, 0, uri);


/* set the destination address */ /* set the destination address */
if (resolve_host(&s->dest_addr.sin_addr, hostname) < 0)
s->dest_addr_len = udp_set_url(&s->dest_addr, hostname, port);
if (s->dest_addr_len < 0) {
return AVERROR(EIO); return AVERROR(EIO);
s->dest_addr.sin_family = AF_INET;
s->dest_addr.sin_port = htons(port);
s->dest_addr_len = sizeof(s->dest_addr);
}

return 0; return 0;
#endif
} }


/** /**


Loading…
Cancel
Save