From dbe3c25d117e7b7413f13b4ece768e8236650ab6 Mon Sep 17 00:00:00 2001 From: lonkaars Date: Mon, 29 Apr 2024 16:30:59 +0200 Subject: basic LocalMP packet dump working --- .gitignore | 2 ++ makefile | 2 ++ src/CMakeLists.txt | 1 + src/frontend/qt_sdl/LocalMP.cpp | 25 +++++++++++++++++++++++++ 4 files changed, 30 insertions(+) diff --git a/.gitignore b/.gitignore index 0e001b7..7680a99 100644 --- a/.gitignore +++ b/.gitignore @@ -20,3 +20,5 @@ cmake-build-debug .vscode CMakeFiles CMakeCache.txt + +*.pcap \ No newline at end of file diff --git a/makefile b/makefile index dcc4ceb..930e85a 100644 --- a/makefile +++ b/makefile @@ -9,3 +9,5 @@ build/build.ninja: CMakeLists.txt build/melonDS: build/build.ninja FORCE @ninja -C build +run: build/melonDS + @$< diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 3dfd3b0..1f6a3e7 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -178,3 +178,4 @@ endif() # ) #endif() +target_link_libraries(core PRIVATE pcap) diff --git a/src/frontend/qt_sdl/LocalMP.cpp b/src/frontend/qt_sdl/LocalMP.cpp index 7ea9868..18d1b65 100644 --- a/src/frontend/qt_sdl/LocalMP.cpp +++ b/src/frontend/qt_sdl/LocalMP.cpp @@ -38,6 +38,11 @@ #include "LocalMP.h" #include "Platform.h" +#include +#include + +pcap_dumper_t* dumper; + using namespace melonDS; using namespace melonDS::Platform; @@ -241,6 +246,11 @@ void SemReset(int num) bool Init() { + pcap_t* handle = pcap_open_dead(DLT_NULL, 1 << 16); + char filename[80]; + snprintf(filename, 79, "melon_instance_%d.pcap", InstanceID); + dumper = pcap_dump_open(handle, filename); + MPQueue = new QSharedMemory("melonNIFI"); if (!MPQueue->attach()) @@ -302,6 +312,8 @@ bool Init() void DeInit() { + pcap_dump_close(dumper); + if (MPQueue) { MPQueue->lock(); @@ -476,6 +488,12 @@ 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; } @@ -526,6 +544,13 @@ 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