Consider the following snippet of a Perl script:
use IO::Socket;
# ...
my $sock = IO::Socket::INET->new(
PeerAddr => $host, # e.g. "google.com"
PeerPort => $port, # e.g. 80
Proto => 'tcp'
);
die("no socket: $!") unless $sock;
# ...
Everything works as expected under normal conditions but when then host system's internet connection is inactive the "sock" variable is empty and $!
has the message "Invalid argument".
Am I using the INET constructor inappropriately or is this the expected behavior? If the latter, is there a way to differentiate between a "network interface inactive" error and a genuine invalid argument to the constructor method?