2001-09-12 14:53:50 -04:00
|
|
|
;; Does pretty-print of internet-addresses (IPv4)
|
|
|
|
;; ADDRESS address to pretty-print
|
|
|
|
;; SEPERATOR optional, defaults to ".", seperator between address-parts
|
|
|
|
;; Example:
|
|
|
|
;; (format-internet-host-address #x0a00ffff)
|
|
|
|
;; ==> "10.0.255.255"
|
|
|
|
;; (format-internet-host-address #x0a00ffff ":")
|
|
|
|
;; ==> "10:0:255:255"
|
|
|
|
|
|
|
|
(define (format-internet-host-address address . maybe-separator)
|
|
|
|
|
2001-11-13 08:50:24 -05:00
|
|
|
(let ((extract (lambda (shift)
|
|
|
|
(number->string
|
|
|
|
(bitwise-and (arithmetic-shift address (- shift))
|
|
|
|
255)))))
|
|
|
|
|
|
|
|
(let-optionals maybe-separator ((separator "."))
|
|
|
|
(string-append
|
|
|
|
(extract 24) separator (extract 16) separator
|
|
|
|
(extract 8) separator (extract 0)))))
|
|
|
|
|
2001-09-12 14:53:50 -04:00
|
|
|
;; does pretty-print of ports
|
|
|
|
;; Example:
|
|
|
|
;; (format-port #x0aff)
|
|
|
|
;; => "10,255"
|
|
|
|
|
|
|
|
(define (format-port port)
|
|
|
|
(string-append
|
|
|
|
(number->string (bitwise-and (arithmetic-shift port -8) 255))
|
|
|
|
","
|
|
|
|
(number->string (bitwise-and port 255))))
|
|
|
|
|