1
0
Fork 0

Reinstate the IP address logging for the reflector.

ycs232-kbc
Jonathan Naylor 4 years ago
parent 79cf5aa89b
commit 035249b5e0

@ -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);

@ -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;

@ -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

@ -211,12 +211,16 @@ void CYSFReflector::run()
rpt->m_addrLen = addrLen; rpt->m_addrLen = addrLen;
m_repeaters.push_back(rpt); m_repeaters.push_back(rpt);
network.setCount(m_repeaters.size()); network.setCount(m_repeaters.size());
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));
} }
rpt->m_timer.start(); rpt->m_timer.start();
network.writePoll(addr, addrLen); network.writePoll(addr, addrLen);
} else if (::memcmp(buffer + 0U, "YSFU", 4U) == 0 && rpt != NULL) { } else if (::memcmp(buffer + 0U, "YSFU", 4U) == 0 && 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<CYSFRepeater*>::iterator it = m_repeaters.begin(); it != m_repeaters.end(); ++it) { for (std::vector<CYSFRepeater*>::iterator it = m_repeaters.begin(); it != m_repeaters.end(); ++it) {
CYSFRepeater* itRpt = *it; CYSFRepeater* itRpt = *it;
if (CUDPSocket::match(itRpt->m_addr, rpt->m_addr)) { if (CUDPSocket::match(itRpt->m_addr, rpt->m_addr)) {
@ -291,7 +295,9 @@ void CYSFReflector::run()
for (std::vector<CYSFRepeater*>::iterator it = m_repeaters.begin(); it != m_repeaters.end(); ++it) { for (std::vector<CYSFRepeater*>::iterator it = m_repeaters.begin(); it != m_repeaters.end(); ++it) {
CYSFRepeater* itRpt = *it; CYSFRepeater* 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;
network.setCount(m_repeaters.size()); network.setCount(m_repeaters.size());
@ -340,9 +346,12 @@ void CYSFReflector::dumpRepeaters() const
LogMessage("Currently linked repeaters/gateways:"); LogMessage("Currently linked repeaters/gateways:");
for (std::vector<CYSFRepeater*>::const_iterator it = m_repeaters.begin(); it != m_repeaters.end(); ++it) { for (std::vector<CYSFRepeater*>::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);
} }
} }

Loading…
Cancel
Save