*** canohost.c	2003-06-16 18:48:56.000000000 +0100
--- canohost_new.c	2003-09-23 17:38:33.000000000 +0100
***************
*** 26,31 ****
--- 26,104 ----
   * caller should free the returned string with xfree.
   */
  
+ const char *
+ get_local_hostname(int socket)
+ {
+         struct sockaddr_storage addr_6or4;
+         int i;
+         socklen_t addr_6or4_len;
+         char name[NI_MAXHOST], ntop[NI_MAXHOST];
+ 
+         /* Get local IP address*/
+         addr_6or4_len = sizeof(addr_6or4);
+         memset(&addr_6or4, 0, sizeof(addr_6or4));
+         if (getsockname(socket, (struct sockaddr *) &addr_6or4, &addr_6or4_len) < 0) {
+                 debug("getsockname failed: %.100s", strerror(errno));
+                 fatal_cleanup();
+         }
+ #ifdef IPV4_IN_IPV6
+         if (addr_6or4.ss_family == AF_INET6) {
+                 struct sockaddr_in6 *addr6 = (struct sockaddr_in6 *)&addr_6or4;
+ 
+                 /* Detect IPv4 in IPv6 mapped address and convert it to */
+                 /* plain (AF_INET) IPv4 address */
+                 if (IN6_IS_ADDR_V4MAPPED(&addr6->sin6_addr)) {
+                         struct sockaddr_in *addr4 = (struct sockaddr_in *)&addr_6or4;
+                         struct in_addr addr;
+                         u_int16_t port;
+ 
+                         memcpy(&addr, ((char *)&addr6->sin6_addr) + 12, sizeof(addr));
+                         port = addr6->sin6_port;
+ 
+                         memset(&addr_6or4, 0, sizeof(addr_6or4));
+ 
+                         addr4->sin_family = AF_INET;
+                         memcpy(&addr4->sin_addr, &addr, sizeof(addr));
+                         addr4->sin_port = port;
+                 }
+         }
+ #endif
+         if (addr_6or4.ss_family == AF_INET)
+                 check_ip_options(socket, ntop);
+ 
+         if (getnameinfo((struct sockaddr *)&addr_6or4, addr_6or4_len, ntop, sizeof(ntop),
+             NULL, 0, NI_NUMERICHOST) != 0)
+                 fatal("get_local_hostname: getnameinfo NI_NUMERICHOST failed");
+ 
+         debug3("Trying to resolve local address %.100s to hostname", ntop);
+         /* Map the IP address to a host name. */
+         if (getnameinfo((struct sockaddr *)&addr_6or4, addr_6or4_len, name, sizeof(name),
+             NULL, 0, NI_NAMEREQD) != 0) {
+                 /* Host name not found.  Use ip address. */
+                 log("Could not resolve local address %.100s to hostname", ntop);
+                 return xstrdup(ntop);
+         }
+ 
+         /* Got host name. */
+         name[sizeof(name) - 1] = '\0';
+         /*
+          * Convert it to all lowercase (which is expected by the rest
+          * of this software).
+          */
+         for (i = 0; name[i]; i++)
+                 if (isupper(name[i]))
+                         name[i] = tolower(name[i]);
+ 
+         debug("Resolved local address %.100s to hostname %s", ntop,name);
+ 
+         return xstrdup(name);
+ }
+ 
+ /*
+  * Return the canonical name of the host at the other end of the socket. The
+  * caller should free the returned string with xfree.
+  */
+ 
  static char *
  get_remote_hostname(int socket, int verify_reverse_mapping)
  {
*** canohost.h	2003-09-23 17:37:57.000000000 +0100
--- canohost_new.h	2003-09-23 17:38:27.000000000 +0100
***************
*** 15,20 ****
--- 15,21 ----
  const char	*get_canonical_hostname(int);
  const char	*get_remote_ipaddr(void);
  const char	*get_remote_name_or_ip(u_int, int);
+ const char      *get_local_hostname(int);
  
  char		*get_peer_ipaddr(int);
  int		 get_peer_port(int);
*** gss-genr.c	2003-06-16 18:51:03.000000000 +0100
--- gss-genr_new.c	2003-09-23 17:38:47.000000000 +0100
***************
*** 38,43 ****
--- 38,44 ----
  #include "log.h"
  #include "compat.h"
  #include "monitor_wrap.h"
+ #include "canohost.h"
  
  #include <netdb.h>
  
***************
*** 395,409 ****
  OM_uint32
  ssh_gssapi_acquire_cred(Gssctxt *ctx) {
  	OM_uint32 status;
! 	char lname[MAXHOSTNAMELEN];
  	gss_OID_set oidset;
  	
  	gss_create_empty_oid_set(&status,&oidset);
  	gss_add_oid_set_member(&status,ctx->oid,&oidset);
  
!         if (gethostname(lname, MAXHOSTNAMELEN)) {
!                 return(-1);
!         }
  	if (GSS_ERROR(ssh_gssapi_import_name(ctx,lname))) {
  		return(ctx->major);
  	}
--- 396,408 ----
  OM_uint32
  ssh_gssapi_acquire_cred(Gssctxt *ctx) {
  	OM_uint32 status;
! 	char *lname;
  	gss_OID_set oidset;
  	
  	gss_create_empty_oid_set(&status,&oidset);
  	gss_add_oid_set_member(&status,ctx->oid,&oidset);
  
!         lname = get_local_hostname(packet_get_connection_in());
  	if (GSS_ERROR(ssh_gssapi_import_name(ctx,lname))) {
  		return(ctx->major);
  	}
