liutanyu / mcl

Automatically exported from code.google.com/p/mcl
Other
0 stars 0 forks source link

Passive TCP streams should be able to listen to the loopback interface #28

Open GoogleCodeExporter opened 8 years ago

GoogleCodeExporter commented 8 years ago
The open-tcp-stream function and the opentransport classes will create a 
passive/listener TCP stream if the 
host is NIL. However, there is no way to create a TCP stream that listens to 
the loopback interface rather than 
making the listener public.

A patch is to use a parameter to pass the loopback address to 
ot-conn-tcp-passive-connect:

(defparameter *passive-interface-address* NIL
  "Address to use for passive connections - optionally bind to loopback address while opening a tcp stream")

 This can be integrated into ot-conn-tcp-passive-connect rather than being an advise:

(advise local-interface-ip-address
 (or *passive-interface-address* (:do-it))
 :when :around :name override-local-interface-ip-address) 

Here is a new open-tcp-listener function that demonstrates the patch - call 
with :loopback as host:

(defun open-tcp-listener (host port &rest rest)
  "Open a passive tcp stream listening at the port, with same keyword arguments as open-tcp-stream. 
Use NIL for host to allow public access and :loopback to only allow connections 
from the computer."
  (declare (dynamic-extent rest))
  (let ((*passive-interface-address* 
         (etypecase host
           (null NIL)
           ((eql :loopback) #.(ccl::get-host-address "127.0.0.1"))
           ((unsigned-byte 32) host)
           (string (ccl::get-host-address host)))))
    (apply #'ccl::open-tcp-stream NIL (or port #$kOTAnyInetAddress) rest)))

Original issue reported on code.google.com by terje.norderhaug on 2 Jan 2010 at 10:34