bug-inetutils
[Top][All Lists]
Advanced

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

[bug-inetutils] [PATCH] ping/libping, ping6: Catch BSD-specific behaviou


From: Mats Erik Andersson
Subject: [bug-inetutils] [PATCH] ping/libping, ping6: Catch BSD-specific behaviour.
Date: Sat, 18 Sep 2010 16:24:01 +0200
User-agent: Mutt/1.5.18 (2008-05-17)

Hello,

in BSD the error returned when the user has insufficient
privilages to generate a raw socket is EACCES, not EPERM
as the present coding in

    ping/libping.c  and   ping/ping6.c.

conduct tests for.

In addition, the header file <sys/uio.h> is necessary
to get access to "struct iovec", which is needed in
order get a compilable source in "ping/ping6.c"


Best regards, 
Mats E A

======================================================================

From db4d22730d618d2c0df98d918d799ceb835012a4 Mon Sep 17 00:00:00 2001
From: Mats Erik Andersson <address@hidden>
Date: Sat, 18 Sep 2010 16:11:11 +0200
Subject: [PATCH] ping/ping6: Missing header and better error detection.

---
 ChangeLog      |    6 ++++++
 ping/libping.c |    2 +-
 ping/ping6.c   |    3 ++-
 3 files changed, 9 insertions(+), 2 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index df40c4b..592bcb7 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,9 @@
+2010-09-18  Mats Erik Andersson <address@hidden>
+
+       * ping/ping6.c: Include <sys/uio.h> for knowing "struct iov" in BSD.
+       * ping/ping6.c (ping_init): Check for EACCES failure from socket(2).
+       * ping/libping.c (ping_init): Likewise.
+
 2010-09-16  Mats Erik Andersson <address@hidden>
 
        * libinetutils/cleansess.c: OpenBSD: include <util.h> if HAVE_UTIL_H.
diff --git a/ping/libping.c b/ping/libping.c
index a83def5..52590ba 100644
--- a/ping/libping.c
+++ b/ping/libping.c
@@ -62,7 +62,7 @@ ping_init (int type, int ident)
   fd = socket (AF_INET, SOCK_RAW, proto->p_proto);
   if (fd < 0)
     {
-      if (errno == EPERM)
+      if (errno == EPERM || errno == EACCES)
        fprintf (stderr, "ping: ping must run as root\n");
       return NULL;
     }
diff --git a/ping/ping6.c b/ping/ping6.c
index e44cdb6..03a9f87 100644
--- a/ping/ping6.c
+++ b/ping/ping6.c
@@ -21,6 +21,7 @@
 
 #include <sys/socket.h>
 #include <sys/time.h>
+#include <sys/uio.h>
 #include <signal.h>
 
 #include <netinet/in.h>
@@ -704,7 +705,7 @@ ping_init (int type, int ident)
   fd = socket (PF_INET6, SOCK_RAW, IPPROTO_ICMPV6);
   if (fd < 0)
     {
-      if (errno == EPERM)
+      if (errno == EPERM || errno == EACCES)
         error (EXIT_FAILURE, errno, NULL);
 
       return NULL;
-- 
1.6.3.3

Attachment: signature.asc
Description: Digital signature


reply via email to

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