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.
13 #include <sys/types.h>
14 #include <netinet/in.h>
15 #include <sys/socket.h>
16 #ifdef HAVE_ARPA_INET_H
17 #include <arpa/inet.h>
23 #include "fake-getaddrinfo.h"
25 #ifndef HAVE_GETNAMEINFO
26 int getnameinfo(const struct sockaddr *sa, size_t salen, char *host,
27 size_t hostlen, char *serv, size_t servlen, int flags)
29 struct sockaddr_in *sin = (struct sockaddr_in *)sa;
34 snprintf(tmpserv, sizeof(tmpserv), "%d", ntohs(sin->sin_port));
35 if (strlen(tmpserv) >= servlen)
38 strcpy(serv, tmpserv);
42 if (flags & NI_NUMERICHOST) {
43 if (strlen(inet_ntoa(sin->sin_addr)) >= hostlen)
46 strcpy(host, inet_ntoa(sin->sin_addr));
49 hp = gethostbyaddr((char *)&sin->sin_addr,
50 sizeof(struct in_addr), AF_INET);
54 if (strlen(hp->h_name) >= hostlen)
57 strcpy(host, hp->h_name);
63 #endif /* !HAVE_GETNAMEINFO */