packages feed

ip6addr 0.1 → 0.1.1

raw patch · 7 files changed

+87/−20 lines, 7 files

Files

+ ChangeLog view
@@ -0,0 +1,9 @@+2009-06-26	Michel Boucey <michel.boucey@gmail.com>++	- Version 0.1 released.++2009-09-11	Michel Boucey <michel.boucey@gmail.com>++	- Version 0.1.1 released.+	- Fixed three bugs in IPv6 address validation.+	- Added a test written in Perl.
IsIPv6Addr.hs view
@@ -43,7 +43,7 @@ isIPv4Token s
               | s == "." = 'd'
               | is8bitsToken s == True = '8'
-              | otherwise = 'u'
+              | otherwise = '?'
 
 internalIPv4Rep :: [String] -> String
 internalIPv4Rep = map isIPv4Token
@@ -59,7 +59,7 @@                    | f == 0 = 0
                    | f == 1 = 1
                    | otherwise = -1
-                   where f = length $ filter(=='4') s
+                   where f = length $ filter (=='4') s
 
 isIPv4Addr :: String -> Bool
 isIPv4Addr = parseIPv4Tokens . internalIPv4Rep . tokenizeIPv4AddrInput
@@ -78,13 +78,13 @@                | s == "::" = 'd'
                | is16bitsToken s == True = '6'
                | isIPv4Addr s == True = '4'
-               | otherwise = 'u'
+               | otherwise = '?'
                
 internalIPv6Rep :: [String] -> String
 internalIPv6Rep = map ipv6AddrToken
 
 parseInternalRep :: String -> Bool
-parseInternalRep s = 'u' `notElem` s
+parseInternalRep s = '?' `notElem` s
 
 isCompressed :: String -> Int
 isCompressed s
@@ -94,19 +94,19 @@               where c = length $ filter (=='d') s
 
 lengthConstraints :: String -> Bool
-lengthConstraints s = (l == 15 && c <= 0) || (l < 15 && c == 1)
-                      where l = length s
-                            c = isCompressed s
+lengthConstraints s = case embeddedIPv4Addr s of
+			0 -> (e == '6' || e == 'd') && ((l == 15 && c <= 0) || (l < 15 && c == 1))
+			1 -> (e == '4' && l == 13 && c <= 0) || (e == '4' && l < 13 && c == 1)
+                        -1 -> False
+			where l = length s
+			      c = isCompressed s
+			      e = last s
 
-validLastToken :: String -> Bool
-validLastToken s = case embeddedIPv4Addr s of
-                           0 -> t == '6' || t == 'd'
-                           1 -> t == '4'
-                           -1 -> False
-                           where t = last s
+validFirstToken :: String -> Bool
+validFirstToken s = h == '6' || h == 'd' where h = head s 
 
 testsIPv6Addr :: String -> Bool
-testsIPv6Addr s = lengthConstraints s && parseInternalRep s && validLastToken s
+testsIPv6Addr s = lengthConstraints s && parseInternalRep s && validFirstToken s
    
 isIPv6Addr :: String -> Bool
-isIPv6Addr = testsIPv6Addr . internalIPv6Rep . tokenizeIPv6Input            +isIPv6Addr = testsIPv6Addr . internalIPv6Rep . tokenizeIPv6Input            
Main.hs view
@@ -65,7 +65,7 @@                        then hPutStrLn stdout a >> evalInputsErr as
                        else hPutStrLn stderr a >> evalInputsErr as
 
-version = "ip6addr 0.1"
+version = "ip6addr Version 0.1.1"
 help   = "Usage: ip6addr [-v|-h] | [-e] [address ...]\n"
 exit    = exitWith ExitSuccess
 
Makefile view
@@ -11,8 +11,10 @@ build: clean configure 	$(RHS) build ++.PHONY: test+test:+	./test/test.pl+ install: clean configure build 	$(RHS) install--sdist:-	$(RHS) sdist
ip6addr.cabal view
@@ -1,5 +1,5 @@ Name:		ip6addr
-Version:	0.1
+Version:	0.1.1
 Author:         Michel Boucey <michel.boucey@gmail.com>
 Maintainer:     Michel Boucey <michel.boucey@gmail.com>
 Homepage:       http://www.cybervisible.fr/ip6addr
+ test/inputs view
@@ -0,0 +1,26 @@+:::!0+::4AF:!0+:!0+::!1+0:0:0:0:0:0:0:0!1+0:0:0:0:0:0:0:0:0!0+::1!1+0:0:0:0:0:0:0:1!1+ABCD:EF01:2345:6789:ABCD:EF01:2345:6789!1+0:ABCD:EF01:2345:6789:ABCD:EF01:2345:6789!0+ABCD:EF01:123.67.3.45:6789:ABCD:EF01:2345:78.123.23.79!0+ABCD:EF01:2345:6789:ABTD:EF01:2345:6789!0+ABCD::2345:6789:ABTD::2345:6789!0+:EF01:2345:6789:ABCD:EF01:2345:6789!0+2001:DB8:0:0:8:800:200C:417A!1+2001:DB8:0:0:8:8004:200CD:417A!0+FF01:0:0:0:0:0:0:101!1+FF01::101!1+0:0:0:0:0:0:13.1.68.3!1+::13.1.68.3!1+0:0:0:0:0:FFFF:129.144.52.38!1+0:0:0:0:0:FFFF:0:129.144.52.38!0+0:0:0:0:0:129.144.52.38:0!0+::FFFF:129.144.52.38!1+::FFFF:129.144.52.38:ADEF!0+129.144.52.38:ADEF!0
+ test/test.pl view
@@ -0,0 +1,30 @@+#!/usr/bin/perl -w++use Cwd 'abs_path';+use File::Basename;++chdir(dirname(abs_path($0)));+$ip6addr = "../dist/build/ip6addr/ip6addr";++if (-e $ip6addr) {+	@testList = `cat ./inputs`;+	$fcpt = 0;+	print "\n";+	foreach (@testList) {+		@test = split(/!/);+		$result = `$ip6addr $test[0]`;+		chomp($result);+		if ($test[1] == "0") {print "Bad";} else {print "Good";}	+		print " input \"$test[0]\" - ";+		if (($result eq "" && $test[1] == "0")||($result eq $test[0] && $test[1] == "1")) {+			print "PASSED\n";+		} else {+			print "FAILED !\n";+			$fcpt++;+		} +		$cpt++;+	}+	print "\nTests: $cpt\nFailed tests: $fcpt\n\n";+} else {+	print "Run  a 'make build' before testing...\n"+}