updates.
[silc.git] / lib / silcutil / silcnet.c
index 35d6427099c9a0b71c9286c988b33847b8d7cb33..0101faae4d344522048cd24f515cf539df633f40 100644 (file)
@@ -215,10 +215,11 @@ uint16 silc_net_get_local_port(int sock)
 
 /* Return name of localhost. */
 
-char *silc_net_localhost()
+char *silc_net_localhost(void)
 {
   char hostname[256];
   struct hostent *dest;
+  char *h;
 
   if (gethostname(hostname, sizeof(hostname)))
     return NULL;
@@ -227,5 +228,34 @@ char *silc_net_localhost()
   if (!dest)
     return strdup(hostname);
 
+  h = strdup(dest->h_name);
+  dest = gethostbyaddr((char *)dest->h_addr_list[0],
+                      sizeof(struct in_addr), AF_INET);
+  if (!dest)
+    return h;
+
+  silc_free(h);
   return strdup(dest->h_name);
 }
+
+/* Returns local IP address */
+
+char *silc_net_localip(void)
+{
+  char hostname[256];
+  struct hostent *dest;
+  struct in_addr ip;
+  char *ips;
+
+  if (gethostname(hostname, sizeof(hostname)))
+    return NULL;
+
+  dest = gethostbyname(hostname);
+  if (!dest)
+    return NULL;
+
+  memcpy(&ip.s_addr, dest->h_addr_list[0], 4);
+  ips = inet_ntoa(ip);
+
+  return strdup(ips);
+}