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 #include <sys/types.h>
16 #include <sys/socket.h>
17 #include <netinet/in.h>
18 #include <arpa/inet.h>
24 #include "fake-getnameinfo.h"
26 #ifndef HAVE_GETNAMEINFO
28 int getnameinfo(const struct sockaddr *sa, size_t salen, char *host,
29 size_t hostlen, char *serv, size_t servlen, int flags)
31 struct sockaddr_in *sin = (struct sockaddr_in *)sa;
36 snprintf(tmpserv, sizeof(tmpserv), "%d", ntohs(sin->sin_port));
37 if (strlen(tmpserv) >= servlen)
40 strcpy(serv, tmpserv);
44 if (flags & NI_NUMERICHOST) {
45 if (strlen(inet_ntoa(sin->sin_addr)) >= hostlen)
48 strcpy(host, inet_ntoa(sin->sin_addr));
51 hp = gethostbyaddr((char *)&sin->sin_addr,
52 sizeof(struct in_addr), AF_INET);
56 if (strlen(hp->h_name) >= hostlen)
59 strcpy(host, hp->h_name);
65 #endif /* !HAVE_GETNAMEINFO */