cl-rw

Layered streams for Common Lisp
git clone https://logand.com/git/cl-rw.git/
Log | Files | Refs

commit b9f176ce3b6708af2ebd3c9a9b8ed65ef51d2918
parent 513d9793d354b596d09d92bc8f040a7f16762c19
Author: Tomas Hlavaty <tom@logand.com>
Date:   Fri, 26 Dec 2014 19:24:37 +0100

fix ipv4 address parsing

Diffstat:
Msocket.lisp | 73++++++++++++++++++++++++++++++++++++++++---------------------------------
1 file changed, 40 insertions(+), 33 deletions(-)

diff --git a/socket.lisp b/socket.lisp @@ -47,46 +47,53 @@ ipv4-integer-to-vector #+ccl progn - (cond - ((eql #\0 (rw:peek r)) - (rw:next r) - (cond - ((member (rw:peek r) '(#\x #\X)) - (rw:next r) - (rw:next-z0 r 16)) - (t - (rw:next-z0 r 8)))) - (t - (let ((a (rw:next-z0 r))) - (cond - ((eql #\. (rw:peek r)) - (rw:next r) - (let ((b (rw:next-z0 r))) - (cond - ((eql #\. (rw:peek r)) - (rw:next r) - (let ((c (rw:next-z0 r))) - (cond - ((eql #\. (rw:peek r)) - (rw:next r) - (logior (ash a 24) (ash b 16) (ash c 8) (rw:next-z0 r))) - (t - (logior (ash a 24) (ash b 16) c))))) - (t - (logior (ash a 24) b))))) - (t a))))))) + (flet ((one () + (cond + ((eql #\0 (rw:peek r)) + (rw:next r) + (cond + ((member (rw:peek r) '(nil #\.)) + 0) + ((member (rw:peek r) '(#\x #\X)) + (rw:next r) + (rw:next-z0 r 16)) + (t (rw:next-z0 r 8)))) + (t (rw:next-z0 r))))) + (let ((a (one))) + (cond + ((eql #\. (rw:peek r)) + (rw:next r) + (let ((b (one))) + (cond + ((eql #\. (rw:peek r)) + (rw:next r) + (let ((c (one))) + (cond + ((eql #\. (rw:peek r)) + (rw:next r) + (logior (ash a 24) (ash b 16) (ash c 8) (one))) + (t + (logior (ash a 24) (ash b 16) c))))) + (t + (logior (ash a 24) b))))) + (t a)))))) (defun parse-ipv4-address (x) (next-ipv4-address (rw:peek-reader (rw:reader x)))) +;;(parse-ipv4-address "172.31.53.254") +;;(parse-ipv4-address "172.2045438") +;;(parse-ipv4-address "172.31.13822") ;;(parse-ipv4-address "0xac1f35fe") ;;(parse-ipv4-address "025407632776") ;;(parse-ipv4-address "2887726590") -;;(parse-ipv4-address "172.2045438") -;;(parse-ipv4-address "172.31.13822") -;;(parse-ipv4-address "172.31.53.254") - -;;(parse-ipv4-address "ac.1f.35.fe") ;; TODO ??? +;;(parse-ipv4-address "192.0.2.235") +;;(parse-ipv4-address "0xC0.0x00.0x02.0xEB") +;;(parse-ipv4-address "0300.0000.0002.0353") +;;(parse-ipv4-address "0xC00002EB") +;;(parse-ipv4-address "3221226219") +;;(parse-ipv4-address "030000001353") +;;(parse-ipv4-address "127.1") (defun ipv4-integer-to-dotted (x) (format nil "~d.~d.~d.~d"