Code Comments

Programming Forum and web based access to our favorite programming groups.
For Programmers: Free Programming Magazines
Registration is free! Edit your profileCalendarFind other membersFrequently Asked QuestionsSearch -> 
Post New Thread











Thread
Author

Re: Problem with IO::Socket [... on Mac OS X]
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'

Report this thread to moderator Post Follow-up to this message
Old Post
Martin Kissner
02-17-05 02:00 AM


Re: Problem with IO::Socket [... on Mac OS X]
Martin 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

Report this thread to moderator Post Follow-up to this message
Old Post
Anno Siegel
02-17-05 02:01 PM


Re: Problem with IO::Socket [... on Mac OS X]
Anno 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'

Report this thread to moderator Post Follow-up to this message
Old Post
Martin Kissner
02-17-05 09:03 PM


Re: Problem with IO::Socket [... on Mac OS X]
Anno 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'

Report this thread to moderator Post Follow-up to this message
Old Post
Martin Kissner
02-20-05 08:56 PM


Re: Problem with IO::Socket [... on Mac OS X]
Martin 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

Report this thread to moderator Post Follow-up to this message
Old Post
Anno Siegel
02-21-05 01:57 PM


Sponsored Links




Last Thread Next Thread Next
Search this forum -> 
Post New Thread

PERL Miscellaneous archive

Show a Printable Version Send to friend Email This Page to Someone! subscribe to this thread Receive updates to this thread
Computer Consultants
Programming Jobs
Visual Basic Controls
SQL Server Programming
Webservices
Java Security
Visual Studio
C# Programming
Visual J++
Software engineering
Open source Software
Perl Programming
PHP Programming
ASP Programming
ASP .NET Programming
Visual Basic Programming
Windows Scripting Host
Java Programming
Java Help
Java Beans
VBScript
Cobol
MAC Applications
Unix Programming
Forum Jump:
All times are GMT. The time now is 03:52 PM.

 

Programming forum archive

Copyrights CodeComments.com 2004 - 2006

Powered by vBulletin Copyright 2000-2006 Jelsoft Enterprises Limited.