From 671742244c20804c9e935326e3649dac3382f17a Mon Sep 17 00:00:00 2001 From: Sam Roberts Date: Mon, 3 May 2010 16:24:13 -0700 Subject: [PATCH] Don't explicitly check for UID 0, we may have capabilities even if not root. (Thomas Habets) Conflicts: libnet/src/libnet_init.c --- libnet/src/libnet_init.c | 9 +-------- libnet/src/libnet_link_linux.c | 17 +++++++++++++++-- 2 files changed, 16 insertions(+), 10 deletions(-) diff --git a/libnet/src/libnet_init.c b/libnet/src/libnet_init.c index b6ff7ec9..5cc15778 100644 --- a/libnet/src/libnet_init.c +++ b/libnet/src/libnet_init.c @@ -44,14 +44,7 @@ libnet_init(int injection_type, const char *device, char *err_buf) { libnet_t *l = NULL; -#if !defined(__WIN32__) - if ((injection_type != LIBNET_NONE) && getuid() && geteuid()) - { - snprintf(err_buf, LIBNET_ERRBUF_SIZE, - "%s(): UID or EUID of 0 required\n", __func__); - goto bad; - } -#else +#if defined(__WIN32__) WSADATA wsaData; if ((WSAStartup(0x0202, &wsaData)) != 0) diff --git a/libnet/src/libnet_link_linux.c b/libnet/src/libnet_link_linux.c index f87502dd..7b6ddc61 100644 --- a/libnet/src/libnet_link_linux.c +++ b/libnet/src/libnet_link_linux.c @@ -87,8 +87,15 @@ libnet_open_link(libnet_t *l) #endif if (l->fd == -1) { - snprintf(l->err_buf, LIBNET_ERRBUF_SIZE, - "socket: %s", strerror(errno)); + if (errno == EPERM) { + snprintf(l->err_buf, LIBNET_ERRBUF_SIZE, + "%s(): UID/EUID 0 or capability CAP_NET_RAW required", + __func__); + + } else { + snprintf(l->err_buf, LIBNET_ERRBUF_SIZE, + "socket: %s", strerror(errno)); + } goto bad; } @@ -299,5 +306,11 @@ libnet_get_hwaddr(libnet_t *l) return (NULL); } +/* ---- Emacs Variables ---- + * Local Variables: + * c-basic-offset: 4 + * indent-tabs-mode: nil + * End: + */ /* EOF */