From 610da89ab433d4113e68e8fa43873d8447bcf356 Mon Sep 17 00:00:00 2001 From: Tom Early Date: Tue, 14 Dec 2021 11:07:29 -0700 Subject: [PATCH] M17 Packet sending a DEBUG help --- reflector/M17Protocol.cpp | 3 +-- reflector/Protocol.cpp | 16 ++++++++++++++++ reflector/Protocol.h | 1 + reflector/UDPSocket.cpp | 5 +++++ reflector/UDPSocket.h | 1 + 5 files changed, 24 insertions(+), 2 deletions(-) diff --git a/reflector/M17Protocol.cpp b/reflector/M17Protocol.cpp index e2cc569..a3c75af 100644 --- a/reflector/M17Protocol.cpp +++ b/reflector/M17Protocol.cpp @@ -262,9 +262,8 @@ void CM17Protocol::HandleQueue(void) // is this client busy ? if ( !client->IsAMaster() && (client->GetReflectorModule() == module) ) { - CBuffer Buffer(frame.magic, sizeof(SM17Frame)); // no, send the packet - Send(Buffer, client->GetIp()); + Send(frame, client->GetIp()); } } diff --git a/reflector/Protocol.cpp b/reflector/Protocol.cpp index 4af5e84..bd6e704 100644 --- a/reflector/Protocol.cpp +++ b/reflector/Protocol.cpp @@ -337,6 +337,22 @@ void CProtocol::Send(const char *buf, const CIp &Ip, uint16_t port) const } } +void CProtocol::Send(const SM17Frame &frame, const CIp &Ip) const +{ + switch (Ip.GetFamily()) + { + case AF_INET: + m_Socket4.Send(frame.magic, sizeof(SM17Frame), Ip); + break; + case AF_INET6: + m_Socket6.Send(frame.magic, sizeof(SM17Frame), Ip); + break; + default: + std::cerr << "WrongFamily: " << Ip.GetFamily() << std::endl; + break; + } +} + #ifdef DEBUG void CProtocol::Dump(const char *title, const uint8_t *data, int length) { diff --git a/reflector/Protocol.h b/reflector/Protocol.h index 719f53e..6d0c37c 100644 --- a/reflector/Protocol.h +++ b/reflector/Protocol.h @@ -113,6 +113,7 @@ protected: void Send(const char *buf, const CIp &Ip) const; void Send(const CBuffer &buf, const CIp &Ip, uint16_t port) const; void Send(const char *buf, const CIp &Ip, uint16_t port) const; + void Send(const SM17Frame &frame, const CIp &Ip) const; // socket CUdpSocket m_Socket4; diff --git a/reflector/UDPSocket.cpp b/reflector/UDPSocket.cpp index 6cc8608..9787cff 100644 --- a/reflector/UDPSocket.cpp +++ b/reflector/UDPSocket.cpp @@ -173,3 +173,8 @@ void CUdpSocket::Send(const char *Buffer, const CIp &Ip, uint16_t destport) cons temp.SetPort(destport); sendto(m_fd, Buffer, ::strlen(Buffer), 0, temp.GetCPointer(), temp.GetSize()); } + +void CUdpSocket::Send(const uint8_t *data, size_t size, const CIp &Ip) const +{ + sendto(m_fd, data, size, 0, Ip.GetCPointer(), Ip.GetSize()); +} diff --git a/reflector/UDPSocket.h b/reflector/UDPSocket.h index 2a3e231..cc001f3 100644 --- a/reflector/UDPSocket.h +++ b/reflector/UDPSocket.h @@ -57,6 +57,7 @@ public: void Send(const char *, const CIp &) const; void Send(const CBuffer &, const CIp &, uint16_t) const; void Send(const char *, const CIp &, uint16_t) const; + void Send(const u_int8_t *, size_t size, const CIp &) const; protected: // data