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

I have this snippet of code that seems to function well.
use IO::Socket; my $server = IO::Socket::INET->new( PeerAddr = 'peer's ip address', PeerPort = 8090, Proto = 'tcp' ) or die "Can't create client socket: $!";
What would would like to know is which IP address/interface the connection was created on? I have a few systems that have several networks connected to them. I want to print out the local interface/ip address that was used to create the connection, something like eth0-192.168.10.5 was able to open socket to 'peer's ip address'. I have poked around the socket perldoc and did not see what I was looking for, I figured I was being blind.. Thanks in advance,

Replies are listed 'Best First'.
Re: Socket Source interface
by jbert (Priest) on Jul 04, 2007 at 16:05 UTC
    I think the system-call functionality you want is getsockname (as opposed to getpeername which returns the IP and port of the remote end).

    It looks like this is implemented in IO::Socket as sockname, so see what you get back from:

    $server->sockname();
    Good luck.
Re: Socket Source interface
by xiaoyafeng (Deacon) on Jul 04, 2007 at 13:56 UTC
    Welcome to Perl!
    for your question,I thinks/=/=>/g might help you ;)

    I am trying to improve my English skills, if you see a mistake please feel free to reply or /msg me a correction