diff options
author | Damien Miller <djm@mindrot.org> | 2003-05-19 00:13:38 +1000 |
---|---|---|
committer | Damien Miller <djm@mindrot.org> | 2003-05-19 00:13:38 +1000 |
commit | 317412502b900ddecdafdfa171da99271846478b (patch) | |
tree | 2e04f618288cdf0c16a98b675b28b8287a15a0c6 /openbsd-compat/fake-getnameinfo.c | |
parent | e323df6c4851b04386e747a009474f469fe97137 (diff) |
- (djm) Big KNF on openbsd-compat/
Diffstat (limited to 'openbsd-compat/fake-getnameinfo.c')
-rw-r--r-- | openbsd-compat/fake-getnameinfo.c | 37 |
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 | ||
15 | RCSID("$Id: fake-getnameinfo.c,v 1.2 2001/02/09 01:55:36 djm Exp $"); | 15 | RCSID("$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 |
18 | int getnameinfo(const struct sockaddr *sa, size_t salen, char *host, | 18 | int 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 */ |