]> andersk Git - gssapi-openssh.git/blobdiff - openssh/canohost.c
release new patch today
[gssapi-openssh.git] / openssh / canohost.c
index 42011fd0acf2996fe09c10b077444fbfe1aae68f..d154ab80d444fd32f4d210545fbfdc7ec813ec2d 100644 (file)
@@ -1,4 +1,4 @@
-/* $OpenBSD: canohost.c,v 1.63 2008/06/12 00:03:49 dtucker Exp $ */
+/* $OpenBSD: canohost.c,v 1.64 2009/02/12 03:00:56 djm Exp $ */
 /*
  * Author: Tatu Ylonen <ylo@cs.hut.fi>
  * Copyright (c) 1995 Tatu Ylonen <ylo@cs.hut.fi>, Espoo, Finland
@@ -16,6 +16,7 @@
 
 #include <sys/types.h>
 #include <sys/socket.h>
+#include <sys/param.h>          /* for MAXHOSTNAMELEN */
 
 #include <netinet/in.h>
 #include <arpa/inet.h>
@@ -27,6 +28,7 @@
 #include <stdlib.h>
 #include <string.h>
 #include <stdarg.h>
+#include <unistd.h>
 
 #include "xmalloc.h"
 #include "packet.h"
@@ -342,7 +344,7 @@ get_remote_name_or_ip(u_int utmp_len, int use_dns)
 
 /* Returns the local/remote port for the socket. */
 
-static int
+int
 get_sock_port(int sock, int local)
 {
        struct sockaddr_storage from;
@@ -416,3 +418,33 @@ get_local_port(void)
 {
        return get_port(1);
 }
+
+void
+resolve_localhost(char **host)
+{
+    struct hostent *hostinfo;
+
+    hostinfo = gethostbyname(*host);
+    if (hostinfo == NULL || hostinfo->h_name == NULL) {
+       debug("gethostbyname(%s) failed", *host);
+       return;
+    }
+    if (hostinfo->h_addrtype == AF_INET) {
+       struct in_addr addr;
+       addr = *(struct in_addr *)(hostinfo->h_addr);
+       if (ntohl(addr.s_addr) == INADDR_LOOPBACK) {
+           char buf[MAXHOSTNAMELEN];
+           if (gethostname(buf, sizeof(buf)) < 0) {
+               debug("gethostname() failed");
+               return;
+           }
+           hostinfo = gethostbyname(buf);
+           xfree(*host);
+           if (hostinfo == NULL || hostinfo->h_name == NULL) {
+               *host = xstrdup(buf);
+           } else {
+               *host = xstrdup(hostinfo->h_name);
+           }
+       }
+    }
+}
This page took 0.033166 seconds and 4 git commands to generate.