netmask-ip
This commit is contained in:
parent
901cd5beee
commit
38be205744
|
@ -4,6 +4,7 @@
|
||||||
string->ip
|
string->ip
|
||||||
ip->string
|
ip->string
|
||||||
ip-netmask
|
ip-netmask
|
||||||
|
netmask-ip
|
||||||
string->subnet
|
string->subnet
|
||||||
subnet->string
|
subnet->string
|
||||||
string->peer
|
string->peer
|
||||||
|
@ -51,6 +52,10 @@
|
||||||
#:break (positive? (bitwise-and ip (arithmetic-shift 1 i)))
|
#:break (positive? (bitwise-and ip (arithmetic-shift 1 i)))
|
||||||
1)))
|
1)))
|
||||||
|
|
||||||
|
(define (netmask-ip mask)
|
||||||
|
(arithmetic-shift (sub1 (arithmetic-shift 1 mask))
|
||||||
|
(- 32 mask)))
|
||||||
|
|
||||||
(define (string->subnet str)
|
(define (string->subnet str)
|
||||||
(match-define (list ipstr maskstr) (string-split str "/"))
|
(match-define (list ipstr maskstr) (string-split str "/"))
|
||||||
(subnet (string->ip ipstr)
|
(subnet (string->ip ipstr)
|
||||||
|
@ -78,6 +83,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->string (netmask-ip 23)) "255.255.254.0")
|
||||||
|
(check-equal? (ip->string (netmask-ip 8)) "255.0.0.0")
|
||||||
|
|
||||||
(check-equal? (ip-netmask (string->ip "255.255.254.0")) 23)
|
(check-equal? (ip-netmask (string->ip "255.255.254.0")) 23)
|
||||||
(check-equal? (ip-netmask (string->ip "255.0.0.0")) 8)
|
(check-equal? (ip-netmask (string->ip "255.0.0.0")) 8)
|
||||||
(check-equal? (subnet->bl (string->subnet "3.3.0.0/24"))
|
(check-equal? (subnet->bl (string->subnet "3.3.0.0/24"))
|
||||||
|
|
Loading…
Reference in New Issue