bug-inetutils
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[bug-inetutils] [PATCH] ping: Abort on sendto () error


From: Guillem Jover
Subject: [bug-inetutils] [PATCH] ping: Abort on sendto () error
Date: Mon, 14 Jan 2013 02:41:50 +0100
User-agent: Mutt/1.5.21 (2010-09-15)

* ping/libping.c (ping_xmit): Return -1 instead of calling perror () on
sendto () error.
* ping/ping6.c (ping_xmit): Likewise.
(send_echo): Error out instead of continuing sending packets.
* ping/ping.c (send_echo): Likewise.
---
 ping/libping.c |  2 +-
 ping/ping.c    |  8 +++++++-
 ping/ping6.c   | 10 ++++++++--
 3 files changed, 16 insertions(+), 4 deletions(-)

diff --git a/ping/libping.c b/ping/libping.c
index d269150..cd6c016 100644
--- a/ping/libping.c
+++ b/ping/libping.c
@@ -152,7 +152,7 @@ ping_xmit (PING * p)
   i = sendto (p->ping_fd, (char *) p->ping_buffer, buflen, 0,
              (struct sockaddr *) &p->ping_dest.ping_sockaddr, sizeof (struct 
sockaddr_in));
   if (i < 0)
-    perror ("ping: sendto");
+    return -1;
   else
     {
       p->ping_num_xmit++;
diff --git a/ping/ping.c b/ping/ping.c
index 9f51671..5da4d99 100644
--- a/ping/ping.c
+++ b/ping/ping.c
@@ -497,6 +497,7 @@ int
 send_echo (PING * ping)
 {
   size_t off = 0;
+  int rc;
 
   if (PING_TIMING (data_length))
     {
@@ -509,7 +510,12 @@ send_echo (PING * ping)
     ping_set_data (ping, data_buffer, off,
                   data_length > off ? data_length - off : data_length,
                   USE_IPV6);
-  return ping_xmit (ping);
+
+  rc = ping_xmit (ping);
+  if (rc < 0)
+    error (EXIT_FAILURE, errno, "sending packet");
+
+  return rc;
 }
 
 int
diff --git a/ping/ping6.c b/ping/ping6.c
index 2035ec2..ff3f4b7 100644
--- a/ping/ping6.c
+++ b/ping/ping6.c
@@ -384,6 +384,7 @@ static int
 send_echo (PING * ping)
 {
   size_t off = 0;
+  int rc;
 
   if (PING_TIMING (data_length))
     {
@@ -396,7 +397,12 @@ send_echo (PING * ping)
     ping_set_data (ping, data_buffer, off,
                   data_length > off ? data_length - off : data_length,
                   USE_IPV6);
-  return ping_xmit (ping);
+
+  rc = ping_xmit (ping);
+  if (rc < 0)
+    error (EXIT_FAILURE, errno, "sending packet");
+
+  return rc;
 }
 
 static int
@@ -796,7 +802,7 @@ ping_xmit (PING * p)
              (struct sockaddr *) &p->ping_dest.ping_sockaddr6,
              sizeof (p->ping_dest.ping_sockaddr6));
   if (i < 0)
-    perror ("ping: sendto");
+    return -1;
   else
     {
       p->ping_num_xmit++;
-- 
1.8.1




reply via email to

[Prev in Thread] Current Thread [Next in Thread]