diff options
author | Colin Watson <cjwatson@debian.org> | 2008-07-22 14:59:59 +0000 |
---|---|---|
committer | Colin Watson <cjwatson@debian.org> | 2008-07-22 14:59:59 +0000 |
commit | ef94e5613d37bcbf880f21ee6094e4b1c7683a4c (patch) | |
tree | eebe1697910d248823033b5d14354c7f5ee8b471 /openbsd-compat/fake-getnameinfo.c | |
parent | 8f42e9b75a55401fa9dfdf14d49fbe5396c6ce92 (diff) | |
parent | 70847d299887abb96f8703ca99db6d817b78960e (diff) |
Import OpenSSH 5.1p1.
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 */ | ||