changeset 1516:a40980e3eec7

cookies fix ipv6 check
author corvid <corvid@lavabit.com>
date Wed, 13 Jan 2010 20:28:16 +0000
parents a7ee9f9a8283
children 773b44547931
files dpi/cookies.c
diffstat 1 files changed, 13 insertions(+), 11 deletions(-) [+]
line wrap: on
line diff
--- a/dpi/cookies.c	Wed Jan 13 11:49:21 2010 +0100
+++ b/dpi/cookies.c	Wed Jan 13 20:28:16 2010 +0000
@@ -926,22 +926,24 @@
  */
 static bool_t Cookies_domain_is_ip(const char *domain)
 {
-   bool_t ipv4 = TRUE, ipv6 = TRUE;
+   uint_t len;
 
    if (!domain)
       return FALSE;
 
-   while (*domain) {
-      if (*domain != '.' && !isdigit(*domain))
-         ipv4 = FALSE;
-      if (*domain != ':' && !isxdigit(*domain))
-         ipv6 = FALSE;
-      if (!(ipv4 || ipv6))
-         return FALSE;
-      domain++;
+   len = strlen(domain);
+
+   if (len == strspn(domain, "0123456789.")) {
+      MSG("an IPv4 address\n");
+      return TRUE;
    }
-   MSG("an IP address\n");
-   return TRUE;
+   if (*domain == '[' &&
+       (len == strspn(domain, "0123456789abcdefABCDEF:.[]"))) {
+      /* The precise format is shown in section 3.2.2 of rfc 3986 */
+      MSG("an IPv6 address\n");
+      return TRUE;
+   }
+   return FALSE;
 }
 
 /*