about summary refs log tree commit diff stats
path: root/src/xmpp/connection.c
diff options
context:
space:
mode:
authorSteffen Jaeckel <jaeckel-floss@eyet-services.de>2022-02-01 16:56:26 +0100
committerSteffen Jaeckel <jaeckel-floss@eyet-services.de>2022-02-01 16:56:26 +0100
commitad87bdffc286aa4a32b350869c2e70af9630c0a2 (patch)
tree6ed3e152a3891b9d570a0569ab89a013332438fa /src/xmpp/connection.c
parent9a1311a82660fc0ce2bacc64d5324b90b3345476 (diff)
downloadprofani-tty-ad87bdffc286aa4a32b350869c2e70af9630c0a2.tar.gz
add missing IPv6 handling
Signed-off-by: Steffen Jaeckel <jaeckel-floss@eyet-services.de>
Diffstat (limited to 'src/xmpp/connection.c')
-rw-r--r--src/xmpp/connection.c27
1 files changed, 22 insertions, 5 deletions
diff --git a/src/xmpp/connection.c b/src/xmpp/connection.c
index c04f9df2..3b389814 100644
--- a/src/xmpp/connection.c
+++ b/src/xmpp/connection.c
@@ -929,14 +929,31 @@ _split_url(const char* alturi, gchar** host, gint* port)
     ptrdiff_t hostlen;
     /* search ':' from start and end
      * if `first` matches `last` it's a `hostname:port` combination
-     * if `first` is different than `last` it's `[ip:v6]:port`
+     * if `first` is different than `last` it's `[ip:v6]` or `[ip:v6]:port`
      */
     char* first = strchr(alturi, ':');
     char* last = strrchr(alturi, ':');
-    if (first && first == last) {
-        hostlen = last - alturi;
-        if (!strtoi_range(last + 1, port, 1, 65535, NULL))
-            return FALSE;
+    if (first) {
+        if (first == last) {
+            hostlen = last - alturi;
+            if (!strtoi_range(last + 1, port, 1, 65535, NULL))
+                return FALSE;
+        } else {
+            /* IPv6 handling */
+            char* bracket = strrchr(alturi, ']');
+            if (!bracket)
+                return FALSE;
+            if (bracket > last) {
+                /* `[ip:v6]` */
+                hostlen = strlen(alturi) + 1;
+                *port = 0;
+            } else {
+                /* `[ip:v6]:port` */
+                hostlen = last - alturi;
+                if (!strtoi_range(last + 1, port, 1, 65535, NULL))
+                    return FALSE;
+            }
+        }
     } else {
         hostlen = strlen(alturi) + 1;
         *port = 0;