diff options
author | Oscar Najera <hi@oscarnajera.com> | 2025-06-06 17:17:20 +0200 |
---|---|---|
committer | Oscar Najera <hi@oscarnajera.com> | 2025-06-06 18:27:04 +0200 |
commit | 2a5a72f9338bdc971fe7d95a44e310b78066fa7d (patch) | |
tree | c6f222ae024ec2dc2d695e251f4448c470fe9b71 | |
parent | 4b37bdabec56aadda803c0cf2c5f6d25d178eb96 (diff) | |
download | scratch-2a5a72f9338bdc971fe7d95a44e310b78066fa7d.tar.gz scratch-2a5a72f9338bdc971fe7d95a44e310b78066fa7d.tar.bz2 scratch-2a5a72f9338bdc971fe7d95a44e310b78066fa7d.zip |
ip reduce
-rw-r--r-- | geoip/ip.lisp | 18 |
1 files changed, 8 insertions, 10 deletions
diff --git a/geoip/ip.lisp b/geoip/ip.lisp index 6b8fad7..e00ba89 100644 --- a/geoip/ip.lisp +++ b/geoip/ip.lisp @@ -18,23 +18,21 @@ (5am:is (= (octet-to-int '(1 5) :big-endian nil) #x501))) (defun parse-ipv4 (ip-address) - (reduce (lambda (acc part) - (let ((n (parse-integer part))) - (assert (<= 0 n 255)) - (+ (ash acc 8) n))) + (reduce (lambda (acc n) + (assert (<= 0 n 255)) + (+ (ash acc 8) n)) (split-sequence #\. ip-address) + :key #'parse-integer :initial-value 0)) (defun parse-ipv6 (ip-address) - (reduce (lambda (acc part) - (let ((n (if (string= part "") 0 - (parse-integer part :radix 16)))) - (assert (<= 0 n #xFFFF)) - (+ (ash acc 16) n))) + (reduce (lambda (acc n) + (assert (<= 0 n #xFFFF)) + (+ (ash acc 16) n)) (split-sequence #\: ip-address) + :key (lambda (part)(if (string= part "") 0 (parse-integer part :radix 16)) ) :initial-value 0)) - (defun parse-ip (ip-address) (if (find #\. ip-address) (cons 4 (parse-ipv4 ip-address)) |