[gambit-list] extracting information from socket ports

Marc Feeley feeley at iro.umontreal.ca
Sat Oct 29 22:02:50 EDT 2005


On 24-Oct-05, at 6:58 AM, david rush wrote:

> Maybe I'm just missing it in the documentation, but how can I extract
> some of the core networking information from a tcp-port returned from
> reading a port opened with open-tcp-server? I'm hoping to extract at
> least the IP address and port number of the inbound connection for
> authorization purposes.
>
> david rush

Beta 15 does not have predefined procedures to do this.  I've added  
the procedures

    (tcp-client-self-socket-info tcp-client-port)
    (tcp-client-peer-socket-info tcp-client-port)

to get information on the two ends of the socket pair of the  
connection.  Here's a sample use:

(define p
   (open-tcp-client
    (list server-address: "www.iro.umontreal.ca"
          port-number: 80)))

(define ssi (tcp-client-self-socket-info p))
(define psi (tcp-client-peer-socket-info p))

(pp (socket-info-port-number ssi))
(pp (socket-info-address ssi))

(pp (socket-info-port-number psi))
(pp (socket-info-address psi))

(pp ssi)
(pp psi)

(pp p)

and the output:

51923
#u8(192 168 0 102)
80
#u8(132 204 5 67)
#<socket-info #2 family: 2 port-number: 51923 address: #u8(192 168 0  
102)>
#<socket-info #3 family: 2 port-number: 80 address: #u8(132 204 5 67)>
#<input-output-port #4 (tcp-client "www.iro.umontreal.ca" 80)>




More information about the Gambit-list mailing list