Changeset 16345


Ignore:
Timestamp:
Jan 22, 2015, 2:13:56 AM (5 years ago)
Author:
rme
Message:

Attempt to restore support for using an (unsigned-byte 32) as an IPv4
address.

I'm not convinced this is a great way to do it; but it will probably stay
in forever anyway.

Closes ticket:1259.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/source/library/sockets.lisp

    r16342 r16345  
    14801480
    14811481errorp may be passed as NIL to return NIL if no match was found."
     1482
     1483  ;; We have historically supported the use of an (unsigned-byte 32)
     1484  ;; value to represent an IPv4 address. If existing code does that to
     1485  ;; avoid overhead (name resolution, consing, what-have-you), then
     1486  ;; that code may not appreciate the consing/mallocing we do here
     1487  ;; to support that.
     1488  (when (typep host '(unsigned-byte 32))
     1489    (let* ((proto (ecase socket-type
     1490                    ((nil :stream) "tcp")
     1491                    (:datagram "udp")))
     1492           (inet-port (typecase port
     1493                        (fixnum (htons port))
     1494                        (string (_getservbyname port proto))
     1495                        (symbol (_getservbyname (string-downcase
     1496                                                 (string port)) proto)))))
     1497      (if (null inet-port)
     1498        (when errorp
     1499          (error "can't resolve port ~s with getservbyname" port))
     1500        (let* ((socket-address (make-instance 'socket-address))
     1501               (sin (sockaddr socket-address)))
     1502          (setf (pref sin :sockaddr_in.sin_family) #$AF_INET)
     1503          (setf (pref sin
     1504                      #+(or windows-target solaris-target) #>sockaddr_in.sin_addr.S_un.S_addr
     1505                      #-(or windows-target solaris-target) :sockaddr_in.sin_addr.s_addr) (htonl host))
     1506          (setf (pref sin :sockaddr_in.sin_port) inet-port)
     1507          (upgrade-socket-address-from-sockaddr #$AF_INET socket-address)
     1508          (return-from resolve-address socket-address)))))
     1509   
    14821510  (with-cstrs ((host-buf (or host ""))
    14831511               (port-buf (string-downcase (or (ensure-string port) ""))))
Note: See TracChangeset for help on using the changeset viewer.