]> andersk Git - openssh.git/blame - openbsd-compat/fake-getnameinfo.c
- markus@cvs.openbsd.org 2002/06/08 05:07:56
[openssh.git] / openbsd-compat / fake-getnameinfo.c
CommitLineData
48e671d5 1/*
2 * fake library for ssh
3 *
4 * This file includes getnameinfo().
5 * These funtions are defined in rfc2133.
6 *
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.
48e671d5 10 */
11
12#include "includes.h"
13#include "ssh.h"
14
0b202697 15RCSID("$Id$");
16
48e671d5 17#ifndef HAVE_GETNAMEINFO
5daf7064 18int getnameinfo(const struct sockaddr *sa, size_t salen, char *host,
19 size_t hostlen, char *serv, size_t servlen, int flags)
48e671d5 20{
5daf7064 21 struct sockaddr_in *sin = (struct sockaddr_in *)sa;
22 struct hostent *hp;
23 char tmpserv[16];
24
25 if (serv) {
26 snprintf(tmpserv, sizeof(tmpserv), "%d", ntohs(sin->sin_port));
6f2e751d 27 if (strlen(tmpserv) >= servlen)
5daf7064 28 return EAI_MEMORY;
29 else
2c153a6c 30 strcpy(serv, tmpserv);
48e671d5 31 }
5daf7064 32
33 if (host) {
34 if (flags & NI_NUMERICHOST) {
c5ae7384 35 if (strlen(inet_ntoa(sin->sin_addr)) >= hostlen)
5daf7064 36 return EAI_MEMORY;
37
2c153a6c 38 strcpy(host, inet_ntoa(sin->sin_addr));
5daf7064 39 return 0;
40 } else {
41 hp = gethostbyaddr((char *)&sin->sin_addr,
42 sizeof(struct in_addr), AF_INET);
43 if (hp == NULL)
44 return EAI_NODATA;
45
c5ae7384 46 if (strlen(hp->h_name) >= hostlen)
5daf7064 47 return EAI_MEMORY;
48
2c153a6c 49 strcpy(host, hp->h_name);
5daf7064 50 return 0;
51 }
52 }
53 return 0;
48e671d5 54}
55#endif /* !HAVE_GETNAMEINFO */
This page took 0.127823 seconds and 5 git commands to generate.