#endif
char hbuf[NI_MAXHOST];
- if (sa && getnameinfo(sa, saSize, hbuf, sizeof(hbuf), 0, 0, 0) == 0)
+ int result = (sa ? ::getnameinfo(sa, saSize, hbuf, sizeof(hbuf), 0, 0, 0) : EAI_NONAME);
+ if (result == 0) {
results.setHostName(QString::fromLatin1(hbuf));
+ } else if (result == EAI_NONAME || result == EAI_FAIL
+#ifdef EAI_NODATA
+ // EAI_NODATA is deprecated in RFC 3493
+ || result == EAI_NODATA
+#endif
+ ) {
+ results.setError(QHostInfo::HostNotFound);
+ results.setErrorString(tr("Host not found"));
+ } else {
+ results.setError(QHostInfo::UnknownError);
+ results.setErrorString(QString::fromLocal8Bit(gai_strerror(result)));
+ }
#else
in_addr_t inetaddr = ::inet_addr(hostName.toLatin1().constData());
struct hostent *ent = gethostbyaddr((const char *)&inetaddr, sizeof(inetaddr), AF_INET);
- if (ent)
+ if (ent) {
results.setHostName(QString::fromLatin1(ent->h_name));
+ } else if (h_errno == HOST_NOT_FOUND || h_errno == NO_DATA || h_errno == NO_ADDRESS) {
+ results.setError(QHostInfo::HostNotFound);
+ results.setErrorString(tr("Host not found"));
+ } else {
+ results.setError(QHostInfo::UnknownError);
+ results.setErrorString(tr("Unknown error"));
+ }
#endif
if (results.hostName().isEmpty())
results.setAddresses(addresses);
freeaddrinfo(res);
- } else if (result == EAI_NONAME
- || result == EAI_FAIL
+ } else if (result == EAI_NONAME || result == EAI_FAIL
#ifdef EAI_NODATA
- // EAI_NODATA is deprecated in RFC 3493
- || result == EAI_NODATA
+ // EAI_NODATA is deprecated in RFC 3493
+ || result == EAI_NODATA
#endif
- ) {
+ ) {
results.setError(QHostInfo::HostNotFound);
results.setErrorString(tr("Host not found"));
} else {