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.
14 #include "fake-getnameinfo.h"
15 #include "fake-getaddrinfo.h"
17 #ifndef HAVE_GETNAMEINFO
19 int getnameinfo(const struct sockaddr *sa, size_t salen, char *host, size_t hostlen, char *serv, size_t servlen, int flags) {
20 struct sockaddr_in *sin = (struct sockaddr_in *)sa;
24 if(sa->sa_family != AF_INET)
28 len = snprintf(serv, servlen, "%d", ntohs(sin->sin_port));
29 if(len < 0 || len >= servlen)
36 if(flags & NI_NUMERICHOST) {
37 len = snprintf(host, hostlen, "%s", inet_ntoa(sin->sin_addr));
38 if(len < 0 || len >= hostlen)
43 hp = gethostbyaddr((char *)&sin->sin_addr, sizeof(struct in_addr), AF_INET);
45 if(!hp || !hp->h_name || !hp->h_name[0])
48 len = snprintf(host, hostlen, "%s", hp->h_name);
49 if(len < 0 || len >= hostlen)
54 #endif /* !HAVE_GETNAMEINFO */