#include #include #include #include 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: pcap_t* handle = pcap_open_dead(DLT_NULL, 1 << 16); dumper = pcap_dump_open(handle, "dump.pcap"); test(); pcap_dump_close(dumper); return 0; }