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

Martin Storsjö martin
Sat Jan 2 00:18:22 CET 2010

On Fri, 1 Jan 2010, Ronald S. Bultje wrote:

> I think I looked into using getaddrinfo() in the past. If memory
> serves me right, what people wanted was that we'd drop any other API
> alltogether, and sort of provide a fallback wrapper in libossupport if
> getaddrinfo() & co are missing.

That does indeed sound like a good plan. As a coincidence, I happen to 
have written such a fallback wrapper for other cases, that I could try to 
adapt. :-)

> The advantage of that approach would be that in many places, we can
> drop resolve_host alltogether. the inet_aton() before gethostbyname()
> isn't needed with getaddrinfo(), it does that implicitely. The added

Doesn't gethostbyname handle numerical IP addresses, too? At least it 
seems to handle it just fine on both linux and os x.

> advantage of using *only* getaddrinfo() is also that we don't have to
> worry about where the data is located in struct sockaddr_inX (think of
> the size/offset diffs between in4/in6), and thus that adding support
> for IPv6 would be very easy (which we indeed do not support right
> now). Lastly, it means we can drop resolve_host() because
> getaddrinfo() does all it does, and better.
> (I, for one, would favour dropping resolve_host() altogether and using
> getaddrinfo() or a fallback implementation using resolve_host()'s
> stuff internally in libossupport() instead.)

That sounds like a good plan.

Using getaddrinfo properly is generally a bit more tricky, since one is 
supposed to try to connect to all returned sockaddrs (e.g. in case an IPv6 
one is returned if the v6 connectivity is lacking).

How about this action order:

1. Apply my current getaddrinfo patch that makes resolve_host use it - 
   that at least fixes the thread safety, until step 2 can be applied.
2. Add a getaddrinfo fallback wrapper, so that such a function can always
   be relied upon. I've got code for that already, just need to adapt it.
3. Transition each usage occurrance of resolve_host into getaddrinfo - 
   potentially with the necessary rewritings for supporting multiple 
   address families (aka IPv6) at the same time.
4. Once resolve_host isn't used anymore, remove it.

// Martin

More information about the ffmpeg-devel mailing list