From 4732f4233313a4150370c0b866335ef4eca3a026 Mon Sep 17 00:00:00 2001 From: lonkaars Date: Mon, 29 Apr 2024 18:40:30 +0200 Subject: better packet sniffer --- makefile | 2 +- src/frontend/qt_sdl/LocalMP.cpp | 29 +++++++++++++++-------------- 2 files changed, 16 insertions(+), 15 deletions(-) diff --git a/makefile b/makefile index 930e85a..6ca562e 100644 --- a/makefile +++ b/makefile @@ -10,4 +10,4 @@ build/melonDS: build/build.ninja FORCE @ninja -C build run: build/melonDS - @$< + @$< --boot always diff --git a/src/frontend/qt_sdl/LocalMP.cpp b/src/frontend/qt_sdl/LocalMP.cpp index 18d1b65..b90ff05 100644 --- a/src/frontend/qt_sdl/LocalMP.cpp +++ b/src/frontend/qt_sdl/LocalMP.cpp @@ -19,6 +19,7 @@ #include #include #include +#include #ifdef __WIN32__ #include @@ -246,9 +247,9 @@ void SemReset(int num) bool Init() { - pcap_t* handle = pcap_open_dead(DLT_NULL, 1 << 16); + pcap_t* handle = pcap_open_dead(DLT_USER0, 1 << 16); char filename[80]; - snprintf(filename, 79, "melon_instance_%d.pcap", InstanceID); + snprintf(filename, 79, "melon_%lu.pcap", time(NULL)); dumper = pcap_dump_open(handle, filename); MPQueue = new QSharedMemory("melonNIFI"); @@ -397,6 +398,12 @@ void FIFORead(int fifo, void* buf, int len) if (fifo == 0) PacketReadOffset = offset; else ReplyReadOffset = offset; + + 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) @@ -433,6 +440,12 @@ void FIFOWrite(int fifo, void* buf, int len) if (fifo == 0) header->PacketWriteOffset = offset; else header->ReplyWriteOffset = offset; + + struct pcap_pkthdr p; + p.len = len; + p.caplen = len; + gettimeofday(&p.ts, NULL); + pcap_dump((u_char*) dumper, &p, (u_char*) buf); } int SendPacketGeneric(u32 type, u8* packet, int len, u64 timestamp) @@ -488,12 +501,6 @@ int SendPacketGeneric(u32 type, u8* packet, int len, u64 timestamp) } } - struct pcap_pkthdr p; - p.len = len; - p.caplen = len; - gettimeofday(&p.ts, NULL); - pcap_dump((u_char*) dumper, &p, packet); - return len; } @@ -545,12 +552,6 @@ int RecvPacketGeneric(u8* packet, bool block, u64* timestamp) if (timestamp) *timestamp = pktheader.Timestamp; MPQueue->unlock(); - struct pcap_pkthdr p; - p.len = pktheader.Length; - p.caplen = pktheader.Length; - gettimeofday(&p.ts, NULL); - pcap_dump((u_char*) dumper, &p, packet); - return pktheader.Length; } } -- cgit v1.2.3