-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathmain.c
executable file
·94 lines (79 loc) · 1.97 KB
/
main.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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
#include <unistd.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "Data.h"
#include "Cfg.h"
#include "Infra.h"
#include "Sniff.h"
#include "main.h"
int main(int argc, char **argv)
{
extern char *optarg;
extern int optind;
int error = 0;
int c;
char *filter = NULL;
dev = NULL;
prefix = (char *)calloc(HBUFSIZE, sizeof(char));
dir = (char *)calloc(BUFSIZE, sizeof(char));
strcpy(prefix, "/usr/local/share/hafiye");
while (!error && (c = getopt(argc,argv,"k:i:n:dhpv")) != -1) {
switch(c) {
case 'i':
dev = (char *)calloc(DEVSIZ, sizeof(char));
strncpy(dev, optarg, DEVSIZ);
break;
case 'k':
strncpy(prefix, optarg, HBUFSIZE);
break;
case 'd':
debug = 1;
break;
case 'n':
npackets = atoi(optarg);
break;
case 'h':
usage();
exit(0);
break;
case 'p':
promisc = 1;
break;
case 'v':
printf("%s -- http://www.enderunix.org/hafiye/\n", VERSION);
printf("by [email protected]\n");
exit(0);
break;
default:
usage();
error = 1;
break;
}
}
if (error)
exit(1);
if (argc > optind)
filter = strdup(argv[optind]);
snprintf(dir, BUFSIZE, "%s/%s", prefix, "LII");
knowLayerTwo(dir);
snprintf(dir, BUFSIZE, "%s/%s", prefix, "LIII");
knowLayerThree(dir);
snprintf(dir, BUFSIZE, "%s/%s", prefix, "LIV");
knowLayerFour(dir);
startSniffer(filter);
startSniffLoop();
return 0;
}
void usage()
{
fprintf(stderr, "usage: hafiye [options] [\"pcap filter\"]\n");
fprintf(stderr, "options:\n");
fprintf(stderr, "\t-i interface\t\t\tspecify interface to listen on\n");
fprintf(stderr, "\t-k directory\t\t\tspecify location to knowledge-base files\n");
fprintf(stderr, "\t-d\t\t\t\tshow debugging info\n");
fprintf(stderr, "\t-p\t\t\t\tput into promiscuous mode\n");
fprintf(stderr, "\t-n packet count\t\t\tnumber of packets to receive\n");
fprintf(stderr, "\t-t timeout\t\t\tread timeout\n");
fprintf(stderr, "\nhttp://www.enderunix.org/hafiye/\n");
}