diff options
author | Ronald S. Bultje <rsbultje@gmail.com> | 2010-01-11 17:14:16 +0000 |
---|---|---|
committer | Ronald S. Bultje <rsbultje@gmail.com> | 2010-01-11 17:14:16 +0000 |
commit | 7e43f74a37b43f0b4fb5448ac01a3dddd0aa533a (patch) | |
tree | e2ab77ff42f01329fdac785dc1965a98c0635322 | |
parent | 84882df62b07a6ddb358e5795d8edcfde0bd71aa (diff) | |
download | ffmpeg-7e43f74a37b43f0b4fb5448ac01a3dddd0aa533a.tar.gz |
Use getaddrinfo(), if available, in resolve_host(). Patch by Martin
Storsjö <$firstname()$firstname,st>.
Originally committed as revision 21143 to svn://svn.ffmpeg.org/ffmpeg/trunk
-rw-r--r-- | libavformat/os_support.c | 23 |
1 files changed, 22 insertions, 1 deletions
diff --git a/libavformat/os_support.c b/libavformat/os_support.c index 96cd347b9e..87481d674e 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)) + return -1; + /* getaddrinfo returns a linked list of addrinfo structs. + * Even if we set ai_family = AF_INET above, make sure + * that the returned one actually is of the correct type. */ + for (cur = ai; cur; cur = cur->ai_next) { + if (cur->ai_family == AF_INET) { + *sin_addr = ((struct sockaddr_in *)cur->ai_addr)->sin_addr; + freeaddrinfo(ai); + return 0; + } + } + freeaddrinfo(ai); + return -1; +#else + struct hostent *hp; hp = gethostbyname(hostname); if (!hp) return -1; memcpy(sin_addr, hp->h_addr_list[0], sizeof(struct in_addr)); +#endif } return 0; } |