From: Christian Grothoff Date: Sun, 11 Mar 2012 22:51:28 +0000 (+0000) Subject: vminko: implementing BINDTO option for hostlist service (#2140) X-Git-Tag: initial-import-from-subversion-38251~14292 X-Git-Url: https://git.librecmc.org/?a=commitdiff_plain;h=0d7234799b96e9822330d70d3dd8ffea89eb0a75;p=oweals%2Fgnunet.git vminko: implementing BINDTO option for hostlist service (#2140) --- diff --git a/src/hostlist/hostlist-server.c b/src/hostlist/hostlist-server.c index a5cc4785a..e7bddbbf3 100644 --- a/src/hostlist/hostlist-server.c +++ b/src/hostlist/hostlist-server.c @@ -537,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) @@ -589,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 @@ -603,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 @@ -618,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)) { diff --git a/src/hostlist/hostlist.conf b/src/hostlist/hostlist.conf index b13e1e59e..2e0c85484 100644 --- a/src/hostlist/hostlist.conf +++ b/src/hostlist/hostlist.conf @@ -10,5 +10,6 @@ OPTIONS = -b SERVERS = http://v9.gnunet.org:58080/ http://ioerror.gnunet.org:65535/ # proxy for downloading hostlists HTTP-PROXY = - +# bind hostlist http server to a specific IPv4 or IPv6 +# BINDTOIP =