- if (Res == EAI_SERVICE)
- return _error->Error("Could not resolve service '%s'",S);
-
- if (Res == EAI_NONAME)
- return _error->Error("Could not resolve '%s'",Host.c_str());
-
- return _error->Error("Something wicked happend resolving '%s/%s'",
- Host.c_str(),S);
+ int Res;
+ if ((Res = getaddrinfo(Host.c_str(),ServStr,&Hints,&LastHostAddr)) != 0 ||
+ LastHostAddr == 0)
+ {
+ if (Res == EAI_NONAME || Res == EAI_SERVICE)
+ {
+ if (DefPort != 0)
+ {
+ snprintf(ServStr, sizeof(ServStr), "%i", DefPort);
+ DefPort = 0;
+ continue;
+ }
+ bad_addr.insert(bad_addr.begin(), Host);
+ Owner->SetFailReason("ResolveFailure");
+ return _error->Error(_("Could not resolve '%s'"),Host.c_str());
+ }
+
+ if (Res == EAI_AGAIN)
+ {
+ Owner->SetFailReason("TmpResolveFailure");
+ return _error->Error(_("Temporary failure resolving '%s'"),
+ Host.c_str());
+ }
+ if (Res == EAI_SYSTEM)
+ return _error->Errno("getaddrinfo", _("System error resolving '%s:%s'"),
+ Host.c_str(),ServStr);
+ return _error->Error(_("Something wicked happened resolving '%s:%s' (%i - %s)"),
+ Host.c_str(),ServStr,Res,gai_strerror(Res));
+ }
+ break;