From 2ef2b0462ec3dd04f4abb790ed538363bf60b502 Mon Sep 17 00:00:00 2001 From: Tom Early Date: Tue, 9 Mar 2021 10:08:29 -0700 Subject: [PATCH] complete logging of unknown packets --- src/cbuffer.cpp | 46 +++++++++++++++++++++++++++++++++++++++ src/cbuffer.h | 1 + src/cdcsprotocol.cpp | 4 +++- src/cdextraprotocol.cpp | 5 +++-- src/cdmrmmdvmprotocol.cpp | 4 ++-- src/cdmrplusprotocol.cpp | 6 +++++ src/cdplusprotocol.cpp | 4 +++- src/cxlxprotocol.cpp | 4 +++- src/cysfprotocol.cpp | 6 ++--- src/main.h | 2 +- 10 files changed, 71 insertions(+), 11 deletions(-) diff --git a/src/cbuffer.cpp b/src/cbuffer.cpp index 6c2097a..0741d9d 100644 --- a/src/cbuffer.cpp +++ b/src/cbuffer.cpp @@ -219,3 +219,49 @@ void CBuffer::DebugDumpAscii(std::ofstream &debugout) const } } } + +void CBuffer::Dump(const std::string &title) +{ + std::cout << title << ":" << std::endl; + + unsigned int offset = 0U; + unsigned int length = m_data.size(); + + while (length > 0U) { + std::string output; + + unsigned int bytes = (length > 16U) ? 16U : length; + + char temp[10U]; + for (unsigned i = 0U; i < bytes; i++) { + ::sprintf(temp, "%02X ", m_data[offset + i]); + output += temp; + } + + for (unsigned int i = bytes; i < 16U; i++) + output += " "; + + output += " *"; + + for (unsigned i = 0U; i < bytes; i++) { + unsigned char c = m_data[offset + i]; + + if (::isprint(c)) + output += c; + else + output += '.'; + } + + output += '*'; + + ::sprintf(temp, "%04X: ", offset); + std::cout << offset << output << std::endl; + + offset += 16U; + + if (length >= 16U) + length -= 16U; + else + length = 0U; + } +} diff --git a/src/cbuffer.h b/src/cbuffer.h index 2ceb109..8faf0e5 100644 --- a/src/cbuffer.h +++ b/src/cbuffer.h @@ -67,6 +67,7 @@ public: // debug void DebugDump(std::ofstream &) const; void DebugDumpAscii(std::ofstream &) const; + void Dump(const std::string &title); // pass through void clear() { m_data.clear(); } diff --git a/src/cdcsprotocol.cpp b/src/cdcsprotocol.cpp index 70e95ad..b062023 100644 --- a/src/cdcsprotocol.cpp +++ b/src/cdcsprotocol.cpp @@ -165,7 +165,9 @@ void CDcsProtocol::Task(void) else { // invalid packet - std::cout << "DCS packet (" << Buffer.size() << ") from " << Ip << std::endl; + std::string title("Unknown DCS packet from "); + title += Ip.GetAddress(); + Buffer.Dump(title); } } diff --git a/src/cdextraprotocol.cpp b/src/cdextraprotocol.cpp index 0527694..fb6aca3 100644 --- a/src/cdextraprotocol.cpp +++ b/src/cdextraprotocol.cpp @@ -188,8 +188,9 @@ void CDextraProtocol::Task(void) } else { - std::cout << "DExtra packet (" << Buffer.size() << ")" << std::endl; - //std::cout << Buffer.data() << std::endl; + std::string title("Unknown DExtra packet from "); + title += Ip.GetAddress(); + Buffer.Dump(title); } } diff --git a/src/cdmrmmdvmprotocol.cpp b/src/cdmrmmdvmprotocol.cpp index 0045fc2..ed5fb2d 100644 --- a/src/cdmrmmdvmprotocol.cpp +++ b/src/cdmrmmdvmprotocol.cpp @@ -234,8 +234,8 @@ void CDmrmmdvmProtocol::Task(void) } else if ( Buffer.size() != 55 ) { - std::cout << "DMRmmdvm packet (" << Buffer.size() << ")" << std::endl; - //std::cout << Buffer << std::endl; + std::string title("Unknown DMRMMDVM packet from "); + title += Ip.GetAddress(); } } diff --git a/src/cdmrplusprotocol.cpp b/src/cdmrplusprotocol.cpp index 213924e..acb02f5 100644 --- a/src/cdmrplusprotocol.cpp +++ b/src/cdmrplusprotocol.cpp @@ -156,6 +156,12 @@ void CDmrplusProtocol::Task(void) } g_Reflector.ReleaseClients(); } + else + { + std::string title("Unknown DMR+ packet from "); + title += Ip.GetAddress(); + Buffer.Dump(title); + } } // handle end of streaming timeout diff --git a/src/cdplusprotocol.cpp b/src/cdplusprotocol.cpp index e695b9b..bd9cd11 100644 --- a/src/cdplusprotocol.cpp +++ b/src/cdplusprotocol.cpp @@ -153,7 +153,9 @@ void CDplusProtocol::Task(void) } else { - std::cout << "DPlus packet (" << Buffer.size() << ")" << std::endl; + std::string title("Unknown DPlus packet from "); + title += Ip.GetAddress(); + Buffer.Dump(title); } } diff --git a/src/cxlxprotocol.cpp b/src/cxlxprotocol.cpp index 1d99597..92717a7 100644 --- a/src/cxlxprotocol.cpp +++ b/src/cxlxprotocol.cpp @@ -189,7 +189,9 @@ void CXlxProtocol::Task(void) } else { - std::cout << "XLX packet (" << Buffer.size() << ")" << std::endl; + std::string title("Unknown XLX packet from "); + title += Ip.GetAddress(); + Buffer.Dump(title); } } diff --git a/src/cysfprotocol.cpp b/src/cysfprotocol.cpp index 918b41d..e700625 100644 --- a/src/cysfprotocol.cpp +++ b/src/cysfprotocol.cpp @@ -195,9 +195,9 @@ void CYsfProtocol::Task(void) } else { - // invalid packet - //std::cout << "YSF packet (" << Buffer.size() << ") from " << Callsign << " at " << Ip << std::endl; - //Buffer.DebugDump(g_Reflector.m_DebugFile); + std::string title("Unknown YSF packet from "); + title += Ip.GetAddress(); + Buffer.Dump(title); } } diff --git a/src/main.h b/src/main.h index 36de772..4cd7fd2 100644 --- a/src/main.h +++ b/src/main.h @@ -66,7 +66,7 @@ #define VERSION_MAJOR 2 #define VERSION_MINOR 4 -#define VERSION_REVISION 28 +#define VERSION_REVISION 29 // global ------------------------------------------------------