gnunet-svn
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[GNUnet-SVN] [gnunet] 01/02: bind to config option (default localhost)


From: gnunet
Subject: [GNUnet-SVN] [gnunet] 01/02: bind to config option (default localhost)
Date: Sat, 09 Mar 2019 16:00:33 +0100

This is an automated email from the git hooks/post-receive script.

martin-schanzenbach pushed a commit to branch master
in repository gnunet.

commit fed55fd466b43dc0175a12a1a475e43747da137a
Author: Schanzenbach, Martin <address@hidden>
AuthorDate: Sat Mar 9 15:58:45 2019 +0100

    bind to config option (default localhost)
---
 src/rest/gnunet-rest-server.c | 59 +++++++++++++++++++++++++++++++++++++++++++
 src/rest/rest.conf            |  2 ++
 2 files changed, 61 insertions(+)

diff --git a/src/rest/gnunet-rest-server.c b/src/rest/gnunet-rest-server.c
index 77f3d898d..f9e954912 100644
--- a/src/rest/gnunet-rest-server.c
+++ b/src/rest/gnunet-rest-server.c
@@ -63,6 +63,16 @@
  */
 static struct GNUNET_SCHEDULER_Task *httpd_task;
 
+/**
+ * The address to bind to
+ */
+static in_addr_t address;
+
+/**
+ * The IPv6 address to bind to
+ */
+static struct in6_addr address6;
+
 /**
  * The port the service is running on (default 7776)
  */
@@ -695,6 +705,7 @@ bind_v4 ()
   memset (&sa4, 0, sizeof (sa4));
   sa4.sin_family = AF_INET;
   sa4.sin_port = htons (port);
+  sa4.sin_addr.s_addr = address;
 #if HAVE_SOCKADDR_IN_SIN_LEN
   sa4.sin_len = sizeof (sa4);
 #endif
@@ -731,6 +742,7 @@ bind_v6 ()
   memset (&sa6, 0, sizeof (sa6));
   sa6.sin6_family = AF_INET6;
   sa6.sin6_port = htons (port);
+  sa6.sin6_addr = address6;
 #if HAVE_SOCKADDR_IN_SIN_LEN
   sa6.sin6_len = sizeof (sa6);
 #endif
@@ -806,9 +818,56 @@ run (void *cls,
      const char *cfgfile,
      const struct GNUNET_CONFIGURATION_Handle *c)
 {
+  char* addr_str;
   cfg = c;
   plugin_map = GNUNET_CONTAINER_multihashmap_create (10, GNUNET_NO);
 
+  /* Get address to bind to */
+  if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_string (cfg, "rest",
+                                                          "BIND_TO",
+                                                          &addr_str))
+  {
+    //No address specified
+    GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+                "Don't know what to bind to...\n");
+    GNUNET_free (addr_str);
+    GNUNET_SCHEDULER_shutdown ();
+    return;
+  }
+  if (1 != inet_pton (AF_INET, addr_str, &address))
+  {
+    GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+                "Unable to parse address %s\n",
+                addr_str);
+    GNUNET_free (addr_str);
+    GNUNET_SCHEDULER_shutdown ();
+    return;
+  }
+  GNUNET_free (addr_str);
+  /* Get address to bind to */
+  if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_string (cfg, "rest",
+                                                          "BIND_TO6",
+                                                          &addr_str))
+  {
+    //No address specified
+    GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+                "Don't know what to bind6 to...\n");
+    GNUNET_free (addr_str);
+    GNUNET_SCHEDULER_shutdown ();
+    return;
+  }
+  if (1 != inet_pton (AF_INET6, addr_str, &address6))
+  {
+    GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+                "Unable to parse IPv6 address %s\n",
+                addr_str);
+    GNUNET_free (addr_str);
+    GNUNET_SCHEDULER_shutdown ();
+    return;
+  }
+  GNUNET_free (addr_str);
+
+
   /* Get CORS data from cfg */
   if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_string (cfg, "rest",
                                                           "REST_ALLOW_ORIGIN",
diff --git a/src/rest/rest.conf b/src/rest/rest.conf
index 138751696..bef8cf473 100644
--- a/src/rest/rest.conf
+++ b/src/rest/rest.conf
@@ -1,6 +1,8 @@
 [rest]
 UNIXPATH = $GNUNET_USER_RUNTIME_DIR/gnunet-service-rest.sock
 BINARY=gnunet-rest-server
+BIND_TO=127.0.0.1
+BIND_TO6=::1
 REST_PORT=7776
 REST_ALLOW_HEADERS=Authorization,Accept,Content-Type
 REST_ALLOW_ORIGIN=*

-- 
To stop receiving notification emails like this one, please contact
address@hidden



reply via email to

[Prev in Thread] Current Thread [Next in Thread]