devinci has asked for the wisdom of the Perl Monks concerning the following question:

I'm basically writing a simple socket server and client in Perl, and could not find documentation on the client end after making a connect() call, it is obvious a port number is automatically selected and used on the client side to connect to a peer host:peer port. I want to write out to a log, what client source port was used to connect out; but couldn't find info on a way to get this information in perl. Basically I would like to log this info like: print FILE time . " Connecting from 192.168.0.1:42244 to 192.168.0.10:443\n"; Does anyone know how to pull client-side source IP and source port from a client side socket in Perl ?
  • Comment on From either Socket or IO::Socket::INET, how to get local port for clients?

Replies are listed 'Best First'.
Re: From either Socket or IO::Socket::INET, how to get local port for clients?
by kcott (Archbishop) on Jun 05, 2013 at 22:10 UTC
      I went through them, and tried a few calls without success. They seem to focus more on server-end where you set the local port to bind, but prior to listen() and accept(). There is no where in the documentation that talks about pulling the local port number that client uses when it calls connect(). Though it seems connect() automatically binds to a randomly provided local port, and make a connection to SERVER socket specified automatically. On the SERVER end, I can easily pull both the source port and target ports after an accept(). I'm thinking about having the server tell the client what source port it was using, but it defeats the purpose of possible troubleshooting the network (via wireshark, or tcpdump, etc), if there was a problem with the connect().