forked from MaryamSaeedmehr/PacketFilteringKernelModule
-
Notifications
You must be signed in to change notification settings - Fork 0
/
App_PacketFiltering.c
57 lines (54 loc) · 1.31 KB
/
App_PacketFiltering.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
/*
* Packet Filtering application
*
* Create By : Maryam Saeedmehr
* Stu.NO : 9629373
*
* Created On : Tue Jan 7, 18:56
* Language : C
*/
#include <string.h>
#include <stdio.h>
#include <stdlib.h>
#include <errno.h>
#include <fcntl.h>
#include <unistd.h>
int main()
{
int k;
char config_mode[15];
char read_from_file[25];
FILE* config_file;
config_file = fopen("config.txt", "r");
if (!config_file)
{
perror("Failed to open the file...");
return errno;
}
fgets(read_from_file, 14, config_file);
sscanf(read_from_file,"%s", config_mode);
printf("Config Mode:%s\n",config_mode);
int fd = open("/dev/packetfilter", O_RDWR);
if (fd < 0)
{
perror("Failed to open the device...");
return errno;
}
int ret = write(fd, read_from_file, strlen(read_from_file));
if (ret < 0)
{
perror("Failed to write the message to the device.");
return errno;
}
while(fgets(read_from_file, 24, config_file))
{
printf("IP : %s is being sent down to the kernel\n", read_from_file);
int ret = write(fd, read_from_file, strlen(read_from_file));
if (ret < 0)
{
perror("Failed to write the message to the device.");
return errno;
}
}
return 0;
}