X-Git-Url: https://git.m6w6.name/?a=blobdiff_plain;f=libtest%2Fdns.cc;h=75a5bbfbf420352aacc907174a7eca932715c273;hb=32eebdc2e1ae14f41bb15e212036b772760a3fd1;hp=2bf094cbe8a2365fffc82ffb87d1c0f2c31c0a59;hpb=f6a25ad2e38d85584d0d55b491d63338cb1e73cf;p=awesomized%2Flibmemcached diff --git a/libtest/dns.cc b/libtest/dns.cc index 2bf094cb..75a5bbfb 100644 --- a/libtest/dns.cc +++ b/libtest/dns.cc @@ -34,7 +34,7 @@ * */ -#include +#include "libtest/yatlcon.h" #include #include @@ -45,16 +45,32 @@ namespace libtest { bool lookup(const char* host) { - assert(host); bool success= false; - struct addrinfo *addrinfo= NULL; - - int limit= 5; - while (limit--) + assert(host and host[0]); + if (host and host[0]) { - int ret; - if ((ret= getaddrinfo(host, NULL, NULL, &(addrinfo)))) + struct addrinfo *addrinfo= NULL; + struct addrinfo hints; + memset(&hints, 0, sizeof(hints)); + hints.ai_socktype= SOCK_STREAM; + hints.ai_protocol= IPPROTO_TCP; + + int limit= 5; + while (--limit and success == false) { + if (addrinfo) + { + freeaddrinfo(addrinfo); + addrinfo= NULL; + } + + int ret; + if ((ret= getaddrinfo(host, "echo", &hints, &addrinfo)) == 0) + { + success= true; + break; + } + switch (ret) { case EAI_AGAIN: @@ -64,22 +80,27 @@ bool lookup(const char* host) default: break; } + + break; } - else + + if (addrinfo) { - success= true; - break; + freeaddrinfo(addrinfo); } } - freeaddrinfo(addrinfo); - return success; } bool check_dns() { + if (valgrind_is_caller()) + { + return false; + } + if (lookup("exist.gearman.info") == false) { return false; @@ -87,7 +108,7 @@ bool check_dns() if (lookup("does_not_exist.gearman.info")) // This should fail, if it passes,... { - return false; + fatal_assert("Your service provider sucks and is providing bogus DNS. You might be in an airport."); } return true;