From: brandon on
I have been having fits getting meaningful errno/perror values out of
Perl from Socket->new() and I am hoping someone here might know what
is going on. The errno/perror values seem to work fine on my Linux
servers but AIX, HP, and Sun are not giving me a correct failure
value. I have remote servers set up so that I can get various types of
failures (no daemon, firewall blocking, no route, etc.) and I can test
all these conditions with telnet to see what the perror string should
be, and my Linux servers match that.

It should be just a matter of getting extern int errno in the
interpreter when I ask for it with $!, no?

Here is my sample code :

------------------------------------------------

#!/usr/bin/perl

use IO::Socket;
use strict;

my($server_ip, $server_port) = ("172.16.18.96", "10");
my($timeout) = 5;
my($firsterr) = "";
my($socket);

print "\$! = $!\n";
$! = 0;
print "\$! = $!\n";

$socket = IO::Socket::INET->new(
Proto => "tcp",
PeerAddr => $server_ip,
PeerPort => $server_port,
Timeout => $timeout
);

if ( $firsterr eq "" ) { $firsterr = $!; }
print "\$! = $!\n";

if ( $socket ) {
close $socket;
print " OK : Port $server_port is OPEN\n";

else {
# Other error detected
print " Use OS problem determination procedures to determine
the \n";
print " source of the perror (errno) string : \n";
print " \t $firsterr\n";
}

exit 0;


----------------------

In this particular case (IP/port) on my subnet, this server exists
and has no process listening on the port so I fully expect to get
(some OS specific form of) a perror string : "connection refused".
This is what I get on all the OS's when I telnet to this server and
port, and is also what I get from this script on Linux. For the other
OS's I am getting errno/perror values that apparently do not have
anything to do with the fact there is no listening process :

OS / Ver perl -v result

RH WS2u1 v5.6.1 "Connection refused"
RH WS3u5 v5.8.0 "Connection refused"
RH AS4u3 v5.8.5 "Connection refused"
AIX 5.3 v5.8.0 "A system call received a parameter that is
not valid."
AIX 5.3 v5.8.2 "A system call received a parameter that is not
valid."
AIX 5.1 v5.6.0 "A system call received aparameter that is not
valid."
AIX 5.2 v5.8.0 "A system call received aparameter that is not
valid."
AIX 4.3 v5.005_03 "A file descriptor does not refer to
an open file."
AIX 4.3 v5.005_03 "A file descriptor does not refer to
an open file."
HP 11.11 v5.8.0 "Invalid argument"
HP 11.00 v4.0 <problem w/ use>
HP 10.20 v4.0 <problem w/ use>
Sun 5.7 v5.8.5 "Connection refused"
Sun 5.8 v5.005_03 "Bad file number"
Sun 5.9 v5.6.1 "Connection refused"
Sun 5.10 v5.8.4 "Connection refused"

If I change nothing other than the IP and port values in the script
(to something that will allow a connection), I get a successful socket
creation. This is just an example of the script I am developing, the
original also writes to and reads from the socket, and that is working
splendidly on all the test boxes. I need to use the errorno/perror to
point the user towards what needs to be checked on the host, client,
or network if there is a failure however.

Also, I have also noticed similar behavior opening ports sucessfully.
The above server had telnet running and I can open port 23
successfully but I get various inexplicable $! errors after the
new().

Thanks, Brandon
From: xhoster on
brandon <brandon.mayfield(a)att.net> wrote:
> I have been having fits getting meaningful errno/perror values out of
> Perl from Socket->new() and I am hoping someone here might know what
> is going on. The errno/perror values seem to work fine on my Linux
> servers but AIX, HP, and Sun are not giving me a correct failure
> value. I have remote servers set up so that I can get various types of
> failures (no daemon, firewall blocking, no route, etc.) and I can test
> all these conditions with telnet to see what the perror string should
> be, and my Linux servers match that.

After the "primary" error, IO::Socket might make more system calls
before it returns to your code. Those other system calls might set errno,
thus overwriting the previous value of $! set by the "primary" error.
Because of this, IO::Socket tries to set $@ to be the most meaningful error
message it can manage, considering the mishmash of system calls that are
going on behind the scenes. You should look in $@ instead of or in
addition to $!. (I'm saying this will solve the problem, only that it is
the first thing I'd try.)


....
>
> Also, I have also noticed similar behavior opening ports sucessfully.
> The above server had telnet running and I can open port 23
> successfully but I get various inexplicable $! errors after the
> new().

After a successful system call, $! contains whatever it contained
*before* that system call. Looking in $! is meaningful only after
an unsuccessful system call.

Xho

--
-------------------- http://NewsReader.Com/ --------------------
The costs of publication of this article were defrayed in part by the
payment of page charges. This article must therefore be hereby marked
advertisement in accordance with 18 U.S.C. Section 1734 solely to indicate
this fact.
From: brandon on
On Jan 16, 3:00 pm, xhos...(a)gmail.com wrote:
> brandon <brandon.mayfi...(a)att.net> wrote:
> >  I have been having fits getting meaningful errno/perror values out of
> > Perl from Socket->new() and I am hoping someone here might know what
> > is going on. The errno/perror values seem to work fine on my Linux
> > servers but AIX, HP, and Sun are not giving me a correct failure
> > value. I have remote servers set up so that I can get various types of
> > failures (no daemon, firewall blocking, no route, etc.) and I can test
> > all these conditions with telnet to see what the perror string should
> > be, and my Linux servers match that.
>
> After the "primary" error, IO::Socket might make more system calls
> before it returns to your code.  Those other system calls might set errno,
> thus overwriting the previous value of $! set by the "primary" error.
> Because of this, IO::Socket tries to set $@ to be the most meaningful error
> message it can manage, considering the mishmash of system calls that are
> going on behind the scenes.  You should look in $@ instead of or in
> addition to $!.  (I'm saying this will solve the problem, only that it is
> the first thing I'd try.)
>
> ...

Thanks - I will definately try that.

>
>
>
> >  Also, I have also noticed similar behavior opening ports sucessfully.
> > The above server had telnet running and I can open port 23
> > successfully but I get various inexplicable $! errors after the
> > new().
>
> After a successful system call, $! contains whatever it contained
> *before* that system call.  Looking in $! is meaningful only after
> an unsuccessful system call.
>

Yes, and note from the code I did test it before and set it to '0'.

> Xho
>
> --
> --------------------http://NewsReader.Com/--------------------
> The costs of publication of this article were defrayed in part by the
> payment of page charges. This article must therefore be hereby marked
> advertisement in accordance with 18 U.S.C. Section 1734 solely to indicate
> this fact.

From: brandon on
On Jan 16, 3:00 pm, xhos...(a)gmail.com wrote:
> brandon <brandon.mayfi...(a)att.net> wrote:
> >  I have been having fits getting meaningful errno/perror values out of
> > Perl from Socket->new() and I am hoping someone here might know what
> > is going on. The errno/perror values seem to work fine on my Linux
> > servers but AIX, HP, and Sun are not giving me a correct failure
> > value. I have remote servers set up so that I can get various types of
> > failures (no daemon, firewall blocking, no route, etc.) and I can test
> > all these conditions with telnet to see what the perror string should
> > be, and my Linux servers match that.
>
> After the "primary" error, IO::Socket might make more system calls
> before it returns to your code.  Those other system calls might set errno,
> thus overwriting the previous value of $! set by the "primary" error.
> Because of this, IO::Socket tries to set $@ to be the most meaningful error
> message it can manage, considering the mishmash of system calls that are
> going on behind the scenes.  You should look in $@ instead of or in
> addition to $!.  (I'm saying this will solve the problem, only that it is
> the first thing I'd try.)
>

That results in :

# ./simple.pl
$! =
$! =
$! = A system call received a parameter that is not valid.
$@ = IO::Socket::INET: connect: A system call received a parameter
that is not valid.
Use OS problem determination procedures to determine the
source of the perror (errno) string :
A system call received a parameter that is not valid.
#
From: Uri Guttman on
>>>>> "b" == brandon <brandon.mayfield(a)att.net> writes:


>> After a successful system call, $! contains whatever it contained
>> *before* that system call. �Looking in $! is meaningful only after
>> an unsuccessful system call.
>>

b> Yes, and note from the code I did test it before and set it to '0'.

but you are missing the point. if the call to IO::Socket->new doesn't
return undef, there is NO point in checking out $! or $@. they will be
meaningless and may be set to some irrelevant value. i have never had to
clear those before making any lib or system calls. i only check them if
there is an indicator of an error. checking them directly is wrong in
almost every case. they could be changed due to some internal call that
is redone or worked around and yet your call will still have succeeded.

uri

--
Uri Guttman ------ uri(a)stemsystems.com -------- http://www.sysarch.com --
----- Perl Architecture, Development, Training, Support, Code Review ------
----------- Search or Offer Perl Jobs ----- http://jobs.perl.org ---------
--------- Gourmet Hot Cocoa Mix ---- http://bestfriendscocoa.com ---------