From df44cd4558a851213a971a1362702049004ba1cc Mon Sep 17 00:00:00 2001 From: Stelian Ionescu Date: Sun, 20 Jan 2008 00:59:41 +0100 Subject: [PATCH] Args REMOTE-ADDRESS and REMOTE-PORT of SEND-TO now get resolved. Signed-off-by: Stelian Ionescu --- sockets/common.lisp | 2 ++ sockets/dns/lookup.lisp | 10 ++++++++++ sockets/make-socket.lisp | 10 ---------- sockets/socket-methods.lisp | 24 ++++++++++++++---------- 4 files changed, 26 insertions(+), 20 deletions(-) diff --git a/sockets/common.lisp b/sockets/common.lisp index cf3e969..2fa9e9a 100644 --- a/sockets/common.lisp +++ b/sockets/common.lisp @@ -209,6 +209,8 @@ (defmacro check-bounds (sequence start end) (with-gensyms (length) `(let ((,length (length ,sequence))) + (check-type ,start unsigned-byte "a non-negative integer") + (check-type ,end (or unsigned-byte null) "a non-negative integer or NIL") (unless ,end (setq ,end ,length)) (unless (<= ,start ,end ,length) diff --git a/sockets/dns/lookup.lisp b/sockets/dns/lookup.lisp index 28e9a82..bf70842 100644 --- a/sockets/dns/lookup.lisp +++ b/sockets/dns/lookup.lisp @@ -140,3 +140,13 @@ behaviour, defaults to *IPV6*." (t (check-type host string "a string") (lookup-host-by-name host ipv6))))) + +(defun convert-or-lookup-inet-address (address &optional (ipv6 *ipv6*)) + "If ADDRESS is an inet-address designator, it is converted, if +necessary, to an INET-ADDRESS object and returned. Otherwise it +is assumed to be a host name which is then looked up in order to +return its primary address as the first return value and the +remaining address list as the second return value." + (or (ignore-parse-errors (ensure-address address :internet)) + (let ((addresses (lookup-host address :ipv6 ipv6))) + (values (car addresses) (cdr addresses))))) diff --git a/sockets/make-socket.lisp b/sockets/make-socket.lisp index 4563e01..ead3d6b 100644 --- a/sockets/make-socket.lisp +++ b/sockets/make-socket.lisp @@ -44,16 +44,6 @@ On error call CLOSE with :ABORT T on VAR." (error (err) `(error ,err))) ,form)) -(defun convert-or-lookup-inet-address (address &optional (ipv6 *ipv6*)) - "If ADDRESS is an inet-address designator, it is converted, if -necessary, to an INET-ADDRESS object and returned. Otherwise it -is assumed to be a host name which is then looked up in order to -return its primary address as the first return value and the -remaining address list as the second return value." - (or (ignore-parse-errors (ensure-address address :internet)) - (let ((addresses (lookup-host address :ipv6 ipv6))) - (values (car addresses) (cdr addresses))))) - (define-symbol-macro +default-host+ (if *ipv6* +ipv6-unspecified+ +ipv4-unspecified+)) diff --git a/sockets/socket-methods.lisp b/sockets/socket-methods.lisp index 046a54d..a8c3c55 100644 --- a/sockets/socket-methods.lisp +++ b/sockets/socket-methods.lisp @@ -398,10 +398,8 @@ (defun %socket-send (socket buffer start end remote-address remote-port flags) (when (typep socket 'passive-socket) (error "You cannot send data on a passive socket.")) - (check-type start unsigned-byte "a non-negative integer") - (check-type end (or unsigned-byte null) "a non-negative integer or NIL") - (check-type remote-address (or address null) "a network address or NIL") - (check-type remote-port tcp-port "a valid TCP port number") + (when remote-address (setf remote-address (convert-or-lookup-inet-address remote-address))) + (when remote-port (setf remote-port (ensure-numerical-service remote-port))) (when (and (ipv4-address-p remote-address) (eq (socket-family socket) :ipv6)) (setf remote-address (map-ipv4-address-to-ipv6 remote-address))) @@ -417,15 +415,21 @@ (if remote-address size-of-sockaddr-storage 0)))))) (defmethod send-to ((socket active-socket) buffer &rest args - &key (start 0) end remote-address (remote-port 0)) - (%socket-send socket buffer start end remote-address remote-port - (compute-flags *sendmsg-flags* args))) + &key (start 0) end remote-address (remote-port 0) (ipv6 *ipv6*)) + (let ((*ipv6* ipv6)) + (%socket-send socket buffer start end remote-address remote-port + (compute-flags *sendmsg-flags* args)))) (define-compiler-macro send-to (&whole form socket buffer &rest args - &key (start 0) end remote-address (remote-port 0)) + &key (start 0) end remote-address (remote-port 0) + (ipv6 '*ipv6* ipv6p)) (let ((flags (compute-flags *sendmsg-flags* args))) - (cond (flags `(%socket-send ,socket ,buffer ,start ,end - ,remote-address ,remote-port ,flags)) + (cond (flags (if ipv6p + `(let ((*ipv6* ,ipv6)) + (%socket-send ,socket ,buffer ,start ,end + ,remote-address ,remote-port ,flags)) + `(%socket-send ,socket ,buffer ,start ,end + ,remote-address ,remote-port ,flags))) (t form)))) ;;;; RECVFROM -- 2.11.4.GIT