Skip to content

Commit aaa383b

Browse files
committed
Don't explicitly check for UID 0, we may have capabilities even if not root.
1 parent 15a4b4d commit aaa383b

File tree

2 files changed

+16
-10
lines changed

2 files changed

+16
-10
lines changed

libnet/src/libnet_init.c

+1-8
Original file line numberDiff line numberDiff line change
@@ -44,14 +44,7 @@ libnet_init(int injection_type, const char *device, char *err_buf)
4444
{
4545
libnet_t *l = NULL;
4646

47-
#if !defined(__WIN32__)
48-
if ((injection_type != LIBNET_NONE) && getuid() && geteuid())
49-
{
50-
snprintf(err_buf, LIBNET_ERRBUF_SIZE,
51-
"%s(): UID or EUID of 0 required", __func__);
52-
goto bad;
53-
}
54-
#else
47+
#if defined(__WIN32__)
5548
WSADATA wsaData;
5649

5750
if ((WSAStartup(0x0202, &wsaData)) != 0)

libnet/src/libnet_link_linux.c

+15-2
Original file line numberDiff line numberDiff line change
@@ -87,8 +87,15 @@ libnet_open_link(libnet_t *l)
8787
#endif
8888
if (l->fd == -1)
8989
{
90-
snprintf(l->err_buf, LIBNET_ERRBUF_SIZE,
91-
"socket: %s", strerror(errno));
90+
if (errno == EPERM) {
91+
snprintf(l->err_buf, LIBNET_ERRBUF_SIZE,
92+
"%s(): UID/EUID 0 or capability CAP_NET_RAW required",
93+
__func__);
94+
95+
} else {
96+
snprintf(l->err_buf, LIBNET_ERRBUF_SIZE,
97+
"socket: %s", strerror(errno));
98+
}
9299
goto bad;
93100
}
94101

@@ -299,5 +306,11 @@ libnet_get_hwaddr(libnet_t *l)
299306
return (NULL);
300307
}
301308

309+
/* ---- Emacs Variables ----
310+
* Local Variables:
311+
* c-basic-offset: 4
312+
* indent-tabs-mode: nil
313+
* End:
314+
*/
302315

303316
/* EOF */

0 commit comments

Comments
 (0)