69a7c4
From 5a3f94a3f0e21d8e685ede4e851a318578a2151f Mon Sep 17 00:00:00 2001
69a7c4
From: Jitka Plesnikova <jplesnik@redhat.com>
69a7c4
Date: Thu, 17 Jun 2021 11:12:30 +0200
69a7c4
Subject: [PATCH 1/2] carp, not croak on most name lookup failures
69a7c4
69a7c4
See RT #124830, a regression.
69a7c4
Return undef instead.
69a7c4
69a7c4
Backported from Net-Ping 2.67
69a7c4
---
69a7c4
 dist/Net-Ping/lib/Net/Ping.pm | 24 ++++++++++++------------
69a7c4
 1 file changed, 12 insertions(+), 12 deletions(-)
69a7c4
69a7c4
diff --git a/dist/Net-Ping/lib/Net/Ping.pm b/dist/Net-Ping/lib/Net/Ping.pm
69a7c4
index 13cbe81..9e2497c 100644
69a7c4
--- a/dist/Net-Ping/lib/Net/Ping.pm
69a7c4
+++ b/dist/Net-Ping/lib/Net/Ping.pm
69a7c4
@@ -144,7 +144,7 @@ sub new
69a7c4
   if ($self->{'host'}) {
69a7c4
     my $host = $self->{'host'};
69a7c4
     my $ip = _resolv($host)
69a7c4
-      or croak("could not resolve host $host");
69a7c4
+      or carp("could not resolve host $host");
69a7c4
     $self->{host} = $ip;
69a7c4
     $self->{family} = $ip->{family};
69a7c4
   }
69a7c4
@@ -152,7 +152,7 @@ sub new
69a7c4
   if ($self->{bind}) {
69a7c4
     my $addr = $self->{bind};
69a7c4
     my $ip = _resolv($addr)
69a7c4
-      or croak("could not resolve local addr $addr");
69a7c4
+      or carp("could not resolve local addr $addr");
69a7c4
     $self->{local_addr} = $ip;
69a7c4
   } else {
69a7c4
     $self->{local_addr} = undef;              # Don't bind by default
69a7c4
@@ -323,7 +323,7 @@ sub bind
69a7c4
     ($self->{proto} eq "udp" || $self->{proto} eq "icmp");
69a7c4
 
69a7c4
   $ip = $self->_resolv($local_addr);
69a7c4
-  croak("nonexistent local address $local_addr") unless defined($ip);
69a7c4
+  carp("nonexistent local address $local_addr") unless defined($ip);
69a7c4
   $self->{local_addr} = $ip;
69a7c4
 
69a7c4
   if (($self->{proto} ne "udp") && 
69a7c4
@@ -1129,13 +1129,14 @@ sub open
69a7c4
     $self->{family_local} = $self->{family};
69a7c4
   }
69a7c4
 
69a7c4
-  $ip = $self->_resolv($host);
69a7c4
   $timeout = $self->{timeout} unless $timeout;
69a7c4
+  $ip = $self->_resolv($host);
69a7c4
 
69a7c4
-  if($self->{proto} eq "stream") {
69a7c4
-    if(defined($self->{fh}->fileno())) {
69a7c4
+  if ($self->{proto} eq "stream") {
69a7c4
+    if (defined($self->{fh}->fileno())) {
69a7c4
       croak("socket is already open");
69a7c4
     } else {
69a7c4
+      return () unless $ip;
69a7c4
       $self->tcp_connect($ip, $timeout);
69a7c4
     }
69a7c4
   }
69a7c4
@@ -1851,12 +1852,11 @@ sub _resolv {
69a7c4
         }
69a7c4
         return \%h
69a7c4
       } else {
69a7c4
-        croak("getnameinfo($getaddr[0]->{addr}) failed - $err");
69a7c4
+        carp("getnameinfo($getaddr[0]->{addr}) failed - $err");
69a7c4
       }
69a7c4
     } else {
69a7c4
-      my $error = sprintf "getaddrinfo($h{host},,%s) failed - $err",
69a7c4
-                  ($family == AF_INET) ? "AF_INET" : "AF_INET6";
69a7c4
-      croak("$error");
69a7c4
+      warn(sprintf("getaddrinfo($h{host},,%s) failed - $err",
69a7c4
+                    $family == AF_INET ? "AF_INET" : "AF_INET6"));
69a7c4
     }
69a7c4
   # old way
69a7c4
   } else {
69a7c4
@@ -1871,7 +1871,7 @@ sub _resolv {
69a7c4
       $h{family} = AF_INET;
69a7c4
       return \%h
69a7c4
     } else {
69a7c4
-      croak("gethostbyname($h{host}) failed - $^E");
69a7c4
+      carp("gethostbyname($h{host}) failed - $^E");
69a7c4
     }
69a7c4
   }
69a7c4
 }
69a7c4
@@ -1913,7 +1913,7 @@ sub _inet_ntoa {
69a7c4
     if (defined($address)) {
69a7c4
       $ret = $address;
69a7c4
     } else {
69a7c4
-      croak("getnameinfo($addr) failed - $err");
69a7c4
+      carp("getnameinfo($addr) failed - $err");
69a7c4
     }
69a7c4
   } else {
69a7c4
     $ret = inet_ntoa($addr)
69a7c4
-- 
69a7c4
2.31.1
69a7c4