From baa0271237ae60cce5a981376eaf14d6ec13b152 Mon Sep 17 00:00:00 2001 From: Daniel Caujolle-Bert Date: Sun, 23 Jan 2022 18:07:55 +0000 Subject: [PATCH] Add new remote command: - status: displays network connection status (n/a, conn, disc), just like DMRGateway/MMDVMHost. - host: display connected host, or NONE if disconnected (surrounded with double quotes). --- P25Gateway/P25Gateway.cpp | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/P25Gateway/P25Gateway.cpp b/P25Gateway/P25Gateway.cpp index 9dd4a3e..f646597 100644 --- a/P25Gateway/P25Gateway.cpp +++ b/P25Gateway/P25Gateway.cpp @@ -36,6 +36,7 @@ #include #include #include +#include #include #include #include @@ -514,6 +515,21 @@ void CP25Gateway::run() voice->linkedTo(currentTG); } } + } else if (::memcmp(buffer + 0U, "status", 6U) == 0) { + std::string state = std::string("p25:") + ((currentAddrLen > 0) ? "conn" : "disc"); + remoteSocket->write((unsigned char*)state.c_str(), (unsigned int)state.length(), addr, addrLen); + } else if (::memcmp(buffer + 0U, "host", 4U) == 0) { + std::string ref; + + if (currentAddrLen > 0) { + char buffer[INET6_ADDRSTRLEN]; + if (getnameinfo((struct sockaddr*)¤tAddr, currentAddrLen, buffer, sizeof(buffer), 0, 0, NI_NUMERICHOST | NI_NUMERICSERV) == 0) { + ref = std::string(buffer); + } + } + + std::string host = std::string("p25:\"") + ((ref.length() == 0) ? "NONE" : ref) + "\""; + remoteSocket->write((unsigned char*)host.c_str(), (unsigned int)host.length(), addr, addrLen); } else { CUtils::dump("Invalid remote command received", buffer, res); }