From 02b20379584ab4467276e00fed34e879587525e5 Mon Sep 17 00:00:00 2001 From: Sean Whitton Date: Wed, 30 Jun 2021 23:03:57 -0700 Subject: add NETWORK:{CLEAN-/ETC/NETWORK/INTERFACES,PRESERVE-STATIC-ONCE} Signed-off-by: Sean Whitton --- src/util.lisp | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) (limited to 'src/util.lisp') diff --git a/src/util.lisp b/src/util.lisp index 74aea8d..73810ae 100644 --- a/src/util.lisp +++ b/src/util.lisp @@ -266,6 +266,37 @@ expansion as a starting point for your own DEFPACKAGE form for your consfig." (declare (ignore ,ignore) ,@declarations) ,@forms)))) +(defun parse-cidr (address-with-suffix) + (destructuring-bind (address cidr) + (split-string address-with-suffix :separator "/") + (unless cidr + (simple-program-error "~A is not in CIDR notation." + address-with-suffix)) + (values + address + (loop with cidr = (parse-integer cidr) + with type = (if (or (> cidr 32) (find #\: address)) 6 4) + with block-digits = (if (= type 4) 8 16) + repeat (if (= type 4) 4 8) + for digits = (min cidr block-digits) + do (decf cidr digits) + collect (parse-integer + (with-output-to-string (s) + (loop repeat digits do (princ #\1 s)) + (loop repeat (- block-digits digits) do (princ #\0 s))) + :radix 2) + into accum + finally (return (if (= type 4) + (format nil "~{~D~^.~}" accum) + (with-output-to-string (s) + (loop for blocks on accum + if (> (car blocks) 0) + do (format s "~X" (car blocks)) + and if (cdr blocks) do (princ #\: s) + end + else do (princ #\: s) + (loop-finish))))))))) + ;;;; Progress & debug printing -- cgit v1.2.3