From a603926b94726cfdffd83e0275a90a1f81353e03 Mon Sep 17 00:00:00 2001 From: haskal Date: Fri, 31 Jan 2020 21:27:51 -0500 Subject: [PATCH] implement subnet->bl --- iputil.rkt | 12 ++++++++++-- radix-tree.rkt | 2 +- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/iputil.rkt b/iputil.rkt index ecc9474..e87748c 100644 --- a/iputil.rkt +++ b/iputil.rkt @@ -59,6 +59,10 @@ (ip->string (subnet-ip sub)) (subnet-mask sub))) +(define (subnet->bl sub) + (for/list ([i (in-range (subnet-mask sub))]) + (= 1 (bitwise-and 1 (arithmetic-shift (subnet-ip sub) (- i 31)))))) + (define (string->peer str) (match-define (list ip type) (string-split str "-")) (peer (string->ip ip) (string->symbol type))) @@ -69,5 +73,9 @@ (check-equal? (ip->string (string->ip "123.84.0.67")) "123.84.0.67") (check-equal? (ip->string (string->ip "0.0.0.0")) "0.0.0.0") - (check-equal? (ip-netmask (string->ip "255.255.254.0")) 9) - (check-equal? (ip-netmask (string->ip "255.0.0.0")) 24)) + (check-equal? (ip-netmask (string->ip "255.255.254.0")) 23) + (check-equal? (ip-netmask (string->ip "255.0.0.0")) 8) + (check-equal? (subnet->bl (string->subnet "3.3.0.0/24")) + '(#f #f #f #f #f #f #t #t + #f #f #f #f #f #f #t #t + #f #f #f #f #f #f #f #f))) diff --git a/radix-tree.rkt b/radix-tree.rkt index 7adb4c6..ee45d7d 100644 --- a/radix-tree.rkt +++ b/radix-tree.rkt @@ -7,7 +7,7 @@ (struct rt-node [edge0 edge1 data] #:transparent #:mutable) (struct rt-edge [label target] #:transparent) -(define empty-node-data (gensym 'WATERDRINKERS)) +(define empty-node-data (gensym 'MEOW)) (define (make-rt) (rt-node #f #f empty-node-data))