Code Comments
Programming Forum and web based access to our favorite programming groups.A. Sinan Unur wrote : > Martin Kissner <news@chaos-net.de> wrote in > news:slrnd178eu.1hq.news@maki.homeunix.net: > > You will need to give some more information regarding the system on which > you are testing this in a clear and concise way. Of course. I should have done in the first place. % uname -msr Darwin 7.8.0 Power Macintosh # which is Mac OS X % perl -v This is perl, v5.8.1-RC3 built for darwin-thread-multi-2level (with 1 registered patch, see perl -V for more detail) > Now, you can check if perl is able to do the mapping from service names > to port addresses on your system by running this script (from Perl docs): Thank you for the script. % ./test_services.pl smtp port for smtp is 25, aliases are % ./test_services.pl http port for http is 80, aliases are www www-http works optimally and makes it still more surprising that the script doesn't -- perl -e 'print 7.74.117.115.116.11.32.13.97.110.111.116.104.101.114.11 .32.13.112.101.114.108.11.32.13.104.97.99.107.101.114.10.7'
Post Follow-up to this messageMartin Kissner <news@chaos-net.de> wrote in comp.lang.perl.misc:
> A. Sinan Unur wrote :
>
> Of course.
> I should have done in the first place.
>
> % uname -msr
> Darwin 7.8.0 Power Macintosh
> # which is Mac OS X
Something is fishy on Darwin. I also see it hang when the service is
given by name and reply as expected when given by port number. However,
just *calling* getservbyname() before opening the socket makes it work
with a name too.
use IO::Socket;
my $server = shift;
if ( my ( $port) = $server =~ /:(.*)/ ) {
# just call it
getservbyname( $port, 'tcp') or die "getservbyname( $port)";
}
print "Trying $server\n";
my $fh = IO::Socket::INET->new( $server) or die $!;
my $line = <$fh>;
print $line;
__END__
This gives the expected reply from "mail.hotmail.com:smtp". Comment out
the call to getservbyname() and it doesn't.
I'm not sure how Darwin deals with getservbyname(). It may use some
netinfo devilry instead of /etc/services. The man page is ominously
missing.
Anno
Post Follow-up to this messageAnno Siegel wrote :
> Something is fishy on Darwin.
I guess it is.
I will try this on FreeBSD as soon as possible.
> I also see it hang when the service is
> given by name and reply as expected when given by port number. However,
> just *calling* getservbyname() before opening the socket makes it work
> with a name too.
>
> use IO::Socket;
>
> my $server = shift;
>
> if ( my ( $port) = $server =~ /:(.*)/ ) {
> # just call it
> getservbyname( $port, 'tcp') or die "getservbyname( $port)";
> }
>
> print "Trying $server\n";
> my $fh = IO::Socket::INET->new( $server) or die $!;
> my $line = <$fh>;
> print $line;
>
Thank you for this code example. It works for me, too and examples like
this one expand my view since I am not so experienced in Perl
programming.
> This gives the expected reply from "mail.hotmail.com:smtp". Comment out
> the call to getservbyname() and it doesn't.
>
> I'm not sure how Darwin deals with getservbyname(). It may use some
> netinfo devilry instead of /etc/services. The man page is ominously
> missing.
Te documentation to Darwin sometimes is a drag. It has become better
with Panther, but it's still not goos enough.
However, Darwin does use /etc/services.
I tried by simply changing the name of a service in /etc/services.
--
perl -e 'print 7.74.117.115.116.11.32.13.97.110.111.116.104.101.114.11
.32.13.112.101.114.108.11.32.13.104.97.99.107.101.114.10.7'
Post Follow-up to this messageAnno Siegel wrote : > Something is fishy on Darwin. I also see it hang when the service is > given by name and reply as expected when given by port number. However, > just *calling* getservbyname() before opening the socket makes it work > with a name too. After I had proved that servicenames can be resolved by Perl on Mac OS X with the function 'getservbyname()' I was interested if I could find out how IO::Socket::INET gets the servicenames and how this might be different from 'getservbyname()'. As far as I can see IO::Socket::INET uses 'getservbyname()'. In Version 1.26 of IO::Socket::INET the conversion is done in line 58/59 of 'INET.pm'. After all I tried the script once again without making any changes and to my very great surprise it ran flawlessly with servicenames and with portnumbers. If Anno had not seen it hang when servicenames were given, I'd probably doubted my mental health ;-). I report this not because I expect that someone could explain this but to give some final feedback to everybody who had to helped. Best regards Martin -- perl -e 'print 7.74.117.115.116.11.32.13.97.110.111.116.104.101.114.11 .32.13.112.101.114.108.11.32.13.104.97.99.107.101.114.10.7'
Post Follow-up to this messageMartin Kissner <news@chaos-net.de> wrote in comp.lang.perl.misc: > Anno Siegel wrote : > [...] > After all I tried the script once again without making any changes and > to my very great surprise it ran flawlessly with servicenames and with > portnumbers. > If Anno had not seen it hang when servicenames were given, I'd probably > doubted my mental health ;-). I've seen that too. It wasn't reproducible, so I dismissed it for the time being. Anno
Post Follow-up to this message
Show a Printable Version
Email This Page to Someone!
Receive updates to this thread
Powered by vBulletin
Copyright 2000-2006 Jelsoft Enterprises Limited.