diff options
author | Damien Miller <djm@mindrot.org> | 2001-01-30 09:19:34 +1100 |
---|---|---|
committer | Damien Miller <djm@mindrot.org> | 2001-01-30 09:19:34 +1100 |
commit | d83ff35d66e11978e0b821ecbfa07011ddcb8868 (patch) | |
tree | b4c757a1a9acd2a1acd074a00fce71b30ff2ee48 /canohost.c | |
parent | 5e953217f13b340d8a5fbcd771a1dbaf43354f20 (diff) |
- (djm) OpenBSD CVS Sync:
- markus@cvs.openbsd.org 2001/01/29 12:42:35
[canohost.c canohost.h channels.c clientloop.c]
add get_peer_ipaddr(socket), x11-fwd in ssh2 requires ipaddr, not DNS
Diffstat (limited to 'canohost.c')
-rw-r--r-- | canohost.c | 59 |
1 files changed, 34 insertions, 25 deletions
diff --git a/canohost.c b/canohost.c index 9fa33c260..f3a659328 100644 --- a/canohost.c +++ b/canohost.c | |||
@@ -12,7 +12,7 @@ | |||
12 | */ | 12 | */ |
13 | 13 | ||
14 | #include "includes.h" | 14 | #include "includes.h" |
15 | RCSID("$OpenBSD: canohost.c,v 1.18 2001/01/21 19:05:45 markus Exp $"); | 15 | RCSID("$OpenBSD: canohost.c,v 1.19 2001/01/29 19:42:33 markus Exp $"); |
16 | 16 | ||
17 | #include "packet.h" | 17 | #include "packet.h" |
18 | #include "xmalloc.h" | 18 | #include "xmalloc.h" |
@@ -188,46 +188,55 @@ get_canonical_hostname() | |||
188 | } | 188 | } |
189 | 189 | ||
190 | /* | 190 | /* |
191 | * Returns the IP-address of the remote host as a string. The returned | 191 | * Returns the remote IP-address of socket as a string. The returned |
192 | * string must not be freed. | 192 | * string must be freed. |
193 | */ | 193 | */ |
194 | 194 | ||
195 | const char * | 195 | char * |
196 | get_remote_ipaddr() | 196 | get_peer_ipaddr(int socket) |
197 | { | 197 | { |
198 | static char *canonical_host_ip = NULL; | ||
199 | struct sockaddr_storage from; | 198 | struct sockaddr_storage from; |
200 | socklen_t fromlen; | 199 | socklen_t fromlen; |
201 | int socket; | ||
202 | char ntop[NI_MAXHOST]; | 200 | char ntop[NI_MAXHOST]; |
203 | 201 | ||
204 | /* Check whether we have chached the name. */ | ||
205 | if (canonical_host_ip != NULL) | ||
206 | return canonical_host_ip; | ||
207 | |||
208 | /* If not a socket, return UNKNOWN. */ | ||
209 | if (!packet_connection_is_on_socket()) { | ||
210 | canonical_host_ip = xstrdup("UNKNOWN"); | ||
211 | return canonical_host_ip; | ||
212 | } | ||
213 | /* Get client socket. */ | ||
214 | socket = packet_get_connection_in(); | ||
215 | |||
216 | /* Get IP address of client. */ | 202 | /* Get IP address of client. */ |
217 | fromlen = sizeof(from); | 203 | fromlen = sizeof(from); |
218 | memset(&from, 0, sizeof(from)); | 204 | memset(&from, 0, sizeof(from)); |
219 | if (getpeername(socket, (struct sockaddr *) & from, &fromlen) < 0) { | 205 | if (getpeername(socket, (struct sockaddr *) & from, &fromlen) < 0) { |
220 | debug("getpeername failed: %.100s", strerror(errno)); | 206 | debug("get_peer_ipaddr: getpeername failed: %.100s", strerror(errno)); |
221 | fatal_cleanup(); | 207 | return NULL; |
222 | } | 208 | } |
223 | /* Get the IP address in ascii. */ | 209 | /* Get the IP address in ascii. */ |
224 | if (getnameinfo((struct sockaddr *)&from, fromlen, ntop, sizeof(ntop), | 210 | if (getnameinfo((struct sockaddr *)&from, fromlen, ntop, sizeof(ntop), |
225 | NULL, 0, NI_NUMERICHOST) != 0) | 211 | NULL, 0, NI_NUMERICHOST) != 0) { |
226 | fatal("get_remote_hostname: getnameinfo NI_NUMERICHOST failed"); | 212 | error("get_peer_ipaddr: getnameinfo NI_NUMERICHOST failed"); |
213 | return NULL; | ||
214 | } | ||
215 | return xstrdup(ntop); | ||
216 | } | ||
227 | 217 | ||
228 | canonical_host_ip = xstrdup(ntop); | 218 | /* |
219 | * Returns the IP-address of the remote host as a string. The returned | ||
220 | * string must not be freed. | ||
221 | */ | ||
229 | 222 | ||
230 | /* Return ip address string. */ | 223 | const char * |
224 | get_remote_ipaddr() | ||
225 | { | ||
226 | static char *canonical_host_ip = NULL; | ||
227 | |||
228 | /* Check whether we have cached the ipaddr. */ | ||
229 | if (canonical_host_ip == NULL) { | ||
230 | if (packet_connection_is_on_socket()) { | ||
231 | canonical_host_ip = | ||
232 | get_peer_ipaddr(packet_get_connection_in()); | ||
233 | if (canonical_host_ip == NULL) | ||
234 | fatal_cleanup(); | ||
235 | } else { | ||
236 | /* If not on socket, return UNKNOWN. */ | ||
237 | canonical_host_ip = xstrdup("UNKNOWN"); | ||
238 | } | ||
239 | } | ||
231 | return canonical_host_ip; | 240 | return canonical_host_ip; |
232 | } | 241 | } |
233 | 242 | ||