4 * This file includes getnameinfo().
5 * These funtions are defined in rfc2133.
7 * But these functions are not implemented correctly. The minimum subset
8 * is implemented for ssh use only. For exapmle, this routine assumes
9 * that ai_family is AF_INET. Don't use it for another purpose.
15 #ifndef HAVE_GETNAMEINFO
16 int getnameinfo(const struct sockaddr *sa, size_t salen, char *host,
17 size_t hostlen, char *serv, size_t servlen, int flags)
19 struct sockaddr_in *sin = (struct sockaddr_in *)sa;
24 snprintf(tmpserv, sizeof(tmpserv), "%d", ntohs(sin->sin_port));
25 if (strlen(tmpserv) >= servlen)
28 strcpy(serv, tmpserv);
32 if (flags & NI_NUMERICHOST) {
33 if (strlen(inet_ntoa(sin->sin_addr)) >= hostlen)
36 strcpy(host, inet_ntoa(sin->sin_addr));
39 hp = gethostbyaddr((char *)&sin->sin_addr,
40 sizeof(struct in_addr), AF_INET);
44 if (strlen(hp->h_name) >= hostlen)
47 strcpy(host, hp->h_name);
53 #endif /* !HAVE_GETNAMEINFO */