]> git.ipfire.org Git - thirdparty/ntp.git/commitdiff
ntp_scanner.c:
authorRob Neal <neal@ntp.org>
Mon, 29 Oct 2007 14:28:31 +0000 (10:28 -0400)
committerRob Neal <neal@ntp.org>
Mon, 29 Oct 2007 14:28:31 +0000 (10:28 -0400)
  [Bug 828] correct IPv6 address parsing

bk: 4725ee0f4kBfwki7MUmag8GD944Dxw

ntpd/ntp_scanner.c

index 82d34fc50080ebd149fdbafb2bc59d49ad05b9f2..f3e3446632e834674ad4756a65aeb8abd92ed1ff 100644 (file)
@@ -420,47 +420,6 @@ static int is_ipv4_address(char *lexeme)
         return 0;
 }
 
-/* IPv6 Address 
- * See RFC 3513, Section 2.2 for details
- * Note: full error checking is not being done
- */
-static int is_ipv6_address(char *lexeme)
-{
-    int i;
-    int quad_no = 1;
-    int digits_read = 0;
-    int group_seen = 0;  
-    
-    for (i = 0;lexeme[i];++i) {
-        if (isxdigit(lexeme[i]))
-            ++digits_read;
-        else if (lexeme[i] == ':') {
-            ++quad_no;            
-            if (digits_read == 0 && !group_seen)
-                group_seen = 1;
-            else if (digits_read > 4 ||
-                     (digits_read == 0 && group_seen))
-                return 0;
-            digits_read = 0;
-        }
-        else if (lexeme[i] == '.') {
-            /* A IPv4 address has been mixed with an IPv6 Address
-             * Ensure that less than 6 quads have been read and that
-             * the IPv4 address is valid 
-             */
-            while (i >= 0 && lexeme[i-1] != ':')
-                --i;
-            return ((quad_no <= 6) && is_ipv4_address(&lexeme[i]));
-        }
-        else
-            return 0;
-    }
-    /* Make sure that we don't end with a single ':' */
-    if (lexeme[i-1] == ':' && lexeme[i-2] != ':')
-        return 0;
-    
-    return ((quad_no <= 7 && digits_read <= 4) ? 1 : 0);
-}
 
 
 /* Host Name */
@@ -510,6 +469,7 @@ int yylex()
     int i, instring = 0;
     int token;                 /* The return value/the recognized token */
     int ch;
+       struct in_addr temp_inaddr;
     static int expect_string = NO_ARG;
 
     do {
@@ -626,7 +586,7 @@ int yylex()
         else
             return T_IPv4_address;
     }
-    else if (is_ipv6_address(yytext) && (!instring)) {
+    else if ((inet_pton(AF_INET6, yytext, &temp_inaddr) == 1) && (!instring)) {
         if (expect_string == SINGLE_ARG)
             expect_string = NO_ARG;
         errno = 0;