summaryrefslogtreecommitdiff
path: root/debian/patches/30_ping-Abort-on-sendto-error.patch
blob: af1d54b231ea24f38501c272dac1637262226166 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
From 8920f43f1957ac1f94850af19905896e19cbc8d3 Mon Sep 17 00:00:00 2001
From: Guillem Jover <guillem@hadrons.org>
Date: Tue, 27 Dec 2011 23:44:05 +0100
Subject: [PATCH] ping: Abort on sendto () error

* 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 99b5cd5..6e6f415 100644
--- a/ping/libping.c
+++ b/ping/libping.c
@@ -144,7 +144,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 b90ebec..db77f46 100644
--- a/ping/ping.c
+++ b/ping/ping.c
@@ -425,6 +425,7 @@ int
 send_echo (PING * ping)
 {
   int off = 0;
+  int rc;
 
   if (PING_TIMING (data_length))
     {
@@ -437,7 +438,12 @@ send_echo (PING * ping)
     ping_set_data (ping, data_buffer, off,
 		   data_length > PING_HEADER_LEN ?
 		   data_length - PING_HEADER_LEN : 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 6bb7618..a7425f4 100644
--- a/ping/ping6.c
+++ b/ping/ping6.c
@@ -381,6 +381,7 @@ static int
 send_echo (PING * ping)
 {
   int off = 0;
+  int rc;
 
   if (PING_TIMING (data_length))
     {
@@ -393,7 +394,12 @@ send_echo (PING * ping)
     ping_set_data (ping, data_buffer, off,
 		   data_length > PING_HEADER_LEN ?
 		   data_length - PING_HEADER_LEN : 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
@@ -784,7 +790,7 @@ ping_xmit (PING * p)
   i = sendto (p->ping_fd, (char *) p->ping_buffer, buflen, 0,
 	      (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.7.7.3