diff options
author | lonkaars <loek@pipeframe.xyz> | 2024-04-29 18:40:03 +0200 |
---|---|---|
committer | lonkaars <loek@pipeframe.xyz> | 2024-04-29 18:40:03 +0200 |
commit | 8f33d9c9a7c95f17c480782fee3b5e405d41a79c (patch) | |
tree | c3898b34563d5225d6027e4b6138c16e1172534d /experiments/pcap | |
parent | 8934da54f4bf6101ae03cdc9ef4644d9d26297f3 (diff) |
WIP wireshark dissector
Diffstat (limited to 'experiments/pcap')
-rw-r--r-- | experiments/pcap/.gitignore | 2 | ||||
-rw-r--r-- | experiments/pcap/main.c | 53 | ||||
-rw-r--r-- | experiments/pcap/makefile | 2 |
3 files changed, 57 insertions, 0 deletions
diff --git a/experiments/pcap/.gitignore b/experiments/pcap/.gitignore new file mode 100644 index 0000000..be0cff0 --- /dev/null +++ b/experiments/pcap/.gitignore @@ -0,0 +1,2 @@ +main +*.pcap diff --git a/experiments/pcap/main.c b/experiments/pcap/main.c new file mode 100644 index 0000000..25fb0fc --- /dev/null +++ b/experiments/pcap/main.c @@ -0,0 +1,53 @@ +#include <stdio.h> +#include <stdint.h> +#include <string.h> + +#include <pcap/pcap.h> + +pcap_dumper_t* dumper; + +ssize_t test_write(uint8_t* buf, size_t count) { + struct pcap_pkthdr packet; + packet.len = count; + packet.caplen = count; + pcap_dump((u_char*) dumper, &packet, buf); + + return count; +} + +ssize_t test_read(uint8_t* buf, size_t count) { + strncpy((char*) buf, "i read hello world!", count); + + struct pcap_pkthdr packet; + packet.len = count; + packet.caplen = count; + pcap_dump((u_char*) dumper, &packet, buf); + + return count; +} + +void test() { + ssize_t len; + const char* msg = "i write hello world!"; + + len = test_write((uint8_t*) msg, strlen(msg)); + printf("wrote %lu bytes: \"%s\"\n", len, msg); + + char buf[80] = { 0 }; + len = test_read((uint8_t*) buf, 16); + buf[len] = '\0'; + printf("read %lu bytes: \"%s\"\n", len, buf); +} + +int main() { + // see also: <https://www.tcpdump.org/linktypes.html> + pcap_t* handle = pcap_open_dead(DLT_NULL, 1 << 16); + dumper = pcap_dump_open(handle, "dump.pcap"); + + test(); + + pcap_dump_close(dumper); + + return 0; +} + diff --git a/experiments/pcap/makefile b/experiments/pcap/makefile new file mode 100644 index 0000000..53c3aea --- /dev/null +++ b/experiments/pcap/makefile @@ -0,0 +1,2 @@ +CFLAGS += -lpcap +main: main.c |