implement subnet->bl

This commit is contained in:
xenia 2020-01-31 21:27:51 -05:00
parent 0127f57230
commit a603926b94
2 changed files with 11 additions and 3 deletions

View File

@ -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)))

View File

@ -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))