[X2Go-Commits] [libx2goclient] 04/06: src/x2goclient-network-ssh.c: implement IPv4 address parsing.

git-admin at x2go.org git-admin at x2go.org
Mon Jul 29 12:13:25 CEST 2019


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

x2go pushed a commit to branch master
in repository libx2goclient.

commit 195a3d563571fef3b3b4d1e1b4a9e4be12f4b91b
Author: Mihai Moldovan <ionic at ionic.de>
Date:   Mon Jul 29 11:20:55 2019 +0200

    src/x2goclient-network-ssh.c: implement IPv4 address parsing.
---
 src/x2goclient-network-ssh.c | 64 +++++++++++++++++++++++++++++++++++---------
 1 file changed, 52 insertions(+), 12 deletions(-)

diff --git a/src/x2goclient-network-ssh.c b/src/x2goclient-network-ssh.c
index 00a0aac..0a17168 100644
--- a/src/x2goclient-network-ssh.c
+++ b/src/x2goclient-network-ssh.c
@@ -209,16 +209,43 @@ static GSocketAddress* x2goclient_network_ssh_parse_sockspec_ip (const GString *
 
     /* FIXME: parse out scope ID! */
   }
+  else {
+    /*
+     * For IPv4 addresses, we'll accept any input of the form address:port.
+     *
+     * Note that "address" may not necessarily be in dotted-quad format.
+     */
+    tmp_end = g_strstr_len (tmp_start, -1, ":");
+
+    if (tmp_end) {
+      --tmp_end;
+
+      address = g_string_new_len (tmp_start, tmp_end - tmp_start);
+    }
+    else {
+      address = g_string_new_len (tmp_start, work_sockspec->len);
+    }
+  }
 
   if (!err) {
+    gboolean is_v6 = FALSE,
+             is_v4 = FALSE;
+    char binary_rep[128] = { 0 };
     if (want_v6) {
       /* Check for an IPv6 address. */
-      char binary_rep[128] = { 0 };
-      gboolean is_v6 = (1 == inet_pton (AF_INET6, address->str, &binary_rep));
+      is_v6 = (1 == inet_pton (AF_INET6, address->str, &binary_rep));
+    }
+    else {
+      /* Check for an IPv4 address. */
+      is_v4 = (1 == inet_pton (AF_INET, address->str, &binary_rep));
+    }
 
-      if (is_v6) {
-        /* Passed a valid IPv6 address. */
-        if (tmp_end) {
+    if (((is_v6) && (want_v6)) || ((is_v4) && (!(want_v6)))) {
+      /* Passed a valid IPv4 or IPv6 address. */
+      if (tmp_end) {
+        GString *portspec = NULL;
+
+        if (want_v6) {
           /*
            * Specification in brackets, so check if there's a port specifier.
            *
@@ -227,16 +254,29 @@ static GSocketAddress* x2goclient_network_ssh_parse_sockspec_ip (const GString *
            * worst case, point to the terminating NULL character, which is
            * fine.
            */
-          GString *portspec = g_string_new (tmp_end + 2);
-          GError *tmp_err = NULL;
-          port = x2goclient_network_ssh_parse_sockspec_port (portspec, &tmp_err);
-          g_string_free (portspec, TRUE);
-          portspec = NULL;
+          portspec = g_string_new (tmp_end + 2);
+        }
+        else {
+          /*
+           * IPv4 addresses are not encapsulated in brackets, so the offset is
+           * lower by one.
+           */
+          portspec = g_string_new (tmp_end + 1);
+        }
 
-          if (tmp_err) {
+        GError *tmp_err = NULL;
+        port = x2goclient_network_ssh_parse_sockspec_port (portspec, &tmp_err);
+        g_string_free (portspec, TRUE);
+        portspec = NULL;
+
+        if (tmp_err) {
+          if (want_v6) {
             g_set_error (err, X2GOCLIENT_NETWORK_SSH_ERROR, X2GOCLIENT_NETWORK_SSH_ERROR_IPV6_CONV, "Unable to parse IPv6 address: %s", tmp_err->message);
-            g_clear_error (&tmp_err);
           }
+          else {
+            g_set_error (err, X2GOCLIENT_NETWORK_SSH_ERROR, X2GOCLIENT_NETWORK_SSH_ERROR_IPV4_CONV, "Unable to parse IPv4 address: %s", tmp_err->message);
+          }
+          g_clear_error (&tmp_err);
         }
       }
     }

--
Alioth's /home/x2go-admin/maintenancescripts/git/hooks/post-receive-email on /srv/git/code.x2go.org/libx2goclient.git


More information about the x2go-commits mailing list