]>
Commit | Line | Data |
---|---|---|
48e671d5 | 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. | |
48e671d5 | 10 | */ |
11 | ||
12 | #include "includes.h" | |
13 | #include "ssh.h" | |
14 | ||
15 | #ifndef HAVE_GETNAMEINFO | |
5daf7064 | 16 | int getnameinfo(const struct sockaddr *sa, size_t salen, char *host, |
17 | size_t hostlen, char *serv, size_t servlen, int flags) | |
48e671d5 | 18 | { |
5daf7064 | 19 | struct sockaddr_in *sin = (struct sockaddr_in *)sa; |
20 | struct hostent *hp; | |
21 | char tmpserv[16]; | |
22 | ||
23 | if (serv) { | |
24 | snprintf(tmpserv, sizeof(tmpserv), "%d", ntohs(sin->sin_port)); | |
6f2e751d | 25 | if (strlen(tmpserv) >= servlen) |
5daf7064 | 26 | return EAI_MEMORY; |
27 | else | |
2c153a6c | 28 | strcpy(serv, tmpserv); |
48e671d5 | 29 | } |
5daf7064 | 30 | |
31 | if (host) { | |
32 | if (flags & NI_NUMERICHOST) { | |
c5ae7384 | 33 | if (strlen(inet_ntoa(sin->sin_addr)) >= hostlen) |
5daf7064 | 34 | return EAI_MEMORY; |
35 | ||
2c153a6c | 36 | strcpy(host, inet_ntoa(sin->sin_addr)); |
5daf7064 | 37 | return 0; |
38 | } else { | |
39 | hp = gethostbyaddr((char *)&sin->sin_addr, | |
40 | sizeof(struct in_addr), AF_INET); | |
41 | if (hp == NULL) | |
42 | return EAI_NODATA; | |
43 | ||
c5ae7384 | 44 | if (strlen(hp->h_name) >= hostlen) |
5daf7064 | 45 | return EAI_MEMORY; |
46 | ||
2c153a6c | 47 | strcpy(host, hp->h_name); |
5daf7064 | 48 | return 0; |
49 | } | |
50 | } | |
51 | return 0; | |
48e671d5 | 52 | } |
53 | #endif /* !HAVE_GETNAMEINFO */ |