implement subnet->bl
This commit is contained in:
parent
0127f57230
commit
a603926b94
12
iputil.rkt
12
iputil.rkt
|
@ -59,6 +59,10 @@
|
||||||
(ip->string (subnet-ip sub))
|
(ip->string (subnet-ip sub))
|
||||||
(subnet-mask 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)
|
(define (string->peer str)
|
||||||
(match-define (list ip type) (string-split str "-"))
|
(match-define (list ip type) (string-split str "-"))
|
||||||
(peer (string->ip ip) (string->symbol type)))
|
(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 "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->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.255.254.0")) 23)
|
||||||
(check-equal? (ip-netmask (string->ip "255.0.0.0")) 24))
|
(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)))
|
||||||
|
|
|
@ -7,7 +7,7 @@
|
||||||
(struct rt-node [edge0 edge1 data] #:transparent #:mutable)
|
(struct rt-node [edge0 edge1 data] #:transparent #:mutable)
|
||||||
(struct rt-edge [label target] #:transparent)
|
(struct rt-edge [label target] #:transparent)
|
||||||
|
|
||||||
(define empty-node-data (gensym 'WATERDRINKERS))
|
(define empty-node-data (gensym 'MEOW))
|
||||||
|
|
||||||
(define (make-rt)
|
(define (make-rt)
|
||||||
(rt-node #f #f empty-node-data))
|
(rt-node #f #f empty-node-data))
|
||||||
|
|
Loading…
Reference in New Issue