From 30de08bbf3be9011b56f9dc3d2322f492d6ec5c8 Mon Sep 17 00:00:00 2001 From: lonkaars Date: Fri, 3 May 2024 17:25:09 +0200 Subject: dump all packets again --- src/frontend/qt_sdl/LocalMP.cpp | 49 +++++++++++++++++++++++++++-------------- 1 file changed, 32 insertions(+), 17 deletions(-) (limited to 'src/frontend') diff --git a/src/frontend/qt_sdl/LocalMP.cpp b/src/frontend/qt_sdl/LocalMP.cpp index 32f08c8..906f4d4 100644 --- a/src/frontend/qt_sdl/LocalMP.cpp +++ b/src/frontend/qt_sdl/LocalMP.cpp @@ -42,6 +42,10 @@ #include #include "../../vsr.h" +// utility: osdAddMessage +#include "Window.h" +extern MainWindow* mainWindow; + #ifdef VSR_DUMP_MESSAGES #include #include @@ -49,9 +53,7 @@ pcap_dumper_t* dumper; #endif #ifdef VSR_MESSAGE_FIDDLING -#include "Window.h" #include -extern MainWindow* mainWindow; bool fiddle = false; #endif @@ -249,13 +251,6 @@ void SemReset(int num) bool Init() { -#ifdef VSR_DUMP_MESSAGES - pcap_t* handle = pcap_open_dead(DLT_USER0, 1 << 16); - char filename[80]; - snprintf(filename, 79, "melon_%lu.pcap", time(NULL)); - dumper = pcap_dump_open(handle, filename); -#endif - MPQueue = new QSharedMemory("melonNIFI"); if (!MPQueue->attach()) @@ -312,6 +307,14 @@ bool Init() RecvTimeout = 25; +#ifdef VSR_DUMP_MESSAGES + pcap_t* handle = pcap_open_dead(DLT_USER0, 1 << 16); + char filename[80]; + snprintf(filename, 79, "melon_%lu_instance_%d.pcap", time(NULL), InstanceID); + mainWindow->osdAddMessage(0xffffff, "started dumping to %s", filename); + dumper = pcap_dump_open(handle, filename); +#endif + return true; } @@ -404,14 +407,6 @@ void FIFORead(int fifo, void* buf, int len) if (fifo == 0) PacketReadOffset = offset; else ReplyReadOffset = offset; - - // WIP: temporarily capture sent packets only, capture is done on both - // sides anyways, so who cares - // struct pcap_pkthdr p; - // p.len = len; - // p.caplen = len; - // gettimeofday(&p.ts, NULL); - // pcap_dump((u_char*) dumper, &p, (u_char*) buf); } void FIFOWrite(int fifo, void* buf, int len) @@ -555,6 +550,10 @@ int SendPacketGeneric(u32 type, u8* packet, int len, u64 timestamp) int RecvPacketGeneric(u8* packet, bool block, u64* timestamp) { +#ifdef VSR_DUMP_MESSAGES + std::vector buf; +#endif + if (!MPQueue) return 0; for (;;) { @@ -590,10 +589,18 @@ int RecvPacketGeneric(u8* packet, bool block, u64* timestamp) continue; } +#ifdef VSR_DUMP_MESSAGES + buf.insert(buf.end(), (uint8_t*) &pktheader, (uint8_t*) &pktheader + sizeof(pktheader)); +#endif + if (pktheader.Length) { FIFORead(0, packet, pktheader.Length); +#ifdef VSR_DUMP_MESSAGES + buf.insert(buf.end(), (uint8_t*) packet, (uint8_t*) packet + pktheader.Length); +#endif + if (pktheader.Type == 1) LastHostID = pktheader.SenderID; } @@ -601,6 +608,14 @@ int RecvPacketGeneric(u8* packet, bool block, u64* timestamp) if (timestamp) *timestamp = pktheader.Timestamp; MPQueue->unlock(); +#ifdef VSR_DUMP_MESSAGES + struct pcap_pkthdr p; + p.len = buf.size(); + p.caplen = buf.size(); + gettimeofday(&p.ts, NULL); + pcap_dump((u_char*) dumper, &p, buf.data()); +#endif + return pktheader.Length; } } -- cgit v1.2.3