- char ipport[128];
- unsigned char addrbuf[4];
- assert(addrinfo->ai_family == PF_INET);
- memcpy(addrbuf,
- &((struct sockaddr_in*)addrinfo->ai_addr)->sin_addr.s_addr, 4);
- sprintf(ipport, "%u.%u.%u.%u:%s",
- addrbuf[0], addrbuf[1], addrbuf[2], addrbuf[3], port);
- freeaddrinfo(addrinfo);
- w->ipport = xstrdup(ipport);
- yaz_log(log_level, "Resolved %s -> %s", hostport, ipport);
+ if (getnameinfo((struct sockaddr *) res->ai_addr, res->ai_addrlen,
+ host, sizeof(host)-1,
+ 0, 0,
+ NI_NUMERICHOST) == 0)
+ {
+ w->ipport = xmalloc(strlen(host) + (port ? strlen(port) : 0) + 2);
+ strcpy(w->ipport, host);
+ if (port)
+ {
+ strcat(w->ipport, ":");
+ strcat(w->ipport, port);
+ }
+ yaz_log(log_level, "Resolved %s -> %s", w->hostport, w->ipport);
+ }
+ else
+ {
+ yaz_log(YLOG_LOG|YLOG_ERRNO, "getnameinfo failed for %s",
+ w->hostport);
+ }
+ freeaddrinfo(res);