From 2a5a72f9338bdc971fe7d95a44e310b78066fa7d Mon Sep 17 00:00:00 2001 From: Oscar Najera Date: Fri, 6 Jun 2025 17:17:20 +0200 Subject: ip reduce --- geoip/ip.lisp | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) (limited to 'geoip') 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)) -- cgit v1.2.3