Changeset 11068 for trunk/source/level-1


Ignore:
Timestamp:
Oct 12, 2008, 4:52:55 PM (11 years ago)
Author:
rme
Message:

IPADDR-TO-DOTTED: don't call _INET_NTOA, just use FORMAT.

_INET_NTOA: remove. In addition to avoiding a bit of
conditionalization ugliness, we also avoid the non-thread-safe C
library function inet_ntoa(), which returns a pointer to a static
memory area.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/source/level-1/l1-sockets.lisp

    r11033 r11068  
    10851085(defun ipaddr-to-dotted (addr &key values)
    10861086  "Convert a 32-bit unsigned IP address into octets."
    1087   (if values
    1088       (values (ldb (byte 8 24) addr)
    1089               (ldb (byte 8 16) addr)
    1090               (ldb (byte 8  8) addr)
    1091               (ldb (byte 8  0) addr))
    1092     (_inet_ntoa (htonl addr))))
     1087  (let* ((a (ldb (byte 8 24) addr))
     1088         (b (ldb (byte 8 16) addr))
     1089         (c (ldb (byte 8  8) addr))
     1090         (d (ldb (byte 8  0) addr)))
     1091    (if values
     1092      (values a b c d)
     1093      (format nil "~d.~d.~d.~d" a b c d))))
    10931094
    10941095(defun ipaddr-to-hostname (ipaddr &key ignore-cache)
     
    11681169      (unless (%null-ptr-p servent-ptr)
    11691170        (pref servent-ptr :servent.s_port)))))
    1170 
    1171 #+linuxppc-target
    1172 (defun _inet_ntoa (addr)
    1173   (rlet ((addrp :unsigned))
    1174     (setf (pref addrp :unsigned) addr)
    1175     (with-macptrs ((p))
    1176       (%setf-macptr p (#_inet_ntoa addrp))
    1177       (unless (%null-ptr-p p) (%get-cstring p)))))
    1178 
    1179 ;;; On all of these platforms, the argument is a (:struct :in_addr),
    1180 ;;; a single word that should be passed by value.  The FFI translator
    1181 ;;; seems to lose the :struct, so just using #_ doesn't work (that
    1182 ;;; sounds like a bug in the FFI translator.)
    1183 #-linuxppc-target
    1184 (defun _inet_ntoa (addr)
    1185   (with-macptrs ((p))
    1186     (%setf-macptr p (external-call #+darwin-target "_inet_ntoa"
    1187                                    #-darwin-target "inet_ntoa"
    1188                                    :unsigned-fullword (htonl addr)
    1189                                    :address))
    1190     (unless (%null-ptr-p p) (%get-cstring p))))                           
    1191 
    11921171
    11931172(defun _inet_aton (string)
Note: See TracChangeset for help on using the changeset viewer.