[FFmpeg-devel] [PATCH/RFC] Prefer getaddrinfo over gethostbyname

Martin Storsjö martin
Mon Jan 4 00:11:16 CET 2010


Hi,

As discussed with Ronald a few days ago, this is a first shot at moving 
most usage of host resolving functions to use getaddrinfo instead of 
gethostbyname. It isn't tested all that much yet, though.

First the current resolve_host is switched to use getaddrinfo if 
available, since it is thread safe, which gethostbyname isn't.

Then a replacement implementation is introduced, to let the rest of the 
code use the getaddrinfo interface directly. The replacement itself should 
be quite acceptable, but building on different platforms with different 
sets of headers may uncover some more problems.

The old resolve_host interface is marked deprecated, and the places where 
it is used in the tcp and udp protocols are converted to use getaddrinfo 
instead.

The tcp protocol now tries to connect to all returned addresses; if one 
fails, it tries the next one. (E.g., a host name with both v4/v6 
addresses, but the desired service only listens on one of the addresses.)

The resolve_host vs full ipv6 support in the udp protocol isn't cleaned up 
- this may need a bit more work, I just replaced the non-ipv6 codepath to 
use getaddrinfo with only the AF_INET protocol family. I guess the 
much of the separate ipv4/ipv6 codepaths could be merged now.

I didn't try to fix up ffserver yet, either.

Also, for platforms where getaddrinfo isn't available, I'm not sure if 
defining a replacement of our own with the same name is the best solution 
- on e.g. windows, a symbol with that name is available on modern windows 
versions, but it isn't available in the mingw link libraries. (To retain 
compatibility with older versions, one is supposed to dynamically load the 
getaddrinfo function pointer, or use a wrapper for gethostbyname if the 
symbol isn't found.) One extra solution perhaps would be to add
#define getaddrinfo ff_getaddrinfo
if using our wrapper.

Also, if the platform doesn't have a proper getaddrinfo, ffserver will 
need to use it from libavformat, so in that case it should be a public 
symbol. (What's the case with resolve_host at the moment?)

// Martin
-------------- next part --------------
A non-text attachment was scrubbed...
Name: 0001-Check-for-the-getaddrinfo-function.patch
Type: text/x-diff
Size: 823 bytes
Desc: 
URL: <http://lists.mplayerhq.hu/pipermail/ffmpeg-devel/attachments/20100104/fb706488/attachment.patch>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: 0002-Use-getaddrinfo-instead-of-gethostbyname-if-availabl.patch
Type: text/x-diff
Size: 1657 bytes
Desc: 
URL: <http://lists.mplayerhq.hu/pipermail/ffmpeg-devel/attachments/20100104/fb706488/attachment-0001.patch>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: 0003-Make-check_type-handle-type-names-containing-spaces.patch
Type: text/x-diff
Size: 818 bytes
Desc: 
URL: <http://lists.mplayerhq.hu/pipermail/ffmpeg-devel/attachments/20100104/fb706488/attachment-0002.patch>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: 0004-Check-for-the-structs-associated-with-getaddrinfo.patch
Type: text/x-diff
Size: 1371 bytes
Desc: 
URL: <http://lists.mplayerhq.hu/pipermail/ffmpeg-devel/attachments/20100104/fb706488/attachment-0003.patch>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: 0005-Make-sure-getaddrinfo-and-freeaddrinfo-are-always-av.patch
Type: text/x-diff
Size: 3500 bytes
Desc: 
URL: <http://lists.mplayerhq.hu/pipermail/ffmpeg-devel/attachments/20100104/fb706488/attachment-0004.patch>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: 0006-Mark-resolve_host-as-deprecated.patch
Type: text/x-diff
Size: 931 bytes
Desc: 
URL: <http://lists.mplayerhq.hu/pipermail/ffmpeg-devel/attachments/20100104/fb706488/attachment-0005.patch>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: 0007-Use-getaddrinfo-instead-of-resolve_host-in-the-tcp-p.patch
Type: text/x-diff
Size: 2995 bytes
Desc: 
URL: <http://lists.mplayerhq.hu/pipermail/ffmpeg-devel/attachments/20100104/fb706488/attachment-0006.patch>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: 0008-Use-getaddrinfo-instead-of-resolve_host-in-the-non-i.patch
Type: text/x-diff
Size: 1600 bytes
Desc: 
URL: <http://lists.mplayerhq.hu/pipermail/ffmpeg-devel/attachments/20100104/fb706488/attachment-0007.patch>



More information about the ffmpeg-devel mailing list