summaryrefslogtreecommitdiff
path: root/openbsd-compat/fake-getnameinfo.c
diff options
context:
space:
mode:
Diffstat (limited to 'openbsd-compat/fake-getnameinfo.c')
-rw-r--r--openbsd-compat/fake-getnameinfo.c37
1 files changed, 17 insertions, 20 deletions
diff --git a/openbsd-compat/fake-getnameinfo.c b/openbsd-compat/fake-getnameinfo.c
index e255ed333..f3b0913de 100644
--- a/openbsd-compat/fake-getnameinfo.c
+++ b/openbsd-compat/fake-getnameinfo.c
@@ -12,7 +12,7 @@
12#include "includes.h" 12#include "includes.h"
13#include "ssh.h" 13#include "ssh.h"
14 14
15RCSID("$Id: fake-getnameinfo.c,v 1.2 2001/02/09 01:55:36 djm Exp $"); 15RCSID("$Id: fake-getnameinfo.c,v 1.3 2003/05/18 14:13:39 djm Exp $");
16 16
17#ifndef HAVE_GETNAMEINFO 17#ifndef HAVE_GETNAMEINFO
18int getnameinfo(const struct sockaddr *sa, size_t salen, char *host, 18int getnameinfo(const struct sockaddr *sa, size_t salen, char *host,
@@ -22,34 +22,31 @@ int getnameinfo(const struct sockaddr *sa, size_t salen, char *host,
22 struct hostent *hp; 22 struct hostent *hp;
23 char tmpserv[16]; 23 char tmpserv[16];
24 24
25 if (serv) { 25 if (serv != NULL) {
26 snprintf(tmpserv, sizeof(tmpserv), "%d", ntohs(sin->sin_port)); 26 snprintf(tmpserv, sizeof(tmpserv), "%d", ntohs(sin->sin_port));
27 if (strlen(tmpserv) >= servlen) 27 if (strlcpy(serv, tmpserv, servlen) >= servlen)
28 return EAI_MEMORY; 28 return (EAI_MEMORY);
29 else
30 strcpy(serv, tmpserv);
31 } 29 }
32 30
33 if (host) { 31 if (host != NULL) {
34 if (flags & NI_NUMERICHOST) { 32 if (flags & NI_NUMERICHOST) {
35 if (strlen(inet_ntoa(sin->sin_addr)) >= hostlen) 33 if (strlcpy(host, inet_ntoa(sin->sin_addr),
36 return EAI_MEMORY; 34 hostlen) >= hostlen)
37 35 return (EAI_MEMORY);
38 strcpy(host, inet_ntoa(sin->sin_addr)); 36 else
39 return 0; 37 return (0);
40 } else { 38 } else {
41 hp = gethostbyaddr((char *)&sin->sin_addr, 39 hp = gethostbyaddr((char *)&sin->sin_addr,
42 sizeof(struct in_addr), AF_INET); 40 sizeof(struct in_addr), AF_INET);
43 if (hp == NULL) 41 if (hp == NULL)
44 return EAI_NODATA; 42 return (EAI_NODATA);
45 43
46 if (strlen(hp->h_name) >= hostlen) 44 if (strlcpy(host, hp->h_name, hostlen) >= hostlen)
47 return EAI_MEMORY; 45 return (EAI_MEMORY);
48 46 else
49 strcpy(host, hp->h_name); 47 return (0);
50 return 0;
51 } 48 }
52 } 49 }
53 return 0; 50 return (0);
54} 51}
55#endif /* !HAVE_GETNAMEINFO */ 52#endif /* !HAVE_GETNAMEINFO */