-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.c
62 lines (54 loc) · 2.07 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
/*
>>=========================================================<<
|| ______ _ __ __ __||
|| /_ __/ __(_)____/ /___ __ / /__ ____ _____/ /||
|| / / | | /| / / / ___/ __/ / / /_ / / _ \/ __ `/ __ / ||
|| / / | |/ |/ / (__ ) /_/ /_/ / /_/ / __/ /_/ / /_/ / ||
||/_/ |__/|__/_/____/\__/\__, /\____/\___/\__,_/\__,_/ ||
|| /____/ ||
>>=========================================================<<
Tʜɪꜱ ᴘʀᴏᴊᴇᴄᴛ ᴡᴀꜱ ᴅᴇᴠᴇʟᴏᴘᴇᴅ ʙʏ TᴡɪꜱᴛʏJᴇᴀᴅ ツ
ɢɪᴛʜᴜʙ.ᴄᴏᴍ/ᴍᴏᴏɴʟxɪɢʜᴛ */
#include <stdio.h>
#include <stdlib.h>
#include <pcap.h>
#include <time.h>
#include <glib.h>
#include "gui.h"
pcap_t *handle;
char errbuf[PCAP_ERRBUF_SIZE];
FILE *logfile;
void packet_handler(u_char *param, const struct pcap_pkthdr *header, const u_char *pkt_data) {
FILE *logfile = (FILE *)param;
int i;
logfile = fopen("packet_log.txt", "a");
if (logfile == NULL) {
fprintf(stderr, "Failed to create log file.\n");
return;
}
fprintf(logfile, "Packet Captured! Size: %d bytes\n", header->len);
fprintf(logfile, "Arrival Time: %s", ctime((const time_t *)&header->ts.tv_sec));
for (i = 0; i < header->len; i++) {
fprintf(logfile, " %02x ", pkt_data[i]);
if ((i + 1) % 16 == 0) fprintf(logfile, "\n");
}
fprintf(logfile, "\n\n");
fclose(logfile);
}
int main() {
logfile = fopen("packet_log.txt", "w");
if (logfile == NULL) {
fprintf(stderr, "Failed to create log file.\n");
exit(1);
}
start_gui(logfile);
handle = pcap_open_live("eth0", BUFSIZ, 1, 1000, errbuf);
if (handle == NULL) {
fprintf(stderr, "Failed to capture network interface: %s\n", errbuf);
exit(1);
}
pcap_loop(handle, 0, packet_handler, (u_char *)logfile);
fclose(logfile);
pcap_close(handle);
return 0;
}