h = gethostbyaddr((void *)&(((struct sockaddr_in *)sa)->sin_addr), sizeof(struct in_addr), AF_INET); endhostent(); };
while (__gethostbyaddr_r((void *)&(((struct sockaddr_in *)sa)->sin_addr), sizeof(struct in_addr), AF_INET, &th, tmpbuf, tmpbuflen, &h, &herrno)) { if (errno == ERANGE) { tmpbuflen *= 2; tmpbuf = __alloca(tmpbuflen); } else { break; } } } }
int getnameinfo(const struct sockaddr *sa, size_t addrlen, char *host, size_t hostlen, char *serv, size_t servlen, int flags){  int serrno = errno;  if (!sa)    return -1;  if (host && (hostlen > 0))    switch(sa->sa_family) {      case AF_INET:#if INET6      case AF_INET6:#endif /* INET6 */	if (!(flags & NI_NUMERICHOST)) {	  struct hostent *h = NULL;#if HOSTTABLE#if INET6	  if (sa->sa_family == AF_INET6)	    h = _addr2hostname_hosts((void *)&(((struct sockaddr_in6 *)sa)->sin6_addr), sizeof(struct in6_addr), AF_INET6);	  else#endif /* INET6 */	    h = _addr2hostname_hosts((void *)&(((struct sockaddr_in *)sa)->sin_addr), sizeof(struct in_addr), AF_INET);#endif /* HOSTTABLE */#if RESOLVER	  if (!h) {#if INET6	    if (sa->sa_family == AF_INET6)	      h = gethostbyaddr((void *)&(((struct sockaddr_in6 *)sa)->sin6_addr), sizeof(struct in6_addr), AF_INET6);	    else#endif /* INET6 */	      h = gethostbyaddr((void *)&(((struct sockaddr_in *)sa)->sin_addr), sizeof(struct in_addr), AF_INET);	    endhostent();	  };#endif /* RESOLVER */	  if (h) {	    if (flags & NI_NOFQDN) {	      char *c;	      if ((c = nrl_domainname()) && (c = strstr(h->h_name, c)) && (c != h->h_name) && (*(--c) == '.')) {		strncpy(host, h->h_name, min(hostlen, (c - h->h_name)));		break;	      };	    };	    strncpy(host, h->h_name, hostlen);	    break;	  };	};	if (flags & NI_NAMEREQD)	  goto fail;        {	  const char *c;#if INET6	  if (sa->sa_family == AF_INET6)	    c = inet_ntop(AF_INET6, (void *)&(((struct sockaddr_in6 *)sa)->sin6_addr), host, hostlen);	  else#endif /* INET6 */	    c = inet_ntop(AF_INET, (void *)&(((struct sockaddr_in *)sa)->sin_addr), host, hostlen);	  if (!c)	    goto fail;	};	break;#if LOCAL      case AF_LOCAL:	if (!(flags & NI_NUMERICHOST)) {	  struct utsname utsname;	  if (!uname(&utsname)) {	    strncpy(host, utsname.nodename, hostlen);	    break;	  };	};	if (flags & NI_NAMEREQD)	  goto fail;	strncpy(host, "localhost", hostlen);	break;#endif /* LOCAL */      default:        return -1;    };  if (serv && (servlen > 0))    switch(sa->sa_family) {      case AF_INET:#if INET6      case AF_INET6:#endif /* INET6 */	if (!(flags & NI_NUMERICSERV)) {	  struct servent *s;	  if (s = getservbyport(((struct sockaddr_in *)sa)->sin_port, (flags & NI_DGRAM) ? "udp" : "tcp")) {	    strncpy(serv, s->s_name, servlen);	    break;	  };	};	snprintf(serv, servlen, "%d", ntohs(((struct sockaddr_in *)sa)->sin_port));	break;#if LOCAL      case AF_LOCAL:	strncpy(serv, ((struct sockaddr_un *)sa)->sun_path, servlen);	break;#endif /* LOCAL */    };  if (host && (hostlen > 0))    host[hostlen-1] = 0;  if (serv && (servlen > 0))    serv[servlen-1] = 0;  errno = serrno;  return 0;fail:  errno = serrno;  return -1;};