aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorlonkaars <loek@pipeframe.xyz>2024-04-29 16:30:59 +0200
committerlonkaars <loek@pipeframe.xyz>2024-04-29 16:30:59 +0200
commitdbe3c25d117e7b7413f13b4ece768e8236650ab6 (patch)
tree16a84ff9e56fcd5249db4f4d835952f6d563b1f5
parent6d509fb24071deb7669977735b613467ebd82518 (diff)
basic LocalMP packet dump working
-rw-r--r--.gitignore2
-rw-r--r--makefile2
-rw-r--r--src/CMakeLists.txt1
-rw-r--r--src/frontend/qt_sdl/LocalMP.cpp25
4 files changed, 30 insertions, 0 deletions
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 <pcap/pcap.h>
+#include <time.h>
+
+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;
}
}