From 3afa96c6cd5f65410a92b527a6b0d933ce2d5191 Mon Sep 17 00:00:00 2001 From: Daniel Caujolle-Bert Date: Sun, 23 Jan 2022 17:44:44 +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). --- NXDNGateway/NXDNGateway.cpp | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/NXDNGateway/NXDNGateway.cpp b/NXDNGateway/NXDNGateway.cpp index 716399d..775268a 100644 --- a/NXDNGateway/NXDNGateway.cpp +++ b/NXDNGateway/NXDNGateway.cpp @@ -38,6 +38,7 @@ #include #include #include +#include #include #include #include @@ -539,6 +540,21 @@ void CNXDNGateway::run() voice->linkedTo(currentTG); } } + } else if (::memcmp(buffer + 0U, "status", 6U) == 0) { + std::string state = std::string("nxdn:") + ((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("nxdn:\"") + ((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); }