[tpm] IO::Socket::INET listening on the 2nd ip address

Antonio Sun antoniosun at lavabit.com
Tue Feb 8 10:04:16 PST 2011


I'll get:


On Tue, Feb 8, 2011 at 11:22 AM, Uri Guttman <uri at stemsystems.com> wrote:

> >>>>> "AS" == Antonio Sun <antoniosun at lavabit.com> writes:
>
>  AS>  $sock = new IO::Socket::INET (  LocalHost => '0.0.0.0',
>  AS>                                 LocalPort => '80',
>  AS>                                 Proto => 'tcp',
>  AS>                                 Listen => 30,
>  AS>                                 Reuse => 1);
>
> don't use the indirect call of new Class. make it Class->new(). . .


OK, will change that once script is working.

 AS> which will fail because my port 80 on localhost is used by web server.
>  AS> How can I change the code to listen on the 2nd ip address?
>
>  AS> I.e., my current IP address is 192.168.0.100, it is
>  AS> also accessible at 192.168.0.101. I want that
>  AS> visiting 192.168.0.100 will land to my normal web server, while
>  AS> visiting 192.168.0.101 will be handled by the code above.
>
> kind of obvious. you set localhost to the ip you want. that binds the
> listen socket to that and the port pair which is unique on your box.
>

Sorry, I still can't figure it out, even it is so obvious to you:

If I use,

$sock = new IO::Socket::INET (  LocalHost => '0.0.0.0',
                                LocalPort => '80',
                                Proto => 'tcp',
                                Listen => 30,
                                Reuse => 1);

if (!defined($sock)) {
        print "error : cannot bind : $! exit\n";
        exit(1);
}

I'll get:

 error : cannot bind : Address already in use exit

I assume it fails because my port 80 is currently used by web server.

If I use

 $sock = new IO::Socket::INET (  LocalHost => '192.168.0.101',

I still get

 error : cannot bind : Address already in use exit

If I use

 $sock = new IO::Socket::INET (  LocalHost => '192.168.0.104',

I'll get:

 error : cannot bind : Cannot assign requested address exit

Please help.

thanks
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.pm.org/pipermail/toronto-pm/attachments/20110208/fc31d911/attachment.html>


More information about the toronto-pm mailing list