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

I have a client that uses IO::Socket to create a socket to a server on another machine and exchange data on that socket. The server is fussy about what IP addresses it will accept connections from, and as the machine running the client uses IP aliasing I need to be able to set which IP address the client connection goes out on.

I can't find anything in the documentation for IO::Socket or in the man pages for the socket system calls that might help me, and all the web searches I have tried come up with nothing relevant.
Any ideas welcome.

The client code starts: my $sock = IO::Socket::INET->new("10.0.0.1:5015") or die "$!\n"; # Write and read messages to socket. The machine runs Linux (Debian Woody with 2.4.20 kernel) and Perl (5.6.1). This is the output of ifconfig: eth0 Link encap:Ethernet HWaddr 00:E0:81:B4:77:83 inet addr:10.0.0.148 Bcast:10.0.0.255 Mask:255.255.255.0 UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1 eth0:0 Link encap:Ethernet HWaddr 00:E0:81:B4:77:83 inet addr:10.0.0.149 Bcast:10.0.0.255 Mask:255.255.255.0 UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1

Replies are listed 'Best First'.
•Re: Setting IP address of client socket
by merlyn (Sage) on May 27, 2003 at 20:37 UTC
    I can't find anything in the documentation for IO::Socket or in the man pages

    And yet IO::Socket::INET says:

    LocalAddr Local host bind address hostname[:port +] LocalHost Synonym for LocalAddr LocalPort Local host bind port <service>[(<no +>)] | <no>
    Perhaps you missed that. Seems pretty clear to me.

    -- Randal L. Schwartz, Perl hacker
    Be sure to read my standard disclaimer if this is a reply.