diff --git a/P25Reflector/P25Reflector.cpp b/P25Reflector/P25Reflector.cpp index 0acfc14..05308c5 100644 --- a/P25Reflector/P25Reflector.cpp +++ b/P25Reflector/P25Reflector.cpp @@ -219,7 +219,8 @@ void CP25Reflector::run() rpt->m_callsign = std::string((char*)(buffer + 1U), 10U); m_repeaters.push_back(rpt); - LogMessage("Adding %s", rpt->m_callsign.c_str()); + char buff[80U]; + LogMessage("Adding %s (%s)", rpt->m_callsign.c_str(), CUDPSocket::display(addr, buff, 80U)); } else { rpt->m_timer.start(); } @@ -227,7 +228,9 @@ void CP25Reflector::run() // Return the poll network.writeData(buffer, len, addr, addrLen); } else if (buffer[0U] == 0xF1U && rpt != NULL) { - LogMessage("Removing %s unlinked", rpt->m_callsign.c_str()); + char buff[80U]; + LogMessage("Removing %s (%s) unlinked", rpt->m_callsign.c_str(), CUDPSocket::display(addr, buff, 80U)); + for (std::vector::iterator it = m_repeaters.begin(); it != m_repeaters.end(); ++it) { CP25Repeater* itRpt = *it; if (CUDPSocket::match(itRpt->m_addr, rpt->m_addr)) { @@ -299,7 +302,9 @@ void CP25Reflector::run() for (std::vector::iterator it = m_repeaters.begin(); it != m_repeaters.end(); ++it) { CP25Repeater* itRpt = *it; if (itRpt->m_timer.hasExpired()) { - LogMessage("Removing %s disappeared", itRpt->m_callsign.c_str()); + char buff[80U]; + LogMessage("Removing %s (%s) disappeared", itRpt->m_callsign.c_str(), CUDPSocket::display(itRpt->m_addr, buff, 80U)); + m_repeaters.erase(it); delete itRpt; break; @@ -350,9 +355,12 @@ void CP25Reflector::dumpRepeaters() const LogMessage("Currently linked repeaters:"); for (std::vector::const_iterator it = m_repeaters.begin(); it != m_repeaters.end(); ++it) { - std::string callsign = (*it)->m_callsign; - unsigned int timer = (*it)->m_timer.getTimer(); - unsigned int timeout = (*it)->m_timer.getTimeout(); - LogMessage(" %s %u/%u", callsign.c_str(), timer, timeout); + std::string callsign = (*it)->m_callsign; + sockaddr_storage addr = (*it)->m_addr; + unsigned int timer = (*it)->m_timer.getTimer(); + unsigned int timeout = (*it)->m_timer.getTimeout(); + + char buffer[80U]; + LogMessage(" %s: %s %u/%u", callsign.c_str(), CUDPSocket::display(addr, buffer, 80U), timer, timeout); } } diff --git a/P25Reflector/UDPSocket.cpp b/P25Reflector/UDPSocket.cpp index 510c8a2..2978405 100644 --- a/P25Reflector/UDPSocket.cpp +++ b/P25Reflector/UDPSocket.cpp @@ -160,6 +160,34 @@ bool CUDPSocket::isNone(const sockaddr_storage& addr) return ((addr.ss_family == AF_INET) && (in->sin_addr.s_addr == htonl(INADDR_NONE))); } +char* CUDPSocket::display(const sockaddr_storage& addr, char* buffer, unsigned int length) +{ + assert(buffer != NULL); + assert(length > INET6_ADDRSTRLEN); + + switch (addr.ss_family) { + case AF_INET: { + struct sockaddr_in* in4 = (struct sockaddr_in*)&addr; + ::inet_ntop(AF_INET, &in4, buffer, length); + ::sprintf(buffer + ::strlen(buffer), ":%u", in4->sin_port); + } + break; + + case AF_INET6: { + struct sockaddr_in6* in6 = (struct sockaddr_in6*)&addr; + ::inet_ntop(AF_INET6, &in6, buffer, length); + ::sprintf(buffer + ::strlen(buffer), ":%u", in6->sin6_port); + } + break; + + default: + ::strcpy(buffer, "Unknown"); + break; + } + + return buffer; +} + bool CUDPSocket::open(const sockaddr_storage& address) { return open(address.ss_family); diff --git a/P25Reflector/UDPSocket.h b/P25Reflector/UDPSocket.h index 6e3846c..003483b 100644 --- a/P25Reflector/UDPSocket.h +++ b/P25Reflector/UDPSocket.h @@ -70,6 +70,8 @@ public: static bool isNone(const sockaddr_storage& addr); + static char* display(const sockaddr_storage& address, char* buffer, unsigned int length); + private: std::string m_address_save; unsigned short m_port_save; diff --git a/P25Reflector/Version.h b/P25Reflector/Version.h index 9e751e8..f8421ca 100644 --- a/P25Reflector/Version.h +++ b/P25Reflector/Version.h @@ -19,6 +19,6 @@ #if !defined(VERSION_H) #define VERSION_H -const char* VERSION = "20201101"; +const char* VERSION = "20201124"; #endif