[32348] in Perl-Users-Digest
Perl-Users Digest, Issue: 3615 Volume: 11
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Tue Feb 21 03:09:21 2012
Date: Tue, 21 Feb 2012 00:09:03 -0800 (PST)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Perl-Users Digest Tue, 21 Feb 2012 Volume: 11 Number: 3615
Today's topics:
Can't connect to 'localhost' in IO::Socket <w.c.humann@arcor.de>
Re: Can't connect to 'localhost' in IO::Socket <ben@morrow.me.uk>
Re: Can't connect to 'localhost' in IO::Socket <w.c.humann@arcor.de>
Re: Can't connect to 'localhost' in IO::Socket <rweikusat@mssgmbh.com>
Re: Can't connect to 'localhost' in IO::Socket <w.c.humann@arcor.de>
Re: Can't connect to 'localhost' in IO::Socket <rweikusat@mssgmbh.com>
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Mon, 20 Feb 2012 02:46:41 -0800 (PST)
From: Wolfram Humann <w.c.humann@arcor.de>
Subject: Can't connect to 'localhost' in IO::Socket
Message-Id: <6bf978c9-cd32-4ff2-a328-b798d3f9637d@m2g2000vbc.googlegroups.com>
I'm using RPC::Lite to exchange data between two programs. I noticed
that when I run the client on the same machine as the server, I am
able to connect using the machine's name but not 'localhost'.
RPC::Lite uses IO::Socket and I found that I see the same problem with
the following command-line:
mymachine:/tmp> perl -MData::Dump=pp -MIO::Socket -E'$sock =
IO::Socket::INET->new( Proto => "tcp", PeerAddr => "mymachine",
PeerPort => 1700); pp $sock'
do {
require Symbol;
my $a = bless(Symbol::gensym(), "IO::Socket::INET");
*{$a} = {
io_socket_domain => 2,
io_socket_proto => 6,
io_socket_timeout => undef,
io_socket_type => 1,
};
$a;
}
mymachine:/tmp> perl -MData::Dump=pp -MIO::Socket -E'$sock =
IO::Socket::INET->new( Proto => "tcp", PeerAddr => "localhost",
PeerPort => 1700); pp $sock'
undef
mymachine:/tmp> perl -MData::Dump=pp -MIO::Socket -E'$sock =
IO::Socket::INET->new( Proto => "tcp", PeerAddr => "127.0.0.1",
PeerPort => 1700); pp $sock'
undef
Any idea why this is the case or how to further debug?
Thanks,
Wolfram
------------------------------
Date: Mon, 20 Feb 2012 11:51:47 +0000
From: Ben Morrow <ben@morrow.me.uk>
Subject: Re: Can't connect to 'localhost' in IO::Socket
Message-Id: <jno919-i982.ln1@anubis.morrow.me.uk>
Quoth Wolfram Humann <w.c.humann@arcor.de>:
> I'm using RPC::Lite to exchange data between two programs. I noticed
> that when I run the client on the same machine as the server, I am
> able to connect using the machine's name but not 'localhost'.
> RPC::Lite uses IO::Socket and I found that I see the same problem with
> the following command-line:
<snippety>
>
> Any idea why this is the case or how to further debug?
You haven't shown us how the listening socket was created.
'localhost' (usually :) ) resolves to 127.0.0.1, whereas your machine
name will resolve to some other IP address(es) used by your machine. A
socket that's only listening on one of those addresses won't receive
connections addressed to the other(s).
If you don't supply a LocalAddr parameter, a listening IO::Socket::INET
will bind to 0.0.0.0 (sometimes called INADDR_ANY), which is a special
magic address meaning 'accept connections destined to this port on any
local address'. If you do supply LocalAddr, though, it will bind to the
address you supply, which means it won't accept connections to any other
address.
On most systems, you can use netstat(1) to see what addresses your
sockets are actually bound to. See your system documentation.
Ben
------------------------------
Date: Mon, 20 Feb 2012 05:14:17 -0800 (PST)
From: Wolfram Humann <w.c.humann@arcor.de>
Subject: Re: Can't connect to 'localhost' in IO::Socket
Message-Id: <620f7dc4-322c-4d2d-a0df-9eb2574f46ad@i2g2000vbv.googlegroups.com>
On 20 Feb., 12:51, Ben Morrow <b...@morrow.me.uk> wrote:
> You haven't shown us how the listening socket was created.
>
> 'localhost' (usually :) ) resolves to 127.0.0.1, whereas your machine
> name will resolve to some other IP address(es) used by your machine. A
> socket that's only listening on one of those addresses won't receive
> connections addressed to the other(s).
Ah, good to know. I had a suspicion that this might be not so much a
perl issue but a problem of my shallow understanding of TCP.
> If you don't supply a LocalAddr parameter, a listening IO::Socket::INET
> will bind to 0.0.0.0 (sometimes called INADDR_ANY), which is a special
> magic address meaning 'accept connections destined to this port on any
> local address'. If you do supply LocalAddr, though, it will bind to the
> address you supply, which means it won't accept connections to any other
> address.
So I expanded my RPC::Lite::Server call to
RPC::Lite::Server->new({ Transports => ['TCP:Port=1700,Host=' .
hostname(), 'TCP:Port=1700,Host=localhost'] })
and voila, it works.
> On most systems, you can use netstat(1) to see what addresses your
> sockets are actually bound to. See your system documentation.
Maybe netstat is another thing I don't know well enough, but grep-ing
netstat's output for the port-number, I could only see it once the
connection was established but not while I only had the server waiting
for a client to connect.
Problem solved -- Thank you, Ben!
Wolfram
------------------------------
Date: Mon, 20 Feb 2012 13:55:33 +0000
From: Rainer Weikusat <rweikusat@mssgmbh.com>
Subject: Re: Can't connect to 'localhost' in IO::Socket
Message-Id: <871uppy5gq.fsf@sapphire.mobileactivedefense.com>
Wolfram Humann <w.c.humann@arcor.de> writes:
[...]
>> If you don't supply a LocalAddr parameter, a listening IO::Socket::INET
>> will bind to 0.0.0.0 (sometimes called INADDR_ANY), which is a special
>> magic address meaning 'accept connections destined to this port on any
>> local address'. If you do supply LocalAddr, though, it will bind to the
>> address you supply, which means it won't accept connections to any other
>> address.
>
> So I expanded my RPC::Lite::Server call to
> RPC::Lite::Server->new({ Transports => ['TCP:Port=1700,Host=' .
> hostname(), 'TCP:Port=1700,Host=localhost'] })
> and voila, it works.
It is usually more sensible to bind to the wildcard address,
especially considering that IP addresses are usually per-host and not
per-interface, meaning, by default, any address that's configured on
any public interface of some computer will reachable via all other
public interfaces (so-called 'weak end-system').
>> On most systems, you can use netstat(1) to see what addresses your
>> sockets are actually bound to. See your system documentation.
> Maybe netstat is another thing I don't know well enough, but grep-ing
> netstat's output for the port-number, I could only see it once the
> connection was established but not while I only had the server waiting
> for a client to connect.
By default, netstat doesn't display listening sockets. It can be
instructed to do wo with either the -l ('listening') or -a ('all')
flags.
------------------------------
Date: Mon, 20 Feb 2012 06:34:23 -0800 (PST)
From: Wolfram Humann <w.c.humann@arcor.de>
Subject: Re: Can't connect to 'localhost' in IO::Socket
Message-Id: <2dff26f5-180d-4c34-9e47-cbbf04751b5e@w19g2000vbe.googlegroups.com>
On 20 Feb., 14:55, Rainer Weikusat <rweiku...@mssgmbh.com> wrote:
> It is usually more sensible to bind to the wildcard address,
> especially considering that IP addresses are usually per-host and not
> per-interface, meaning, by default, any address that's configured on
> any public interface of some computer will reachable via all other
> public interfaces (so-called 'weak end-system').
So I would simply say Transports => ['TCP:Port=1700,Host=']
with the corresponding netstat (thanks for the -l / -a tip!) reply:
tcp 0 0 *:1700
*:* LISTEN
Is that what you meant? Does this wildcard create any security issues
(exceeding those potentially present before by providing *any* TCP-
accessible service)?
Regards,
Wolfram
------------------------------
Date: Mon, 20 Feb 2012 15:17:30 +0000
From: Rainer Weikusat <rweikusat@mssgmbh.com>
Subject: Re: Can't connect to 'localhost' in IO::Socket
Message-Id: <87sji5wn3p.fsf@sapphire.mobileactivedefense.com>
Wolfram Humann <w.c.humann@arcor.de> writes:
> On 20 Feb., 14:55, Rainer Weikusat <rweiku...@mssgmbh.com> wrote:
>> It is usually more sensible to bind to the wildcard address,
>> especially considering that IP addresses are usually per-host and not
>> per-interface, meaning, by default, any address that's configured on
>> any public interface of some computer will reachable via all other
>> public interfaces (so-called 'weak end-system').
>
> So I would simply say Transports => ['TCP:Port=1700,Host=']
>
> with the corresponding netstat (thanks for the -l / -a tip!) reply:
>
> tcp 0 0 *:1700
> *:* LISTEN
>
> Is that what you meant? Does this wildcard create any security issues
> (exceeding those potentially present before by providing *any* TCP-
> accessible service)?
Usually no if the service is supposed to listening on a 'public'
address (here supposed to mean anything except 127.0.0.1) anyway, see my
remark about 'weak end-systems' above. Insofar desired, working
source-based access control can either be provided by the application
(by immediately closing connections from 'unwelcome' source addresses
after accepting them) or with the help of some kind of host- or
gateway-based packet filter.
------------------------------
Date: 6 Apr 2001 21:33:47 GMT (Last modified)
From: Perl-Users-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin)
Subject: Digest Administrivia (Last modified: 6 Apr 01)
Message-Id: <null>
Administrivia:
To submit articles to comp.lang.perl.announce, send your article to
clpa@perl.com.
Back issues are available via anonymous ftp from
ftp://cil-www.oce.orst.edu/pub/perl/old-digests.
#For other requests pertaining to the digest, send mail to
#perl-users-request@ruby.oce.orst.edu. Do not waste your time or mine
#sending perl questions to the -request address, I don't have time to
#answer them even if I did know the answer.
------------------------------
End of Perl-Users Digest V11 Issue 3615
***************************************