-
Notifications
You must be signed in to change notification settings - Fork 0
/
lwfwtest.c
64 lines (59 loc) · 1.4 KB
/
lwfwtest.c
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
#include <stdio.h>
#include <getopt.h>
#include <sys/ioctl.h>
#include <fcntl.h>
#include "lwfw.h"
char* const short_options = "adgf:p:t:";
struct option long_options[] = {
{ "active" , 0, NULL, 'a' },
{ "deactive" , 0, NULL, 'd' },
{ "getstatus" , 0, NULL, 'g' },
{ "denyif" , 1, NULL, 'f' },
{ "denyip" , 1, NULL, 'p' },
{ "denyport" , 1, NULL, 't' },
{ 0 , 0, NULL, 0 },
};
int main(int argc, char *argv[])
{
int c;
int fd;
struct lwfw_stats status;
fd = open("/dev/lwfw",O_RDWR);
if(fd == -1 ){
perror("open");
return 0;
}
while((c = getopt_long (argc, argv, short_options, long_options, NULL)) != -1) {
switch(c){
case 'a':
ioctl(fd,LWFW_ACTIVATE);
break;
case 'd':
ioctl(fd,LWFW_DEACTIVATE);
break;
case 'g':
ioctl(fd,LWFW_GET_STATS,status);
printf("if_dropped is %x\n",status.if_dropped);
printf("ip_dropped is %x\n",status.ip_dropped);
printf("tcp_dropped is %x\n",status.tcp_dropped);
printf("total_dropped is %x\n",status.total_dropped);
printf("total_seen is %x\n",status.total_seen);
break;
case 'f':
ioctl(fd,LWFW_DENY_IF,optarg);
printf("optarg is %s\n",optarg);
break;
case 'p':
ioctl(fd,LWFW_DENY_IP,optarg);
printf("optarg is %s\n",optarg);
break;
case 't':
ioctl(fd,LWFW_DENY_PORT,optarg);
printf("optarg is %s\n",optarg);
break;
default:
printf("sadf\n");
}
}
close(fd);
}