in reply to LWP and LocalIP/LocalPort

This is actually really easy to achieve and I'm surprised that this solution hasn't been forwarded already ...

@LWP::Protocol::http::EXTRA_SOCK_OPTS = ( LocalAddr => '1.2.3.4', Loca +lPort => '8080' );
These parameters are passed to the IO::Socket::INET class which is created within the LWP::Protocol::http object that is used to fetch HTTP pages. From this module ...

local($^W) = 0; # IO::Socket::INET can be noisy my $sock = $self->socket_class->new(PeerAddr => $host, PeerPort => $port, Proto => 'tcp', Timeout => $timeout, KeepAlive => !!$conn_cache, SendTE => 1, $self->_extra_sock_opts($host, $po +rt), );

This allows for any of the default options of the IO::Socket::INET class to be re-defined as required.

 

perl -e 'print+unpack("N",pack("B32","00000000000000000000000111010001")),"\n"'

Replies are listed 'Best First'.
Re: Re: LWP and LocalIP/LocalPort
by jj808 (Hermit) on Oct 16, 2002 at 14:26 UTC
    This was actually the first thing I thought of. But then I read the documentation for IO::Socket::INET, which states:
    In addition to the key-value pairs accepted by IO::Socket, IO::Socket::INET provides.
    PeerAddr Remote host address <hostname>[:<port>] PeerHost Synonym for PeerAddr PeerPort Remote port or service <service>[(<no>)] | <no> LocalAddr Local host bind address hostname[:port] LocalHost Synonym for LocalAddr LocalPort Local host bind port <service>[(<no>)] | <no> ...
    So what is the difference between specifying the host and port as separate options, or using a string like '1.2.3.4:8080' (as in jk2addict's original example] as the argument to LocalAddr?

    JJ