Hi, Erik

On SBCL (I'm using 1.0.18.x), HOST-TO-HBO cannot work for string:

* (usocket::host-to-hbo "localhost")

debugger invoked on a SB-KERNEL:CASE-FAILURE:
  #(127 0 0 1) fell through ETYPECASE expression.
  Wanted one of (INTEGER (VECTOR T 4) STRING).

Type HELP for debugger help, or (SB-EXT:QUIT) to exit from SBCL.

restarts (invokable by number or by possibly-abbreviated name):
  0: [ABORT] Exit debugger, returning to top level.

This is because SBCL return #(127 0 0 1) as type (simple-array (unsigned-byte 8) (4)), it's not a subtype of (VECTOR T 4).

An solution is add more type to the ETYPECASE of HOST-TO-HBO: (and HOST-TO-VECTOR-QUAD)

#-(or clisp armedbear)
(progn
  (defun host-to-vector-quad (host)
"Translate a host specification (vector quad, dotted quad or domain name)
to a vector quad."
    (etypecase host
      (string (let* ((ip (ignore-errors
                           (dotted-quad-to-vector-quad host))))
                (if (and ip (= 4 (length ip)))
                    ;; valid IP dotted quad?
                    ip
                  (get-random-host-by-name host))))
      ((vector t 4) host)
      ((simple-array (unsigned-byte 8) (4)) host)
      (integer (hbo-to-vector-quad host))
      (null nil)))

  (defun host-to-hbo (host)
    (etypecase host
      (string (let ((ip (ignore-errors
                          (dotted-quad-to-vector-quad host))))
                (if (and ip (= 4 (length ip)))
                    (host-byte-order ip)
                  (host-to-hbo (get-host-by-name host)))))
      ((vector t 4) (host-byte-order host))
      ((simple-array (unsigned-byte 8) (4)) (host-byte-order host))
      (integer host)
      (null nil))))

For some reason, I think just let (HOST-TO-HBO NIL) returns NIL will be good, can save us some coding.

Please review this, thanks.

Regards,

Chun Tian (binghe)

_______________________________________________
usocket-devel mailing list
usocket-devel@common-lisp.net
http://common-lisp.net/cgi-bin/mailman/listinfo/usocket-devel

Reply via email to