summaryrefslogtreecommitdiff
path: root/usr.bin/ssh/canohost.c
diff options
context:
space:
mode:
authorMarkus Friedl <markus@cvs.openbsd.org>2001-01-29 19:42:36 +0000
committerMarkus Friedl <markus@cvs.openbsd.org>2001-01-29 19:42:36 +0000
commitdb845f186bda7cece113ce8c619af2c50d6236a1 (patch)
treec57c273ab1811e37dd57eefd984dc6fc8e4d19b4 /usr.bin/ssh/canohost.c
parentfc275459f7ccd34d16a96a1f4d2b4d73477e0b1a (diff)
add get_peer_ipaddr(socket), x11-fwd in ssh2 requires ipaddr, not DNS
Diffstat (limited to 'usr.bin/ssh/canohost.c')
-rw-r--r--usr.bin/ssh/canohost.c59
1 files changed, 34 insertions, 25 deletions
diff --git a/usr.bin/ssh/canohost.c b/usr.bin/ssh/canohost.c
index ceb840050de..8d5a50d5648 100644
--- a/usr.bin/ssh/canohost.c
+++ b/usr.bin/ssh/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"
@@ -164,46 +164,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;
}