summaryrefslogtreecommitdiff
path: root/canohost.c
diff options
context:
space:
mode:
authorDamien Miller <djm@mindrot.org>2001-01-30 09:19:34 +1100
committerDamien Miller <djm@mindrot.org>2001-01-30 09:19:34 +1100
commitd83ff35d66e11978e0b821ecbfa07011ddcb8868 (patch)
treeb4c757a1a9acd2a1acd074a00fce71b30ff2ee48 /canohost.c
parent5e953217f13b340d8a5fbcd771a1dbaf43354f20 (diff)
downloadopenssh-git-d83ff35d66e11978e0b821ecbfa07011ddcb8868.tar.gz
- (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.c59
1 files changed, 34 insertions, 25 deletions
diff --git a/canohost.c b/canohost.c
index 9fa33c26..f3a65932 100644
--- a/canohost.c
+++ b/canohost.c
@@ -12,7 +12,7 @@
*/
#include "includes.h"
-RCSID("$OpenBSD: canohost.c,v 1.18 2001/01/21 19:05:45 markus Exp $");
+RCSID("$OpenBSD: canohost.c,v 1.19 2001/01/29 19:42:33 markus Exp $");
#include "packet.h"
#include "xmalloc.h"
@@ -188,46 +188,55 @@ get_canonical_hostname()
}
/*
- * Returns the IP-address of the remote host as a string. The returned
- * string must not be freed.
+ * Returns the remote IP-address of socket as a string. The returned
+ * string must be freed.
*/
-const char *
-get_remote_ipaddr()
+char *
+get_peer_ipaddr(int socket)
{
- static char *canonical_host_ip = NULL;
struct sockaddr_storage from;
socklen_t fromlen;
- int socket;
char ntop[NI_MAXHOST];
- /* Check whether we have chached the name. */
- if (canonical_host_ip != NULL)
- return canonical_host_ip;
-
- /* If not a socket, return UNKNOWN. */
- if (!packet_connection_is_on_socket()) {
- canonical_host_ip = xstrdup("UNKNOWN");
- return canonical_host_ip;
- }
- /* Get client socket. */
- socket = packet_get_connection_in();
-
/* Get IP address of client. */
fromlen = sizeof(from);
memset(&from, 0, sizeof(from));
if (getpeername(socket, (struct sockaddr *) & from, &fromlen) < 0) {
- debug("getpeername failed: %.100s", strerror(errno));
- fatal_cleanup();
+ debug("get_peer_ipaddr: getpeername failed: %.100s", strerror(errno));
+ return NULL;
}
/* Get the IP address in ascii. */
if (getnameinfo((struct sockaddr *)&from, fromlen, ntop, sizeof(ntop),
- NULL, 0, NI_NUMERICHOST) != 0)
- fatal("get_remote_hostname: getnameinfo NI_NUMERICHOST failed");
+ NULL, 0, NI_NUMERICHOST) != 0) {
+ error("get_peer_ipaddr: getnameinfo NI_NUMERICHOST failed");
+ return NULL;
+ }
+ return xstrdup(ntop);
+}
- canonical_host_ip = xstrdup(ntop);
+/*
+ * Returns the IP-address of the remote host as a string. The returned
+ * string must not be freed.
+ */
- /* Return ip address string. */
+const char *
+get_remote_ipaddr()
+{
+ static char *canonical_host_ip = NULL;
+
+ /* Check whether we have cached the ipaddr. */
+ if (canonical_host_ip == NULL) {
+ if (packet_connection_is_on_socket()) {
+ canonical_host_ip =
+ get_peer_ipaddr(packet_get_connection_in());
+ if (canonical_host_ip == NULL)
+ fatal_cleanup();
+ } else {
+ /* If not on socket, return UNKNOWN. */
+ canonical_host_ip = xstrdup("UNKNOWN");
+ }
+ }
return canonical_host_ip;
}