-;(define-condition host-not-found-error (socket-error)) ; host unknown
-;(define-condition no-address-error (socket-error)) ; valid name but no IP address
-;(define-condition no-recovery-error (socket-error)) ; name server error
-;(define-condition try-again-error (socket-error)) ; temporary
+(defun make-host-ent (h &optional errno)
+ (when (sb-grovel::foreign-nullp h)
+ (name-service-error "gethostbyname" errno))
+ (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
+ ;; CLH: Work around x86-64 darwin bug here.
+ ;; The length is reported as 8, when it should be 4.
+ ;; FIXME: this is rumored to be fix in 10.5
+ #+(and darwin x86-64)
+ (progn
+ (assert (or (= length 4) (= length 8)))
+ (naturalize-unsigned-byte-8-array ad 4))
+ #-(and darwin x86-64)
+ (progn
+ (assert (= length 4))
+ (naturalize-unsigned-byte-8-array ad length)))
+ #-win32
+ (#.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 naturalize-unsigned-byte-8-array (array length)
+ (let ((addr (make-array 4 :element-type '(unsigned-byte 8))))
+ (dotimes (i length)
+ (setf (elt addr i) (sb-alien:deref array i)))
+ addr))
+
+;;; Resolving