]> andersk Git - gssapi-openssh.git/blame - openssh/openbsd-compat/fake-getnameinfo.c
no longer included in OpenSSH distribution
[gssapi-openssh.git] / openssh / openbsd-compat / fake-getnameinfo.c
CommitLineData
3c0ef626 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.
10 */
11
12#include "includes.h"
13#include "ssh.h"
14
15RCSID("$Id$");
16
17#ifndef HAVE_GETNAMEINFO
18int getnameinfo(const struct sockaddr *sa, size_t salen, char *host,
19 size_t hostlen, char *serv, size_t servlen, int flags)
20{
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));
27 if (strlen(tmpserv) >= servlen)
28 return EAI_MEMORY;
29 else
30 strcpy(serv, tmpserv);
31 }
32
33 if (host) {
34 if (flags & NI_NUMERICHOST) {
35 if (strlen(inet_ntoa(sin->sin_addr)) >= hostlen)
36 return EAI_MEMORY;
37
38 strcpy(host, inet_ntoa(sin->sin_addr));
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
46 if (strlen(hp->h_name) >= hostlen)
47 return EAI_MEMORY;
48
49 strcpy(host, hp->h_name);
50 return 0;
51 }
52 }
53 return 0;
54}
55#endif /* !HAVE_GETNAMEINFO */
This page took 0.057436 seconds and 5 git commands to generate.