Hi!

On Sun, 2011-11-13 at 19:03:00 +0100, Simon Josefsson wrote:
> > I think this should cause an error instead of:
> > 
> > rmh@bombadil:~$ ping 1
> > PING 1 (0.0.0.1): 56 data bytes
> 
> I believe this is intended and a feature that comes from using
> getaddrinfo.  Several programs behave the same -- you can use "short"
> numeric addresses like '1', '1.2', '4711' etc and it is translated into
> an IP address.
> 
> root@sid:~# ping 1.2
> PING 1.2 (1.0.0.2): 48 data bytes
> 
> root@sid:~# nc -v -v 1.2 80
> 1.2: inverse host lookup failed: Unknown host
> (UNKNOWN) [1.0.0.2] 80 (http) open
> 
> root@sid:~# telnet 1.2
> Trying 1.0.0.2...
> 
> root@sid:~# ifconfig eth0 1.2
> root@sid:~# ifconfig eth0 |head -2|tail -1
>           inet addr:1.0.0.2  Bcast:1.255.255.255  Mask:255.0.0.0
> root@sid:~# 
> 
> Unless you object, I suggest we close this bug report.

I concur that this is a feature and no additional checking besides the
ones performed by getaddrinfo(3) (similar to inet_aton(3)) are needed,
but the difference between 1.2 and 1 or 4711 is that these latter ones
produce errors (EINVAL) when calling sendto(2), but inetutils' ping
continues regardless, and IMO this needs fixing:

$ PING 1 (0.0.0.1): 48 data bytes
ping: sendto: Invalid argument
ping: sendto: Invalid argument
ping: sendto: Invalid argument
^C--- 1 ping statistics ---
0 packets transmitted, 0 packets received,

I'm applying the attached patch on the next upload. Will be sending it
to upstream too.

thanks,
guillem
>From e85b786a3b76d29544a9a6cadec43d071da218d4 Mon Sep 17 00:00:00 2001
From: Guillem Jover <[email protected]>
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/ping.c (send_echo): Error out instead of continuing sending packets.
---
 ping/libping.c |    2 +-
 ping/ping.c    |    8 +++++++-
 2 files changed, 8 insertions(+), 2 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
-- 
1.7.7.3

Reply via email to