-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathringbuf.cc
More file actions
79 lines (68 loc) · 1.63 KB
/
Copy pathringbuf.cc
File metadata and controls
79 lines (68 loc) · 1.63 KB
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
#include <cstdio>
#include <cstring>
#include <unistd.h>
#include <linux/ethtool.h>
#include <linux/sockios.h>
#include <sys/socket.h>
#include <sys/ioctl.h>
#include <net/if.h>
int main(int argc, char *argv[])
{
if (argc < 1)
{
fprintf(stderr, "Usage: %s dev ..\n", argv[0]);
return 1;
}
/* Open a socket so that we can do ioctl()s */
int fd = socket(AF_INET, SOCK_DGRAM, 0);
if (fd < 0)
{
perror("socket");
return 1;
}
++ argv;
while (argv && *argv)
{
const char *iface = *argv;
printf("trying %s\n", iface);
/* Set up command structure */
ifreq ifr;
memset(&ifr, 0, sizeof ifr);
/* Select device */
strcpy(ifr.ifr_name, iface);
/* Select command */
ethtool_ringparam ering;
ifr.ifr_data = reinterpret_cast<char *>(&ering);
ering.cmd = ETHTOOL_GRINGPARAM; /* read ring data */
int retval = ioctl(fd, SIOCETHTOOL, &ifr);
if (retval < 0)
{
perror("ioctl");
}
else if (ering.rx_pending)
{
printf("Current rx value is %d\n", ering.rx_pending);
if (ering.rx_pending < 4096)
{
ering.rx_pending = 4096;
ering.cmd = ETHTOOL_SRINGPARAM;
retval = ioctl(fd, SIOCETHTOOL, &ifr);
if (retval < 0)
{
perror("ioctl 2");
}
else
{
printf(" ==> successfully updated to %d\n", ering.rx_pending);
}
}
}
else
{
printf("ioctl() did not return any data\n");
}
++ argv;
}
close(fd);
return 0;
}