@@ -25,11 +25,11 @@ #import "macros.h" #import "resolver.h" #if !defined(HAVE_THREADSAFE_GETADDRINFO) && defined(OF_HAVE_THREADS) -# include "OFMutex.h" +# include "threading.h" #endif #import "OFAddressTranslationFailedException.h" #import "OFInitializationFailedException.h" #import "OFInvalidArgumentException.h" @@ -72,13 +72,17 @@ if (!of_mutex_lock(&mutex)) @throw [OFLockFailedException exception]; @try { # endif - if (getaddrinfo([host UTF8String], portCString, &hints, &res0)) + int error; + + if ((error = getaddrinfo([host UTF8String], portCString, &hints, + &res0)) != 0) @throw [OFAddressTranslationFailedException - exceptionWithHost: host]; + exceptionWithHost: host + error: error]; count = 0; for (res = res0; res != NULL; res = res->ai_next) count++; @@ -89,20 +93,20 @@ } if ((ret = calloc(count + 1, sizeof(*ret))) == NULL) { freeaddrinfo(res0); @throw [OFOutOfMemoryException - exceptionWithRequestedSize: - (count + 1) * sizeof(*ret)]; + exceptionWithRequestedSize: (count + 1) * + sizeof(*ret)]; } if ((results = malloc(count * sizeof(*results))) == NULL) { freeaddrinfo(res0); free(ret); @throw [OFOutOfMemoryException - exceptionWithRequestedSize: - count * sizeof(*results)]; + exceptionWithRequestedSize: count * + sizeof(*results)]; } for (retIter = ret, resultsIter = results, res = res0; res != NULL; retIter++, resultsIter++, res = res->ai_next) { resultsIter->family = res->ai_family; @@ -178,11 +182,12 @@ } if ((he = gethostbyname([host UTF8String])) == NULL || he->h_addrtype != AF_INET) @throw [OFAddressTranslationFailedException - exceptionWithHost: host]; + exceptionWithHost: host + error: h_errno]; count = 0; for (ip = he->h_addr_list; *ip != NULL; ip++) count++; @@ -190,18 +195,18 @@ @throw [OFAddressTranslationFailedException exceptionWithHost: host]; if ((ret = calloc(count + 1, sizeof(*ret))) == NULL) @throw [OFOutOfMemoryException - exceptionWithRequestedSize: - (count + 1) * sizeof(*ret)]; + exceptionWithRequestedSize: (count + 1) * + sizeof(*ret)]; if ((results = malloc(count * sizeof(*results))) == NULL) { free(ret); @throw [OFOutOfMemoryException - exceptionWithRequestedSize: - count * sizeof(*results)]; + exceptionWithRequestedSize: count * + sizeof(*results)]; } if ((addrs = calloc(count, sizeof(*addrs))) == NULL) { free(ret); free(results); @@ -251,14 +256,18 @@ if (!of_mutex_lock(&mutex)) @throw [OFLockFailedException exception]; @try { # endif + int error; + /* FIXME: Add NI_DGRAM for UDP? */ - if (getnameinfo(address, addressLength, hostCString, NI_MAXHOST, - portCString, NI_MAXSERV, NI_NUMERICHOST | NI_NUMERICSERV)) - @throw [OFAddressTranslationFailedException exception]; + if ((error = getnameinfo(address, addressLength, hostCString, + NI_MAXHOST, portCString, NI_MAXSERV, + NI_NUMERICHOST | NI_NUMERICSERV)) != 0) + @throw [OFAddressTranslationFailedException + exceptionWithError: error]; if (host != NULL) *host = [OFString stringWithUTF8String: hostCString]; if (port != NULL) { @@ -293,11 +302,12 @@ @try { # endif if ((hostCString = inet_ntoa( ((struct sockaddr_in*)(void*)address)->sin_addr)) == NULL) - @throw [OFAddressTranslationFailedException exception]; + @throw [OFAddressTranslationFailedException + exceptionWithError: h_errno]; if (host != NULL) *host = [OFString stringWithUTF8String: hostCString]; if (port != NULL)