summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorMukund Sivaraman <muks@banu.com>2011-02-04 20:28:48 +0530
committerMukund Sivaraman <muks@banu.com>2011-02-04 20:28:48 +0530
commit2d02e2211e1493b2652b44329bd0b29bac71c1b7 (patch)
tree324269df85add3a69d8ebcc104f99c7d896dff68
parent8fd3808ad315fcdf84648a2378324cfab21df0c1 (diff)
Handle IPv6 literals in URLs correctly
-rw-r--r--src/reqs.c15
1 files changed, 14 insertions, 1 deletions
diff --git a/src/reqs.c b/src/reqs.c
index ead54ff..569f916 100644
--- a/src/reqs.c
+++ b/src/reqs.c
@@ -167,12 +167,18 @@ static void strip_username_password (char *host)
static int strip_return_port (char *host)
{
char *ptr1;
+ char *ptr2;
int port;
- ptr1 = strchr (host, ':');
+ ptr1 = strrchr (host, ':');
if (ptr1 == NULL)
return 0;
+ /* Check for IPv6 style literals */
+ ptr2 = strchr (ptr1, ']');
+ if (ptr2 != NULL)
+ return 0;
+
*ptr1++ = '\0';
if (sscanf (ptr1, "%d", &port) != 1) /* one conversion required */
return 0;
@@ -212,6 +218,13 @@ static int extract_http_url (const char *url, struct request_s *request)
port = strip_return_port (request->host);
request->port = (port != 0) ? port : HTTP_PORT;
+ /* Remove any surrounding '[' and ']' from IPv6 literals */
+ p = strrchr (request->host, ']');
+ if (p && (*(request->host) == '[')) {
+ request->host++;
+ *p = '\0';
+ }
+
return 0;
ERROR_EXIT: