summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTrygve Laugstøl <trygvis@inamo.no>2023-11-17 15:14:37 +0100
committerTrygve Laugstøl <trygvis@inamo.no>2023-11-17 15:14:37 +0100
commitd6fea03e6576f6ddc48d6562abd84ba26d146f81 (patch)
tree9d433cb14a1186da8629b3bb9eae0945b13690d6
parent457c908f9ed2df66feb9cddffc791ebd08a3049e (diff)
downloadprolog-firewall-d6fea03e6576f6ddc48d6562abd84ba26d146f81.tar.gz
prolog-firewall-d6fea03e6576f6ddc48d6562abd84ba26d146f81.tar.bz2
prolog-firewall-d6fea03e6576f6ddc48d6562abd84ba26d146f81.tar.xz
prolog-firewall-d6fea03e6576f6ddc48d6562abd84ba26d146f81.zip
wip
-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).