diff options
author | Gerd Hoffmann <kraxel@redhat.com> | 2010-02-25 14:52:35 +0100 |
---|---|---|
committer | Uri Lublin <uril@redhat.com> | 2010-03-18 13:48:51 +0200 |
commit | 54c5236f347a19aa202876eebb1c1f29c4f21928 (patch) | |
tree | 47079ce4af8df25b0fa8b6cfb094d6d00d73d0bb | |
parent | 38add29e24e9923f76cdae4b1710bb754674a482 (diff) | |
download | spice-54c5236f347a19aa202876eebb1c1f29c4f21928.tar.gz spice-54c5236f347a19aa202876eebb1c1f29c4f21928.tar.xz spice-54c5236f347a19aa202876eebb1c1f29c4f21928.zip |
spice client: fix dns lookup #566444
ignore lookup results which are not ipv4
Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
-rw-r--r-- | client/red_peer.cpp | 12 |
1 files changed, 9 insertions, 3 deletions
diff --git a/client/red_peer.cpp b/client/red_peer.cpp index 069fdae5..9db48e4f 100644 --- a/client/red_peer.cpp +++ b/client/red_peer.cpp @@ -113,17 +113,23 @@ void RedPeer::cleanup() uint32_t RedPeer::host_by_name(const char* host) { - struct addrinfo *result = NULL; + struct addrinfo *e, *result = NULL; struct sockaddr_in *addr; uint32_t return_value; int rc; rc = getaddrinfo(host, NULL, NULL, &result); - if (rc != 0 || result == NULL) { + for (e = result; e != NULL; e = e->ai_next) { + if (e->ai_family == PF_INET) + break; + } + if (rc != 0 || e == NULL) { + if (result) + freeaddrinfo(result); THROW_ERR(SPICEC_ERROR_CODE_GETHOSTBYNAME_FAILED, "cannot resolve host address %s", host); } - addr = (sockaddr_in *)result->ai_addr; + addr = (sockaddr_in *)e->ai_addr; return_value = addr->sin_addr.s_addr; freeaddrinfo(result); |