Browse Source

implement subnet->bl

master
haskal 10 months ago
parent
commit
a603926b94
2 changed files with 11 additions and 3 deletions
  1. +10
    -2
      iputil.rkt
  2. +1
    -1
      radix-tree.rkt

+ 10
- 2
iputil.rkt 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)))

+ 1
- 1
radix-tree.rkt 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))


Loading…
Cancel
Save