diff options
author | Colin Watson <cjwatson@debian.org> | 2007-06-12 11:03:36 +0000 |
---|---|---|
committer | Colin Watson <cjwatson@debian.org> | 2007-06-12 11:03:36 +0000 |
commit | 086ea76990b1e6287c24b6db74adffd4605eb3b0 (patch) | |
tree | 4650093038f9f66b02823fb07f49d6a4becd1667 /openbsd-compat/fake-getnameinfo.c | |
parent | 4ee72c71e31226c81743439fe1ed2b521b5ddb7e (diff) | |
parent | 3e2e0ac10674d77618c4c7339e18b83ced247492 (diff) |
Import OpenSSH 4.6p1.
Diffstat (limited to 'openbsd-compat/fake-getnameinfo.c')
-rw-r--r-- | openbsd-compat/fake-getnameinfo.c | 55 |
1 files changed, 55 insertions, 0 deletions
diff --git a/openbsd-compat/fake-getnameinfo.c b/openbsd-compat/fake-getnameinfo.c new file mode 100644 index 000000000..e255ed333 --- /dev/null +++ b/openbsd-compat/fake-getnameinfo.c | |||
@@ -0,0 +1,55 @@ | |||
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 | |||
15 | RCSID("$Id: fake-getnameinfo.c,v 1.2 2001/02/09 01:55:36 djm Exp $"); | ||
16 | |||
17 | #ifndef HAVE_GETNAMEINFO | ||
18 | int 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 */ | ||