udpates.
[silc.git] / lib / silcutil / silcnet.c
index 1120529e33ddf0eb04764b4d14332e4be8a468d8..2cdac41ab2e0063f1b4bbb8827489d47cd3cc72a 100644 (file)
@@ -229,3 +229,25 @@ char *silc_net_localhost(void)
 
   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;
+
+  SILC_GET32_LSB(ip.s_addr, dest->h_addr_list[0]);
+  ips = inet_ntoa(ip);
+
+  return strdup(ips);
+}