Reinstate the IP address logging for the reflector.

This commit is contained in:
Jonathan Naylor 2020-11-24 12:50:41 +00:00
parent 061f54b169
commit a2b0e02593
4 changed files with 46 additions and 8 deletions

View File

@ -219,7 +219,8 @@ void CP25Reflector::run()
rpt->m_callsign = std::string((char*)(buffer + 1U), 10U); rpt->m_callsign = std::string((char*)(buffer + 1U), 10U);
m_repeaters.push_back(rpt); 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 { } else {
rpt->m_timer.start(); rpt->m_timer.start();
} }
@ -227,7 +228,9 @@ void CP25Reflector::run()
// Return the poll // Return the poll
network.writeData(buffer, len, addr, addrLen); network.writeData(buffer, len, addr, addrLen);
} else if (buffer[0U] == 0xF1U && rpt != NULL) { } 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<CP25Repeater*>::iterator it = m_repeaters.begin(); it != m_repeaters.end(); ++it) { for (std::vector<CP25Repeater*>::iterator it = m_repeaters.begin(); it != m_repeaters.end(); ++it) {
CP25Repeater* itRpt = *it; CP25Repeater* itRpt = *it;
if (CUDPSocket::match(itRpt->m_addr, rpt->m_addr)) { if (CUDPSocket::match(itRpt->m_addr, rpt->m_addr)) {
@ -299,7 +302,9 @@ void CP25Reflector::run()
for (std::vector<CP25Repeater*>::iterator it = m_repeaters.begin(); it != m_repeaters.end(); ++it) { for (std::vector<CP25Repeater*>::iterator it = m_repeaters.begin(); it != m_repeaters.end(); ++it) {
CP25Repeater* itRpt = *it; CP25Repeater* itRpt = *it;
if (itRpt->m_timer.hasExpired()) { 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); m_repeaters.erase(it);
delete itRpt; delete itRpt;
break; break;
@ -350,9 +355,12 @@ void CP25Reflector::dumpRepeaters() const
LogMessage("Currently linked repeaters:"); LogMessage("Currently linked repeaters:");
for (std::vector<CP25Repeater*>::const_iterator it = m_repeaters.begin(); it != m_repeaters.end(); ++it) { for (std::vector<CP25Repeater*>::const_iterator it = m_repeaters.begin(); it != m_repeaters.end(); ++it) {
std::string callsign = (*it)->m_callsign; std::string callsign = (*it)->m_callsign;
unsigned int timer = (*it)->m_timer.getTimer(); sockaddr_storage addr = (*it)->m_addr;
unsigned int timeout = (*it)->m_timer.getTimeout(); unsigned int timer = (*it)->m_timer.getTimer();
LogMessage(" %s %u/%u", callsign.c_str(), timer, timeout); 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);
} }
} }

View File

@ -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))); 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) bool CUDPSocket::open(const sockaddr_storage& address)
{ {
return open(address.ss_family); return open(address.ss_family);

View File

@ -70,6 +70,8 @@ public:
static bool isNone(const sockaddr_storage& addr); static bool isNone(const sockaddr_storage& addr);
static char* display(const sockaddr_storage& address, char* buffer, unsigned int length);
private: private:
std::string m_address_save; std::string m_address_save;
unsigned short m_port_save; unsigned short m_port_save;

View File

@ -19,6 +19,6 @@
#if !defined(VERSION_H) #if !defined(VERSION_H)
#define VERSION_H #define VERSION_H
const char* VERSION = "20201101"; const char* VERSION = "20201124";
#endif #endif