[FFmpeg-devel] [PATCH] Use getaddrinfo instead of gethostbyname, if available

Reimar Döffinger Reimar.Doeffinger
Fri Jan 1 16:20:10 CET 2010


On Fri, Jan 01, 2010 at 03:59:20PM +0200, Martin Storsj? wrote:
> diff --git a/libavformat/os_support.c b/libavformat/os_support.c
> index 6763e39..db70dbb 100644
> --- a/libavformat/os_support.c
> +++ b/libavformat/os_support.c
> @@ -63,13 +63,34 @@ int inet_aton (const char * str, struct in_addr * add)
>  /* resolve host with also IP address parsing */
>  int resolve_host(struct in_addr *sin_addr, const char *hostname)
>  {
> -    struct hostent *hp;
>  
>      if (!inet_aton(hostname, sin_addr)) {
> +#if HAVE_GETADDRINFO
> +        struct addrinfo *ai, *cur;
> +        struct addrinfo hints;
> +        memset(&hints, 0, sizeof(hints));
> +        hints.ai_family = AF_INET;
> +        if (getaddrinfo(hostname, NULL, &hints, &ai) != 0)
> +            return -1;

> +        cur = ai;
> +        while (cur) {
> +            if (cur->ai_family == AF_INET) {
> +                struct sockaddr_in* sa = (struct sockaddr_in*) cur->ai_addr;
> +                *sin_addr = sa->sin_addr;
> +                freeaddrinfo(ai);
> +                return 0;
> +            }
> +            cur = cur->ai_next;
> +        }

AFAICT for any correct implementation this is a very complex way of
doing
*sin_addr = ((struct sockaddr_in *)cur->ai_addr)->sin_addr;

Even if we don't want that,
> for (cur = ai; cur; cur = cur->ai_next)
is a bit simpler than the while.



More information about the ffmpeg-devel mailing list