X-Git-Url: http://repo.macrolet.net/gitweb/?a=blobdiff_plain;f=contrib%2Fsb-bsd-sockets%2Fname-service.lisp;h=0b731dbcff65f7b70cf0206894dce194c2f71a45;hb=1483e561a090d9f07687da27f8dd10fcd4152be1;hp=3b2d576c2eb6f73be71a8f239090ded655b3757a;hpb=23953bc6b14c93f59268996554c18706c8e16581;p=sbcl.git diff --git a/contrib/sb-bsd-sockets/name-service.lisp b/contrib/sb-bsd-sockets/name-service.lisp index 3b2d576..0b731db 100644 --- a/contrib/sb-bsd-sockets/name-service.lisp +++ b/contrib/sb-bsd-sockets/name-service.lisp @@ -20,7 +20,7 @@ (car (host-ent-addresses host-ent))) (defun make-host-ent (h &optional errno) - (when (sb-grovel::foreign-nullp h) + (when (sb-alien:null-alien h) (name-service-error "gethostbyname" errno)) (let* ((length (sockint::hostent-length h)) (aliases (loop for i = 0 then (1+ i) @@ -61,6 +61,9 @@ ;;; Resolving +#-sb-bsd-sockets-addrinfo +(sb-ext:defglobal **gethostby-lock** (sb-thread:make-mutex :name "gethostby lock")) + (defun get-host-by-name (host-name) "Returns a HOST-ENT instance for HOST-NAME or signals a NAME-SERVICE-ERROR. HOST-NAME may also be an IP address in dotted quad notation or some other @@ -68,7 +71,8 @@ weird stuff - see gethostbyname(3) or getaddrinfo(3) for the details." #+sb-bsd-sockets-addrinfo (get-address-info host-name) #-sb-bsd-sockets-addrinfo - (make-host-ent (sockint::gethostbyname host-name))) + (sb-thread::with-system-mutex (**gethostby-lock** :allow-with-interrupts t) + (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 @@ -77,22 +81,23 @@ weird stuff - see gethostbyname(3) or getaddrinfo(3) for the details." #+sb-bsd-sockets-addrinfo (get-name-info address) #-sb-bsd-sockets-addrinfo - (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))))) + (sb-thread::with-system-mutex (**gethostby-lock** :allow-with-interrupts t) + (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)))))) ;;; Emulate the above two functions with getaddrinfo / getnameinfo #+sb-bsd-sockets-addrinfo (defun get-address-info (node) - (sb-alien:with-alien ((res (* (* sockint::addrinfo)) :local - (sb-alien:make-alien (* sockint::addrinfo)))) - (let ((err (sockint::getaddrinfo node nil nil res))) + (sb-alien:with-alien ((buf (sb-alien:array (* sockint::addrinfo) 1))) + (let* ((res (sb-alien:addr (sb-alien:deref buf 0))) + (err (sockint::getaddrinfo node nil nil res))) (if (zerop err) (let ((host-ent (make-instance 'host-ent :name node @@ -114,7 +119,7 @@ weird stuff - see gethostbyname(3) or getaddrinfo(3) for the details." 4) (host-ent-addresses host-ent) :test 'equalp))))) - (sockint::free-addrinfo (sb-alien:deref res)) + (sockint::freeaddrinfo (sb-alien:deref res)) host-ent) (addrinfo-error "getaddrinfo" err))))) @@ -230,8 +235,11 @@ GET-NAME-SERVICE-ERRNO") sockint::EAI-FAIL no-recovery-error) (define-name-service-condition - sockint::NO-ADDRESS ;; Also defined as NO-DATA, with the same value - #-freebsd sockint::EAI-NODATA #+freebsd nil + ;; Also defined as NO-DATA, with the same value + sockint::NO-ADDRESS + ;; getaddrinfo() as of RFC 3493 can no longer distinguish between + ;; host no found and address not found + nil no-address-error) (defun condition-for-name-service-errno (err)