X-Git-Url: http://repo.macrolet.net/gitweb/?a=blobdiff_plain;ds=sidebyside;f=contrib%2Fsb-bsd-sockets%2Fname-service.lisp;h=2c02fcacbf0ed516858c738b871cc3ce62903173;hb=fb8533122551bbb7aea669f40bc91c1211809b58;hp=7fc2892f65afc1a43e277b66e23dafd3d505a769;hpb=d4c7ab04ed10729a2cfa3321f4382d8a218ad958;p=sbcl.git diff --git a/contrib/sb-bsd-sockets/name-service.lisp b/contrib/sb-bsd-sockets/name-service.lisp index 7fc2892..2c02fca 100644 --- a/contrib/sb-bsd-sockets/name-service.lisp +++ b/contrib/sb-bsd-sockets/name-service.lisp @@ -27,25 +27,6 @@ eventually, so that we can do DNS lookups in parallel with other things ;(define-condition no-recovery-error (socket-error)) ; name server error ;(define-condition try-again-error (socket-error)) ; temporary -(defun get-host-by-name (host-name) - "Returns a HOST-ENT instance for HOST-NAME or throws some kind of condition. -HOST-NAME may also be an IP address in dotted quad notation or some other -weird stuff - see gethostbyname(3) for grisly details." - (make-host-ent (sockint::gethostbyname host-name))) - -(defun get-host-by-address (address) - "Returns a HOST-ENT instance for ADDRESS, which should be a vector of - (integer 0 255), or throws some kind of error. See gethostbyaddr(3) for -grisly details." - (sockint::with-in-addr packed-addr () - (let ((addr-vector (coerce address 'vector))) - (loop for i from 0 below (length addr-vector) - do (setf (sb-alien:deref (sockint::in-addr-addr packed-addr) i) - (elt addr-vector i))) - (make-host-ent (sockint::gethostbyaddr packed-addr - 4 - sockint::af-inet))))) - (defun make-host-ent (h) (if (sb-grovel::foreign-nullp h) (name-service-error "gethostbyname")) (let* ((length (sockint::hostent-length h)) @@ -53,15 +34,17 @@ grisly details." for al = (sb-alien:deref (sockint::hostent-aliases h) i) while al collect al)) - (address0 (sockint::hostent-addresses h)) (addresses (loop for i = 0 then (1+ i) - for ad = (sb-alien:deref address0 i) + for ad = (sb-alien:deref (sockint::hostent-addresses h) i) until (sb-alien:null-alien ad) collect (ecase (sockint::hostent-type h) (#.sockint::af-inet - (loop for i from 0 below length - collect (sb-alien:deref ad i))) + (assert (= length 4)) + (let ((addr (make-array 4 :element-type '(unsigned-byte 8)))) + (loop for i from 0 below length + do (setf (elt addr i) (sb-alien:deref ad i))) + addr)) (#.sockint::af-local (sb-alien:cast ad sb-alien:c-string)))))) (make-instance 'host-ent @@ -70,6 +53,25 @@ grisly details." :aliases aliases :addresses addresses))) +(defun get-host-by-name (host-name) + "Returns a HOST-ENT instance for HOST-NAME or throws some kind of condition. +HOST-NAME may also be an IP address in dotted quad notation or some other +weird stuff - see gethostbyname(3) for grisly details." + (make-host-ent (sockint::gethostbyname host-name))) + +(defun get-host-by-address (address) + "Returns a HOST-ENT instance for ADDRESS, which should be a vector of + (integer 0 255), or throws some kind of error. See gethostbyaddr(3) for +grisly details." + (sockint::with-in-addr packed-addr () + (let ((addr-vector (coerce address 'vector))) + (loop for i from 0 below (length addr-vector) + do (setf (sb-alien:deref (sockint::in-addr-addr packed-addr) i) + (elt addr-vector i))) + (make-host-ent (sockint::gethostbyaddr packed-addr + 4 + sockint::af-inet))))) + ;;; The remainder is my fault - gw (defvar *name-service-errno* 0