diff options
author | lonkaars <loek@pipeframe.xyz> | 2024-04-29 16:30:59 +0200 |
---|---|---|
committer | lonkaars <loek@pipeframe.xyz> | 2024-04-29 16:30:59 +0200 |
commit | dbe3c25d117e7b7413f13b4ece768e8236650ab6 (patch) | |
tree | 16a84ff9e56fcd5249db4f4d835952f6d563b1f5 /src/frontend | |
parent | 6d509fb24071deb7669977735b613467ebd82518 (diff) |
basic LocalMP packet dump working
Diffstat (limited to 'src/frontend')
-rw-r--r-- | src/frontend/qt_sdl/LocalMP.cpp | 25 |
1 files changed, 25 insertions, 0 deletions
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; } } |