- fix
[oweals/gnunet.git] / src / hostlist / hostlist-server.c
index 69d83b4d487a20a15b0101d64172bc0298c6136d..e7bddbbf3c24f3bc839bee6ecb3464a75c899280 100644 (file)
@@ -141,16 +141,13 @@ finish_response (struct HostSet *results)
  * Set 'cls' to GNUNET_YES (we have an address!).
  *
  * @param cls closure, an 'int*'
- * @param tname name of the transport (ignored)
+ * @param address the address (ignored)
  * @param expiration expiration time (call is ignored if this is in the past)
- * @param addr the address (ignored)
- * @param addrlen length of the address (ignored)
  * @return  GNUNET_SYSERR to stop iterating (unless expiration has occured)
  */
 static int
-check_has_addr (void *cls, const char *tname,
-                struct GNUNET_TIME_Absolute expiration, const void *addr,
-                uint16_t addrlen)
+check_has_addr (void *cls, const struct GNUNET_HELLO_Address *address,
+                struct GNUNET_TIME_Absolute expiration)
 {
   int *arg = cls;
 
@@ -493,7 +490,7 @@ prepare_daemon (struct MHD_Daemon *daemon_handle)
   struct GNUNET_NETWORK_FDSet *wws;
   struct GNUNET_NETWORK_FDSet *wes;
   int max;
-  unsigned long long timeout;
+  unsigned MHD_LONG_LONG timeout;
   int haveto;
   struct GNUNET_TIME_Relative tv;
 
@@ -540,7 +537,13 @@ GNUNET_HOSTLIST_server_start (const struct GNUNET_CONFIGURATION_Handle *c,
 {
   unsigned long long port;
   char *hostname;
+  char *ip;
   size_t size;
+  struct in_addr i4;
+  struct in6_addr i6;
+  struct sockaddr_in v4;
+  struct sockaddr_in6 v6;
+  const struct sockaddr *sa;
 
   advertising = advertise;
   if (!advertising)
@@ -592,6 +595,50 @@ GNUNET_HOSTLIST_server_start (const struct GNUNET_CONFIGURATION_Handle *c,
     }
     GNUNET_free (hostname);
   }
+
+  if (GNUNET_CONFIGURATION_have_value (cfg, "HOSTLIST", "BINDTOIP"))
+  {
+    GNUNET_break (GNUNET_OK ==
+                  GNUNET_CONFIGURATION_get_value_string (cfg, "HOSTLIST",
+                                                         "BINDTOIP", &ip));
+  }
+  else 
+    ip = NULL;
+  if (ip != NULL)
+  {
+    if (1 == inet_pton (AF_INET, ip, &i4))
+    {
+      memset (&v4, 0, sizeof (v4));
+      v4.sin_family = AF_INET;
+      v4.sin_addr = i4;
+      v4.sin_port = htons (port);
+#if HAVE_SOCKADDR_IN_SIN_LEN
+      v4.sin_len = sizeof (v4);
+#endif
+      sa = (const struct sockaddr *) &v4;
+    }
+    else if (1 == inet_pton (AF_INET6, ip, &i6))
+    {
+      memset (&v6, 0, sizeof (v6));
+      v6.sin6_family = AF_INET6;
+      v6.sin6_addr = i6;
+      v6.sin6_port = htons (port);
+#if HAVE_SOCKADDR_IN_SIN_LEN
+      v6.sin6_len = sizeof (v6);
+#endif
+      sa = (const struct sockaddr *) &v6;
+    }
+    else
+    {
+      GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
+                  _("`%s' is not a valid IP address! Ignoring BINDTOIP.\n"),
+                  ip);
+      sa = NULL;
+    }
+  }
+  else
+    sa = NULL;
+
   daemon_handle_v6 = MHD_start_daemon (MHD_USE_IPv6
 #if DEBUG_HOSTLIST_SERVER
                                        | MHD_USE_DEBUG
@@ -606,7 +653,10 @@ GNUNET_HOSTLIST_server_start (const struct GNUNET_CONFIGURATION_Handle *c,
                                        MHD_OPTION_CONNECTION_TIMEOUT,
                                        (unsigned int) 16,
                                        MHD_OPTION_CONNECTION_MEMORY_LIMIT,
-                                       (size_t) (16 * 1024), MHD_OPTION_END);
+                                       (size_t) (16 * 1024),
+                                       MHD_OPTION_SOCK_ADDR,
+                                       sa,
+                                       MHD_OPTION_END);
   daemon_handle_v4 = MHD_start_daemon (MHD_NO_FLAG
 #if DEBUG_HOSTLIST_SERVER
                                        | MHD_USE_DEBUG
@@ -621,7 +671,10 @@ GNUNET_HOSTLIST_server_start (const struct GNUNET_CONFIGURATION_Handle *c,
                                        MHD_OPTION_CONNECTION_TIMEOUT,
                                        (unsigned int) 16,
                                        MHD_OPTION_CONNECTION_MEMORY_LIMIT,
-                                       (size_t) (16 * 1024), MHD_OPTION_END);
+                                       (size_t) (16 * 1024),
+                                       MHD_OPTION_SOCK_ADDR,
+                                       sa,
+                                       MHD_OPTION_END);
 
   if ((daemon_handle_v6 == NULL) && (daemon_handle_v4 == NULL))
   {