diff options
| author | Mosder <xmosder12@gmail.com> | 2026-06-17 23:01:28 +0200 |
|---|---|---|
| committer | Mosder <xmosder12@gmail.com> | 2026-06-17 23:01:28 +0200 |
| commit | cc903a47e45daa3499d652944665419eeadd74be (patch) | |
| tree | 2ab15188499eb5c0d7f9c36d1b2c63c92c31a602 /analyzer/analyzer.c | |
| parent | 2e3f7fe39791cd671a68330f7ba7a5bb5fc6f9ae (diff) | |
| parent | d62be280a151883866554e9ea00a5efed2fa593a (diff) | |
Merge the branch with master, because i forgor to create it from newest
commit
Diffstat (limited to 'analyzer/analyzer.c')
| -rw-r--r-- | analyzer/analyzer.c | 36 |
1 files changed, 36 insertions, 0 deletions
diff --git a/analyzer/analyzer.c b/analyzer/analyzer.c new file mode 100644 index 0000000..7790f41 --- /dev/null +++ b/analyzer/analyzer.c @@ -0,0 +1,36 @@ +#include "analyzer.h" + +#include <unistd.h> + +#include "utils/pcap.h" + +void analyze_file(char *path) { + // open the file + char errbuf[PCAP_ERRBUF_SIZE]; + pcap_t *handle = pcap_open_offline(path, errbuf); + + // handle errors + if (handle == NULL) { + printf("Couldn't open the specified file:\n%s\n", errbuf); + return; + } + + struct pcap_pkthdr *packet_data; + const unsigned char *packet; + const unsigned char *payload; + + // read packets from the file + while (pcap_next_ex(handle, &packet_data, &packet) == 1) { + int payload_len; + payload = get_payload_from_packet(packet, packet_data, &payload_len); + if (payload_len > 0) { + printf("\n----------------\n"); + printf("Payload length: %d\n", payload_len); + printf("Payload:\n"); + fflush(stdout); + write(STDOUT_FILENO, payload, payload_len); + } + } + + pcap_close(handle); +} |
