X-Git-Url: http://git.onelab.eu/?a=blobdiff_plain;ds=sidebyside;f=lib%2Fsocket-util.c;h=2dff9f5924331495790e43f89e244f053fa8ecbf;hb=e6603631d3c101620882adb29e34cb09b5234291;hp=4f9b5b8919e9eed367540e74fe9303deac3e6ebf;hpb=df451457ad9a02bcd9793126b66be445f4d5a8a7;p=sliver-openvswitch.git diff --git a/lib/socket-util.c b/lib/socket-util.c index 4f9b5b891..2dff9f592 100644 --- a/lib/socket-util.c +++ b/lib/socket-util.c @@ -178,30 +178,61 @@ lookup_ipv6(const char *host_name, struct in6_addr *addr) * successful, otherwise a positive errno value. * * Most Open vSwitch code should not use this because it causes deadlocks: - * gethostbyname() sends out a DNS request but that starts a new flow for which + * getaddrinfo() sends out a DNS request but that starts a new flow for which * OVS must set up a flow, but it can't because it's waiting for a DNS reply. * The synchronous lookup also delays other activity. (Of course we can solve * this but it doesn't seem worthwhile quite yet.) */ int lookup_hostname(const char *host_name, struct in_addr *addr) { - struct hostent *h; + struct addrinfo *result; + struct addrinfo hints; if (inet_aton(host_name, addr)) { return 0; } - h = gethostbyname(host_name); - if (h) { - *addr = *(struct in_addr *) h->h_addr; + memset(&hints, 0, sizeof hints); + hints.ai_family = AF_INET; + + switch (getaddrinfo(host_name, NULL, &hints, &result)) { + case 0: + *addr = ((struct sockaddr_in *) result->ai_addr)->sin_addr; + freeaddrinfo(result); return 0; - } - return (h_errno == HOST_NOT_FOUND ? ENOENT - : h_errno == TRY_AGAIN ? EAGAIN - : h_errno == NO_RECOVERY ? EIO - : h_errno == NO_ADDRESS ? ENXIO - : EINVAL); +#ifdef EAI_ADDRFAMILY + case EAI_ADDRFAMILY: +#endif + case EAI_NONAME: + case EAI_SERVICE: + return ENOENT; + + case EAI_AGAIN: + return EAGAIN; + + case EAI_BADFLAGS: + case EAI_FAMILY: + case EAI_SOCKTYPE: + return EINVAL; + + case EAI_FAIL: + return EIO; + + case EAI_MEMORY: + return ENOMEM; + +#ifdef EAI_NODATA + case EAI_NODATA: + return ENXIO; +#endif + + case EAI_SYSTEM: + return errno; + + default: + return EPROTO; + } } int