Subject: | Handle getprotobyn{ame,umber} not being available |
If perl is built with -Ud_getprotobyname -Ud_getprotobynumber, or if, like in Android, the OS lacks those functions, using them will cause a runtime exception saying that they aren't implemented.
The patch below protects the calls with an eval {}, which works around the issue. Alternatively, this could be implemented as if ($Config{d_getprotobyname}) { getprotobyname() }
(patch is against blead)
diff --git a/dist/IO/lib/IO/Socket/INET.pm b/dist/IO/lib/IO/Socket/INET.pm
index 4fa6a29..07f2b3f 100644
--- a/dist/IO/lib/IO/Socket/INET.pm
+++ b/dist/IO/lib/IO/Socket/INET.pm
@@ -50,7 +50,7 @@ sub _get_proto_number {
return undef unless defined $name;
return $proto_number{$name} if exists $proto_number{$name};
- my @proto = getprotobyname($name);
+ my @proto = eval { getprotobyname($name) };
return undef unless @proto;
_cache_proto(@proto);
@@ -62,7 +62,7 @@ sub _get_proto_name {
return undef unless defined $num;
return $proto_name{$num} if exists $proto_name{$num};
- my @proto = getprotobynumber($num);
+ my @proto = eval { getprotobynumber($num) };
return undef unless @proto;
_cache_proto(@proto);