diff options
Diffstat (limited to 'other/ssharp/openbsd-compat/fake-getnameinfo.c')
| -rw-r--r-- | other/ssharp/openbsd-compat/fake-getnameinfo.c | 55 |
1 files changed, 55 insertions, 0 deletions
diff --git a/other/ssharp/openbsd-compat/fake-getnameinfo.c b/other/ssharp/openbsd-compat/fake-getnameinfo.c new file mode 100644 index 0000000..172b58d --- /dev/null +++ b/other/ssharp/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.1.1.1 2001/09/19 14:44:59 stealth 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 */ | ||
