Damien Miller | 34132e5 | 2000-01-14 15:45:46 +1100 | [diff] [blame] | 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. |
Damien Miller | 34132e5 | 2000-01-14 15:45:46 +1100 | [diff] [blame] | 10 | */ |
| 11 | |
| 12 | #include "includes.h" |
| 13 | #include "ssh.h" |
| 14 | |
Damien Miller | e9cf357 | 2001-02-09 12:55:35 +1100 | [diff] [blame] | 15 | RCSID("$Id: fake-getnameinfo.c,v 1.2 2001/02/09 01:55:36 djm Exp $"); |
| 16 | |
Damien Miller | 34132e5 | 2000-01-14 15:45:46 +1100 | [diff] [blame] | 17 | #ifndef HAVE_GETNAMEINFO |
Damien Miller | 2f6a0ad | 2000-05-31 11:20:11 +1000 | [diff] [blame] | 18 | int getnameinfo(const struct sockaddr *sa, size_t salen, char *host, |
| 19 | size_t hostlen, char *serv, size_t servlen, int flags) |
Damien Miller | 34132e5 | 2000-01-14 15:45:46 +1100 | [diff] [blame] | 20 | { |
Damien Miller | 2f6a0ad | 2000-05-31 11:20:11 +1000 | [diff] [blame] | 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)); |
Damien Miller | e9edd7c | 2000-09-29 10:59:14 +1100 | [diff] [blame] | 27 | if (strlen(tmpserv) >= servlen) |
Damien Miller | 2f6a0ad | 2000-05-31 11:20:11 +1000 | [diff] [blame] | 28 | return EAI_MEMORY; |
| 29 | else |
Damien Miller | ecf5830 | 2000-09-26 13:13:26 +1100 | [diff] [blame] | 30 | strcpy(serv, tmpserv); |
Damien Miller | 34132e5 | 2000-01-14 15:45:46 +1100 | [diff] [blame] | 31 | } |
Damien Miller | 2f6a0ad | 2000-05-31 11:20:11 +1000 | [diff] [blame] | 32 | |
| 33 | if (host) { |
| 34 | if (flags & NI_NUMERICHOST) { |
Damien Miller | e772b68 | 2000-09-26 13:10:37 +1100 | [diff] [blame] | 35 | if (strlen(inet_ntoa(sin->sin_addr)) >= hostlen) |
Damien Miller | 2f6a0ad | 2000-05-31 11:20:11 +1000 | [diff] [blame] | 36 | return EAI_MEMORY; |
| 37 | |
Damien Miller | ecf5830 | 2000-09-26 13:13:26 +1100 | [diff] [blame] | 38 | strcpy(host, inet_ntoa(sin->sin_addr)); |
Damien Miller | 2f6a0ad | 2000-05-31 11:20:11 +1000 | [diff] [blame] | 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 | |
Damien Miller | e772b68 | 2000-09-26 13:10:37 +1100 | [diff] [blame] | 46 | if (strlen(hp->h_name) >= hostlen) |
Damien Miller | 2f6a0ad | 2000-05-31 11:20:11 +1000 | [diff] [blame] | 47 | return EAI_MEMORY; |
| 48 | |
Damien Miller | ecf5830 | 2000-09-26 13:13:26 +1100 | [diff] [blame] | 49 | strcpy(host, hp->h_name); |
Damien Miller | 2f6a0ad | 2000-05-31 11:20:11 +1000 | [diff] [blame] | 50 | return 0; |
| 51 | } |
| 52 | } |
| 53 | return 0; |
Damien Miller | 34132e5 | 2000-01-14 15:45:46 +1100 | [diff] [blame] | 54 | } |
| 55 | #endif /* !HAVE_GETNAMEINFO */ |