X-Git-Url: http://repo.macrolet.net/gitweb/?a=blobdiff_plain;f=contrib%2Fsb-bsd-sockets%2Finet.lisp;h=57ab02c87c08669ee1eecf643e98ca7a45bb72da;hb=f2db6743b1fadeea9e72cb583d857851c87efcd4;hp=5879341567a3b60c0764ccc0c563cb2a56d60309;hpb=5eb1bc45f5bd68638ae861dd8bd81c33ae6cd14d;p=sbcl.git diff --git a/contrib/sb-bsd-sockets/inet.lisp b/contrib/sb-bsd-sockets/inet.lisp index 5879341..57ab02c 100644 --- a/contrib/sb-bsd-sockets/inet.lisp +++ b/contrib/sb-bsd-sockets/inet.lisp @@ -22,10 +22,30 @@ Examples: (defun make-inet-address (dotted-quads) "Return a vector of octets given a string DOTTED-QUADS in the format -\"127.0.0.1\"" - (map 'vector - #'parse-integer - (split dotted-quads nil '(#\.)))) +\"127.0.0.1\". Signals an error if the string is malformed." + (declare (type string dotted-quads)) + (labels ((oops () + (error "~S is not a string designating an IP address." + dotted-quads)) + (check (x) + (if (typep x '(unsigned-byte 8)) + x + (oops)))) + (let* ((s1 (position #\. dotted-quads)) + (s2 (if s1 (position #\. dotted-quads :start (1+ s1)) (oops))) + (s3 (if s2 (position #\. dotted-quads :start (1+ s2)) (oops))) + (u0 (parse-integer dotted-quads :end s1)) + (u1 (parse-integer dotted-quads :start (1+ s1) :end s2)) + (u2 (parse-integer dotted-quads :start (1+ s2) :end s3))) + (multiple-value-bind (u3 end) (parse-integer dotted-quads :start (1+ s3) :junk-allowed t) + (unless (= end (length dotted-quads)) + (oops)) + (let ((vector (make-array 4 :element-type '(unsigned-byte 8)))) + (setf (aref vector 0) (check u0) + (aref vector 1) (check u1) + (aref vector 2) (check u2) + (aref vector 3) (check u3)) + vector))))) (define-condition unknown-protocol () ((name :initarg :name @@ -42,7 +62,7 @@ using getprotobyname(2) which typically looks in NIS or /etc/protocols" ;; for extra brownie points, could return canonical protocol name ;; and aliases as extra values (let ((ent (sockint::getprotobyname name))) - (if (sb-grovel::foreign-nullp ent) + (if (sb-alien::null-alien ent) (error 'unknown-protocol :name name)) (sockint::protoent-proto ent)))