[gupnp-tools] network-light: Enable ipv6



commit 21a2744c50b0a780c182c3c65393c2f2d5c6fee6
Author: Jens Georg <mail jensge org>
Date:   Mon May 10 12:16:59 2021 +0200

    network-light: Enable ipv6

 src/network-light/main.c | 10 +++++++++-
 src/network-light/upnp.c | 19 +++++++++++++++++--
 src/network-light/upnp.h |  2 +-
 3 files changed, 27 insertions(+), 4 deletions(-)
---
diff --git a/src/network-light/main.c b/src/network-light/main.c
index 7cb1eb0..1f604bb 100644
--- a/src/network-light/main.c
+++ b/src/network-light/main.c
@@ -42,15 +42,23 @@ static int      upnp_port = 0;
 static char   **interfaces = NULL;
 static char    *name = NULL;
 static gboolean exclusive;
+static gboolean ipv4 = TRUE;
+static gboolean ipv6 = TRUE;
 
+// clang-format off
 static GOptionEntry entries[] =
 {
         { "port", 'p', 0, G_OPTION_ARG_INT, &upnp_port, N_("Network PORT to use for UPnP"), "PORT" },
         { "interface", 'i', 0, G_OPTION_ARG_STRING_ARRAY, &interfaces, N_("Network interfaces to use for 
UPnP communication"), "INTERFACE" },
         { "name", 'n', 0, G_OPTION_ARG_STRING, &name, N_("Friendly name for this UPnP light"), "NAME" },
         { "exclusive", 'x', 0, G_OPTION_ARG_NONE, &exclusive, N_("Apply change exclusively to this UPnP 
light"), NULL },
+        { "v4", '4', 0, G_OPTION_ARG_NONE, &ipv4, N_("Use IPv4"), NULL },
+        { "v6", '6', 0, G_OPTION_ARG_NONE, &ipv6, N_("Use IPv6"), NULL },
+        { "no-v4",  0, G_OPTION_FLAG_REVERSE, G_OPTION_ARG_NONE, &ipv4, N_("No not use IPv4"), NULL },
+        { "no-v6", 0, G_OPTION_FLAG_REVERSE, G_OPTION_ARG_NONE, &ipv6, N_("Do not use IPv6"), NULL },
         { NULL }
 };
+// clang-format on
 
 void
 set_status (gboolean status)
@@ -119,7 +127,7 @@ main (int argc, char **argv)
                 return -1;
         }
 
-        if (!init_upnp (interfaces, upnp_port, name)) {
+        if (!init_upnp (interfaces, upnp_port, name, ipv4, ipv6)) {
                 return -2;
         }
 
diff --git a/src/network-light/upnp.c b/src/network-light/upnp.c
index 193eba5..1536d6c 100644
--- a/src/network-light/upnp.c
+++ b/src/network-light/upnp.c
@@ -767,7 +767,7 @@ context_equal (GUPnPContext *context1, GUPnPContext *context2)
 }
 
 gboolean
-init_upnp (gchar **interfaces, guint port, gchar *name)
+init_upnp (gchar **interfaces, guint port, gchar *name, gboolean ipv4, gboolean ipv6)
 {
         GUPnPWhiteList *white_list;
 
@@ -783,7 +783,22 @@ init_upnp (gchar **interfaces, guint port, gchar *name)
                 return FALSE;
         }
 
-        context_manager = gupnp_context_manager_create (port);
+        // Default: Both
+        GSocketFamily family = G_SOCKET_FAMILY_INVALID;
+        if (!ipv4 && ipv6) {
+            g_debug ("Option a");
+            family = G_SOCKET_FAMILY_IPV6;
+        } else if (ipv4 && !ipv6) {
+            g_debug ("Option b");
+            family = G_SOCKET_FAMILY_IPV4;
+        } else {
+            g_debug ("Option c");
+            // Neither? Just do nothing and enable both
+        }
+
+        context_manager = gupnp_context_manager_create_full (GSSDP_UDA_VERSION_1_0,
+                                                             family,
+                                                             port);
         g_assert (context_manager != NULL);
 
         if (interfaces != NULL) {
diff --git a/src/network-light/upnp.h b/src/network-light/upnp.h
index 4b4100a..097ab3f 100644
--- a/src/network-light/upnp.h
+++ b/src/network-light/upnp.h
@@ -30,7 +30,7 @@ void
 notify_load_level_change        (gint           load_level);
 
 gboolean
-init_upnp                       (gchar **interfaces, guint port, gchar *name);
+init_upnp                       (gchar **interfaces, guint port, gchar *name, gboolean ipv4, gboolean ipv6);
 
 void
 deinit_upnp                     (void);


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