Code auditing weekend results and fixes committing.
[silc.git] / lib / silcutil / silcnet.c
index 68a820f6316ec79b5fdb6dc95dc31a817f849b5f..428f764ccaf206d0da33051d70880ddfc5c272db 100644 (file)
   GNU General Public License for more details.
 
 */
-/*
- * $Id$
- * $Log$
- * Revision 1.1  2000/09/13 17:45:16  priikone
- *     Splitted SILC core library. Core library includes now only
- *     SILC protocol specific stuff. New utility library includes the
- *     old stuff from core library that is more generic purpose stuff.
- *
- * Revision 1.3  2000/07/05 06:06:35  priikone
- *     Global cosmetic change.
- *
- * Revision 1.2  2000/06/30 10:49:48  priikone
- *     Added SOCKS4 and SOCKS5 support for SILC client.
- *
- * Revision 1.1.1.1  2000/06/27 11:36:55  priikone
- *     Imported from internal CVS/Added Log headers.
- *
- *
- */
+/* $Id$ */
 
 #include "silcincludes.h"
 #include "silcnet.h"
@@ -149,8 +131,9 @@ int silc_net_create_connection(int port, char *host)
     return -1;
   }
 
-  /* Set appropriate option */
+  /* Set appropriate options */
   silc_net_set_socket_opt(sock, IPPROTO_TCP, TCP_NODELAY, 1);
+  silc_net_set_socket_opt(sock, SOL_SOCKET, SO_KEEPALIVE, 1);
 
   SILC_LOG_DEBUG(("Connection created"));
 
@@ -205,8 +188,9 @@ int silc_net_create_connection_async(int port, char *host)
     }
   }
 
-  /* Set appropriate option */
+  /* Set appropriate options */
   silc_net_set_socket_opt(sock, IPPROTO_TCP, TCP_NODELAY, 1);
+  silc_net_set_socket_opt(sock, SOL_SOCKET, SO_KEEPALIVE, 1);
 
   SILC_LOG_DEBUG(("Connection operation in progress"));
 
@@ -249,7 +233,8 @@ int silc_net_is_ip(const char *addr)
   return inet_aton(addr, &tmp);
 }
 
-/* Performs lookups for remote name and IP address. */
+/* Performs lookups for remote name and IP address. This peforms reverse
+   lookup as well to verify that the IP has FQDN. */
 
 void silc_net_check_host_by_sock(int sock, char **hostname, char **ip)
 {
@@ -277,7 +262,7 @@ void silc_net_check_host_by_sock(int sock, char **hostname, char **ip)
   if (!dest)
     return;
 
-  /* Get same hsot by name to see that the remote host really is
+  /* Get same host by name to see that the remote host really is
      the who it says it is */
   memset(host_name, 0, sizeof(host_name));
   memcpy(host_name, dest->h_name, strlen(dest->h_name));
@@ -304,3 +289,13 @@ void silc_net_check_host_by_sock(int sock, char **hostname, char **ip)
   memcpy(*ip, host_ip, strlen(host_ip));
   SILC_LOG_DEBUG(("Resolved IP address `%s'", *ip));
 }
+
+/* Return name of localhost. */
+
+char *silc_net_localhost()
+{
+  char hostname[256];
+  if (!gethostname(hostname, sizeof(hostname)))
+    return strdup(hostname);
+  return NULL;
+}