Don't getsockopt() SO_ERROR. We get the error from send()/recv() anyway.
[tinc] / lib / fake-getnameinfo.c
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 "system.h"
13
14 #include "fake-getnameinfo.h"
15 #include "fake-getaddrinfo.h"
16
17 #ifndef HAVE_GETNAMEINFO
18
19 int getnameinfo(const struct sockaddr *sa, size_t salen, char *host, 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
24         if(serv)
25                 snprintf(serv, sizeof(tmpserv), "%d", ntohs(sin->sin_port));
26
27         if(!host)
28                 return 0;
29
30         if(flags & NI_NUMERICHOST) {
31                 strncpy(host, inet_ntoa(sin->sin_addr), sizeof(host));
32                 return 0;
33         }
34
35         hp = gethostbyaddr((char *)&sin->sin_addr, sizeof(struct in_addr), AF_INET);
36         
37         if(!hp || !hp->h_name)
38                 return EAI_NODATA;
39         
40         if(strlen(hp->h_name) >= hostlen)
41                 return EAI_MEMORY;
42
43         strncpy(host, hp->h_name, hostlen);
44         return 0;
45 }
46 #endif /* !HAVE_GETNAMEINFO */