[Spice-devel] [PATCH] proxy: support ipv6 addresses in brackets

Wolfgang Bumiller w.bumiller at proxmox.com
Mon Oct 5 05:38:51 PDT 2015


Signed-off-by: Wolfgang Bumiller <w.bumiller at proxmox.com>
---
 src/spice-uri.c | 19 ++++++++++++++++---
 1 file changed, 16 insertions(+), 3 deletions(-)

diff --git a/src/spice-uri.c b/src/spice-uri.c
index 82aefdb..2415857 100644
--- a/src/spice-uri.c
+++ b/src/spice-uri.c
@@ -114,11 +114,24 @@ gboolean spice_uri_parse(SpiceURI *self, const gchar *_uri, GError **error)
         uri = next;
     }
 
-    /* max 2 parts, host:port */
-    gchar **uriv = g_strsplit(uri, ":", 2);
+    /* ipv6 support */
+    gchar **uriv = NULL;
     const gchar *uri_port = NULL;
+    if (uri[0] == '[') {
+        gchar *end = strstr(uri+1, "]");
+        if (end) {
+            *end = 0;
+            uriv = g_malloc(sizeof(gchar*)*3);
+            uriv[0] = g_strdup(uri+1);
+            uriv[1] = (end[1] == ':') ? g_strdup(end+2) : NULL;
+            uriv[2] = NULL;
+        }
+    } else {
+        /* max 2 parts, host:port */
+        uriv = g_strsplit(uri, ":", 2);
+    }
 
-    if (uriv[0] == NULL || strlen(uriv[0]) == 0) {
+    if (!uriv || uriv[0] == NULL || strlen(uriv[0]) == 0) {
         g_set_error(error, SPICE_CLIENT_ERROR, SPICE_CLIENT_ERROR_FAILED,
                     "Invalid hostname in uri address");
         goto end;
-- 
2.1.4




More information about the Spice-devel mailing list