changeset 2583:26a6da30d5f1 libavformat

Add IPv6 support to url_split() patch by: Ronald S. Bultje rsbultje a gmail d com thread: "[PATCH] url_split() ipv6 support" at 2007/Sep/23 18:43
author andoma
date Sat, 29 Sep 2007 14:35:52 +0000
parents 1f9d02d072a7
children 4630871ef965
files utils.c
diffstat 1 files changed, 14 insertions(+), 8 deletions(-) [+]
line wrap: on
line diff
--- a/utils.c	Fri Sep 28 15:12:26 2007 +0000
+++ b/utils.c	Sat Sep 29 14:35:52 2007 +0000
@@ -2878,7 +2878,7 @@
                char *path, int path_size,
                const char *url)
 {
-    const char *p, *ls, *at, *col;
+    const char *p, *ls, *at, *col, *brk;
 
     if (port_ptr)               *port_ptr = -1;
     if (proto_size > 0)         proto[0] = 0;
@@ -2913,13 +2913,19 @@
             p = at + 1; /* skip '@' */
         }
 
-        /* port */
-        if ((col = strchr(p, ':')) && col < ls) {
-            ls = col;
-            if (port_ptr) *port_ptr = atoi(col + 1); /* skip ':' */
-        }
-
-        av_strlcpy(hostname, p, FFMIN(1 + ls - p, hostname_size));
+        if (*p == '[' && (brk = strchr(p, ']')) && brk < ls) {
+            /* [host]:port */
+            av_strlcpy(hostname, p + 1,
+                       FFMIN(hostname_size, brk - p));
+            if (brk[1] == ':' && port_ptr)
+                *port_ptr = atoi(brk + 2);
+        } else if ((col = strchr(p, ':')) && col < ls) {
+            av_strlcpy(hostname, p,
+                       FFMIN(col + 1 - p, hostname_size));
+            if (port_ptr) *port_ptr = atoi(col + 1);
+        } else
+            av_strlcpy(hostname, p,
+                       FFMIN(ls + 1 - p, hostname_size));
     }
 }