2002-06-09 15:26:10 +00:00
|
|
|
/*
|
|
|
|
* fake library for ssh
|
|
|
|
*
|
|
|
|
* This file includes getnameinfo().
|
|
|
|
* These funtions are defined in rfc2133.
|
|
|
|
*
|
|
|
|
* But these functions are not implemented correctly. The minimum subset
|
|
|
|
* is implemented for ssh use only. For exapmle, this routine assumes
|
|
|
|
* that ai_family is AF_INET. Don't use it for another purpose.
|
|
|
|
*/
|
|
|
|
|
2003-07-17 15:06:27 +00:00
|
|
|
#include "system.h"
|
2002-06-09 15:26:10 +00:00
|
|
|
|
2002-07-12 11:45:21 +00:00
|
|
|
#include "fake-getnameinfo.h"
|
2003-01-17 00:43:58 +00:00
|
|
|
#include "fake-getaddrinfo.h"
|
2002-06-09 15:26:10 +00:00
|
|
|
|
|
|
|
#ifndef HAVE_GETNAMEINFO
|
|
|
|
|
2003-08-16 12:10:28 +00:00
|
|
|
int getnameinfo(const struct sockaddr *sa, size_t salen, char *host, size_t hostlen, char *serv, size_t servlen, int flags)
|
2002-06-09 15:26:10 +00:00
|
|
|
{
|
|
|
|
struct sockaddr_in *sin = (struct sockaddr_in *)sa;
|
|
|
|
struct hostent *hp;
|
2003-08-17 08:32:39 +00:00
|
|
|
int len;
|
2002-06-09 15:26:10 +00:00
|
|
|
|
2003-08-17 08:32:39 +00:00
|
|
|
if(sa->sa_family != AF_INET)
|
|
|
|
return EAI_FAMILY;
|
2003-08-16 12:10:28 +00:00
|
|
|
|
2003-08-17 08:32:39 +00:00
|
|
|
if(serv && servlen) {
|
|
|
|
len = snprintf(serv, servlen, "%d", ntohs(sin->sin_port));
|
|
|
|
if(len < 0 || len >= servlen)
|
|
|
|
return EAI_MEMORY;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(!host || !hostlen)
|
2003-08-16 12:10:28 +00:00
|
|
|
return 0;
|
|
|
|
|
|
|
|
if(flags & NI_NUMERICHOST) {
|
2003-08-17 12:03:40 +00:00
|
|
|
len = snprintf(host, hostlen, "%s", inet_ntoa(sin->sin_addr));
|
2003-08-17 08:32:39 +00:00
|
|
|
if(len < 0 || len >= hostlen)
|
|
|
|
return EAI_MEMORY;
|
2003-08-16 12:10:28 +00:00
|
|
|
return 0;
|
2002-06-09 15:26:10 +00:00
|
|
|
}
|
2003-08-16 12:10:28 +00:00
|
|
|
|
|
|
|
hp = gethostbyaddr((char *)&sin->sin_addr, sizeof(struct in_addr), AF_INET);
|
|
|
|
|
2003-08-17 08:32:39 +00:00
|
|
|
if(!hp || !hp->h_name || !hp->h_name[0])
|
2003-08-16 12:10:28 +00:00
|
|
|
return EAI_NODATA;
|
|
|
|
|
2003-08-17 12:03:40 +00:00
|
|
|
len = snprintf(host, hostlen, "%s", hp->h_name);
|
2003-08-17 08:32:39 +00:00
|
|
|
if(len < 0 || len >= hostlen)
|
2003-08-16 12:10:28 +00:00
|
|
|
return EAI_MEMORY;
|
|
|
|
|
2002-06-09 15:26:10 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
#endif /* !HAVE_GETNAMEINFO */
|