From: Stelian Ionescu Date: Thu, 11 Jul 2013 11:26:17 +0000 (+0200) Subject: Use endianness functions from swap-bytes X-Git-Tag: v0.8.1~56 X-Git-Url: https://repo.or.cz/w/iolib.git/commitdiff_plain/3574c4ef06537c7e95f9f0170beb88f24430ebdc Use endianness functions from swap-bytes --- diff --git a/iolib.asd b/iolib.asd index f2e0023..068191d 100644 --- a/iolib.asd +++ b/iolib.asd @@ -197,7 +197,7 @@ :defsystem-depends-on (:iolib/asdf :iolib/conf :iolib/grovel) :depends-on (:iolib/base :iolib/syscalls :iolib/streams :babel :cffi :iolib/grovel :bordeaux-threads - :idna) + :idna :swap-bytes) :around-compile "iolib/asdf:compile-wrapper" :encoding :utf-8 :pathname "src/sockets/" diff --git a/src/sockets/common.lisp b/src/sockets/common.lisp index c7f0681..aeb3ce5 100644 --- a/src/sockets/common.lisp +++ b/src/sockets/common.lisp @@ -10,28 +10,6 @@ (deftype ipv4-array () '(ub8-sarray 4)) (deftype ipv6-array () '(ub16-sarray 8)) -;;;; Byte-swap functions - -(defun htons (short) - #+little-endian - (logior (ash (logand (the ub16 short) #x00FF) 8) - (ash (logand (the ub16 short) #xFF00) -8)) - #+big-endian short) - -(defun ntohs (short) - (htons short)) - -(defun htonl (long) - #+little-endian - (logior (ash (logand (the ub32 long) #x000000FF) 24) - (ash (logand (the ub32 long) #x0000FF00) 8) - (ash (logand (the ub32 long) #x00FF0000) -8) - (ash (logand (the ub32 long) #xFF000000) -24)) - #+big-endian long) - -(defun ntohl (long) - (htonl long)) - ;;;; Conversion between address formats (defun copy-simple-array-ub16-to-alien-vector (lisp-vec alien-vec) diff --git a/src/sockets/pkgdcl.lisp b/src/sockets/pkgdcl.lisp index 995003d..b8f4f2b 100644 --- a/src/sockets/pkgdcl.lisp +++ b/src/sockets/pkgdcl.lisp @@ -8,6 +8,8 @@ (defpackage :iolib.sockets (:nicknames :sockets :iolib/sockets) (:use :iolib.base :iolib.streams :cffi) + (:import-from #:swap-bytes + #:htons #:ntohs #:htonl #:ntohl) (:import-from #:iolib.syscalls #:defsyscall #:size-t #:ssize-t #:pid-t #:uid-t #:gid-t #:timeval #:sec #:usec)