X-Git-Url: http://repo.macrolet.net/gitweb/?a=blobdiff_plain;f=contrib%2Fsb-bsd-sockets%2Fname-service.lisp;h=2c02fcacbf0ed516858c738b871cc3ce62903173;hb=fb8533122551bbb7aea669f40bc91c1211809b58;hp=46094d27a7699d342c8541a5c3f1fe837f153e4e;hpb=b7eed59f1877263e1af5ad80299e641e8276f77d;p=sbcl.git diff --git a/contrib/sb-bsd-sockets/name-service.lisp b/contrib/sb-bsd-sockets/name-service.lisp index 46094d2..2c02fca 100644 --- a/contrib/sb-bsd-sockets/name-service.lisp +++ b/contrib/sb-bsd-sockets/name-service.lisp @@ -27,50 +27,50 @@ 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 make-host-ent (h) + (if (sb-grovel::foreign-nullp h) (name-service-error "gethostbyname")) + (let* ((length (sockint::hostent-length h)) + (aliases (loop for i = 0 then (1+ i) + for al = (sb-alien:deref (sockint::hostent-aliases h) i) + while al + collect al)) + (addresses + (loop for i = 0 then (1+ 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 + (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 + :name (sockint::hostent-name h) + :type (sockint::hostent-type h) + :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." - (let ((h (sockint::gethostbyname host-name))) - (make-host-ent h))) + (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 + (integer 0 255), or throws some kind of error. See gethostbyaddr(3) for grisly details." - (let ((packed-addr (sockint::allocate-in-addr))) - (loop for i from 0 to 3 - do (setf (sockint::in-addr-addr packed-addr i) (elt address i))) - (make-host-ent - (sb-sys:with-pinned-objects (packed-addr) - (sockint::gethostbyaddr (sockint::array-data-address packed-addr) - 4 - sockint::af-inet))))) - -(defun make-host-ent (h) - (if (sockint::foreign-nullp h) (name-service-error "gethostbyname")) - (let* ((local-h (sockint::foreign-vector h 1 sockint::size-of-hostent)) - (length (sockint::hostent-length local-h)) - (aliases - (loop for i = 0 then (1+ i) - for al = (sb-sys:sap-ref-sap - (sb-sys:int-sap (sockint::hostent-aliases local-h)) - (* i 4)) - until (= (sb-sys:sap-int al) 0) - collect (sb-c-call::%naturalize-c-string al))) - (address0 (sb-sys:sap-ref-sap (sb-sys:int-sap (sockint::hostent-addresses local-h)) 0)) - (addresses - (loop for i = 0 then (+ length i) - for ad = (sb-sys:sap-ref-32 address0 i) - while (> ad 0) - collect - (sockint::foreign-vector (sb-sys:sap+ address0 i) 1 length)))) - (make-instance 'host-ent - :name (sb-c-call::%naturalize-c-string - (sb-sys:int-sap (sockint::hostent-name local-h))) - :type (sockint::hostent-type local-h) - :aliases aliases - :addresses addresses))) + (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 @@ -130,7 +130,7 @@ GET-NAME-SERVICE-ERRNO") (sb-alien:alien-funcall (sb-alien:extern-alien "get_h_errno" (function integer))))) -#-solaris +#-(and cmu solaris) (progn #+sbcl (sb-alien:define-alien-routine "hstrerror" @@ -143,4 +143,3 @@ GET-NAME-SERVICE-ERRNO") (defun get-name-service-error-message (num) (hstrerror num)) ) -