local IP in environment

Eric Huss e-huss at netmeridian.com
Sat Oct 13 10:04:36 EST 2001


I'm not sure if this is useful to anyone, but I made a small patch to
include the local IP address that the user connected to in the environment
(the opposite of SSH_CLIENT).  The variable is called SSH_LOCAL.

-Eric
-------------- next part --------------
*** openssh-2.9.9p2/canohost.c.bak	Sun Jun 24 22:01:24 2001
--- openssh-2.9.9p2/canohost.c	Fri Oct 12 16:52:09 2001
***************
*** 255,260 ****
--- 255,281 ----
  	return get_socket_address(socket, 0, NI_NAMEREQD);
  }
  
+ const char *
+ get_local_ipaddr2(void)
+ {
+ 	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_local_ipaddr(packet_get_connection_out());
+ 			if (canonical_host_ip == NULL)
+ 				fatal_cleanup();
+ 		} else {
+ 			/* If not on socket, return UNKNOWN. */
+ 			canonical_host_ip = xstrdup("UNKNOWN");
+ 		}
+ 	}
+ 	return canonical_host_ip;
+ }
+ 
+ 
  /*
   * Returns the IP-address of the remote host as a string.  The returned
   * string must not be freed.
*** openssh-2.9.9p2/canohost.h.bak	Tue Jul  3 21:46:57 2001
--- openssh-2.9.9p2/canohost.h	Fri Oct 12 16:52:12 2001
***************
*** 14,19 ****
--- 14,20 ----
  
  const char	*get_canonical_hostname(int);
  const char	*get_remote_ipaddr(void);
+ const char      *get_local_ipaddr2(void);
  const char	*get_remote_name_or_ip(u_int, int);
  
  char		*get_peer_ipaddr(int);
*** openssh-2.9.9p2/session.c.bak	Sun Sep 16 15:17:15 2001
--- openssh-2.9.9p2/session.c	Fri Oct 12 16:52:09 2001
***************
*** 1255,1260 ****
--- 1255,1263 ----
  	snprintf(buf, sizeof buf, "%.50s %d %d",
  		 get_remote_ipaddr(), get_remote_port(), get_local_port());
  	child_set_env(&env, &envsize, "SSH_CLIENT", buf);
+ 	snprintf(buf, sizeof buf, "%.50s",
+ 		 get_local_ipaddr2());
+ 	child_set_env(&env, &envsize, "SSH_LOCAL", buf);
  
  	if (s->ttyfd != -1)
  		child_set_env(&env, &envsize, "SSH_TTY", s->tty);


More information about the openssh-unix-dev mailing list