summaryrefslogtreecommitdiffstats
path: root/crypto/openssh/canohost.c
diff options
context:
space:
mode:
authorgreen <green@FreeBSD.org>2000-06-26 05:44:23 +0000
committergreen <green@FreeBSD.org>2000-06-26 05:44:23 +0000
commit9bccae4f2e267ca62056b16d55b797317a3060a6 (patch)
treee7fa8720c8c45d3a71b8303040261663e3c13769 /crypto/openssh/canohost.c
parent1f6b02c5a30aeb0ad40e2c490bd13805890ab99c (diff)
downloadFreeBSD-src-9bccae4f2e267ca62056b16d55b797317a3060a6.zip
FreeBSD-src-9bccae4f2e267ca62056b16d55b797317a3060a6.tar.gz
Make rate limiting work per-listening-socket. Log better messages than
before for this, requiring a new function (get_ipaddr()). canohost.c receives a $FreeBSD$ line. Suggested by: Niels Provos <niels@OpenBSD.org>
Diffstat (limited to 'crypto/openssh/canohost.c')
-rw-r--r--crypto/openssh/canohost.c32
1 files changed, 31 insertions, 1 deletions
diff --git a/crypto/openssh/canohost.c b/crypto/openssh/canohost.c
index a73f8d0..306ec06 100644
--- a/crypto/openssh/canohost.c
+++ b/crypto/openssh/canohost.c
@@ -11,6 +11,7 @@
*
* Functions for returning the canonical host name of the remote site.
*
+ * $FreeBSD$
*/
#include "includes.h"
@@ -201,7 +202,7 @@ get_remote_ipaddr()
/* 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");
+ fatal("get_remote_ipaddr: getnameinfo NI_NUMERICHOST failed");
canonical_host_ip = xstrdup(ntop);
@@ -209,6 +210,35 @@ get_remote_ipaddr()
return canonical_host_ip;
}
+/*
+ * Returns the IP-address of the local host as a string. The returned
+ * string must be freed.
+ */
+
+const char *
+get_ipaddr(int socket)
+{
+ static char *canonical_host_ip = NULL;
+ struct sockaddr_storage from;
+ socklen_t fromlen;
+ char ntop[NI_MAXHOST];
+
+ /* Get IP address of server. */
+ fromlen = sizeof(from);
+ memset(&from, 0, sizeof(from));
+ if (getsockname(socket, (struct sockaddr *)&from, &fromlen) < 0) {
+ debug("getsockname failed: %.100s", strerror(errno));
+ fatal_cleanup();
+ }
+ /* Get the IP address in ascii. */
+ if (getnameinfo((struct sockaddr *)&from, fromlen, ntop, sizeof(ntop),
+ NULL, 0, NI_NUMERICHOST) != 0)
+ fatal("get_local_ipaddr: getnameinfo NI_NUMERICHOST failed");
+
+ /* Return ip address string. */
+ return xstrdup(ntop);
+}
+
/* Returns the local/remote port for the socket. */
int
OpenPOWER on IntegriCloud