summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--ip.pl25
1 files changed, 24 insertions, 1 deletions
diff --git a/ip.pl b/ip.pl
index ebac00f..c27d020 100644
--- a/ip.pl
+++ b/ip.pl
@@ -21,13 +21,28 @@ ip_format(ip4_range(ip4(A, B, C, D, _), Range), Str) :-
ip4_g(A, B, C, D) --> ip4_num(A), ".", ip4_num(B), ".", ip4_num(C), ".", ip4_num(D).
ip4_num(D) --> integer(D), { D >= 0, D =< 255 }.
-ipx(A) --> integer(A).
ip_parse(Str, Obj) :-
string_codes(Str, Codes),
phrase(ip4_g(A, B, C, D), Codes),
Obj = ip4(A, B, C, D).
+ip6_g(A, B, C, D, E, F, G, H) -->
+ ip6_num(A), ":",
+ ip6_num(B), ":",
+ ip6_num(C), ":",
+ ip6_num(D), ":",
+ ip6_num(E), ":",
+ ip6_num(F), ":",
+ ip6_num(G), ":",
+ ip6_num(H).
+ip6_num(D) --> xinteger(D), { D >= 0, D =< 65535 }.
+
+ip6_parse(Str, Obj) :-
+ string_codes(Str, Codes),
+ phrase(ip6_g(A, B, C, D, E, F, G, H), Codes),
+ Obj = ip6(A, B, C, D, E, F, G, H).
+
:- begin_tests(lists).
:- use_module(library(lists)).
@@ -48,4 +63,12 @@ test(ip_parse) :-
ip_parse("1.2.3.4", Ip),
assertion(Ip == ip4(1, 2, 3, 4)).
+test(ip6_parse) :-
+ ip6_parse("1:2:3:4:5:6:a:b", Ip),
+ assertion(Ip == ip6(1, 2, 3, 4, 5, 6, 10, 11)).
+
+test(ip6_parse) :-
+ ip6_parse("0:2:3:4:5:6:a:b", Ip),
+ assertion(Ip == ip6(0, 2, 3, 4, 5, 6, 10, 11)).
+
:- end_tests(lists).