forked from f0lg0/netmon_cli
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnetmon.c
65 lines (53 loc) · 1.82 KB
/
netmon.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
65
/*
+----------------------------------------+
| netmon_cli |
| |
| packet sniffer written using |
| raw sockets |
| |
| Author: f0lg0 |
| Date: 31-12-2020 (dd-mm-yyyy) |
+----------------------------------------+
*/
#include "inc/includes.h"
#include "inc/info_gathering.h"
#include "inc/sniffer.h"
#include "inc/repl.h"
FILE* log_f = NULL;
int main(int argc, char *argv[]) {
input_buffer* ibuff = new_input_buffer();
printf("Type '.help' to display commands usage.\n");
while (1) {
print_prompt();
read_input(ibuff);
if (ibuff->buffer[0] == '.') {
switch (parse_meta_command(ibuff)) {
case (META_COMMAND_SUCCESS):
continue;
case (META_COMMAND_UNRECOGNIZED_COMMAND):
printf("Unrecognized command '%s'\n", ibuff->buffer);
continue;
}
}
command cmd;
switch (prepare_command(ibuff, &cmd)) {
case (PREPARE_SUCCESS):
break;
case (PREPARE_SYNTAX_ERROR):
printf("Syntax error. Could not parse command.\n");
continue;
case (PREPARE_UNRECOGNIZED_COMMAND):
printf("Unrecognized keyword at start of '%s'.\n", ibuff->buffer);
continue;
}
switch (execute_command(&cmd)) {
case (EXECUTE_SUCCESS):
printf("[\033[1;32mSUCCESS\033[0m] Executed. \n");
break;
case (EXECUTE_FAILURE):
printf("[\033[1;31mFAILURE\033[0m] failed to execute. \n");
break;
}
}
return 0;
}