1
0
Fork 0

Merge branch 'master' into IPv6

ycs232-kbc
Jonathan Naylor 4 years ago
commit 183f5e722e

@ -35,6 +35,7 @@ m_debug(debug),
m_addr(), m_addr(),
m_addrLen(), m_addrLen(),
m_ping(NULL), m_ping(NULL),
m_options(NULL),
m_info(NULL), m_info(NULL),
m_reflector(), m_reflector(),
m_print(), m_print(),
@ -53,60 +54,33 @@ m_state(FCS_UNLINKED)
::memset(m_ping + 4U, ' ', 6U); ::memset(m_ping + 4U, ' ', 6U);
::memcpy(m_ping + 4U, callsign.c_str(), callsign.size()); ::memcpy(m_ping + 4U, callsign.c_str(), callsign.size());
::memset(m_ping + 10U, 0x00U, 15U); ::memset(m_ping + 10U, 0x00U, 15U);
m_options = new unsigned char[50U];
::memcpy(m_options + 0U, "FCSO", 4U);
::memset(m_options + 4U, ' ', 46U);
::memcpy(m_options + 4U, callsign.c_str(), callsign.size());
} }
CFCSNetwork::~CFCSNetwork() CFCSNetwork::~CFCSNetwork()
{ {
delete[] m_info; delete[] m_info;
delete[] m_ping; delete[] m_ping;
delete[] m_options;
} }
bool CFCSNetwork::open() bool CFCSNetwork::open()
{ {
LogMessage("Resolving FCS00x addresses"); LogMessage("Resolving FCS999 address");
sockaddr_storage addr; sockaddr_storage addr;
unsigned int addrLen; unsigned int addrLen;
if (CUDPSocket::lookup("fcs999.xreflector.net", FCS_PORT, addr, addrLen) != 0) {
CUDPSocket::lookup("fcs001.xreflector.net", FCS_PORT, addr, addrLen); LogWarning("Unable to lookup the address for FCS999");
return false;
} else {
std::pair<sockaddr_storage, unsigned int> entry = std::make_pair(addr, addrLen); std::pair<sockaddr_storage, unsigned int> entry = std::make_pair(addr, addrLen);
m_addresses["FCS001"] = entry; m_addresses["FCS999"] = entry;
}
CUDPSocket::lookup("fcs002.xreflector.net", FCS_PORT, addr, addrLen);
entry = std::make_pair(addr, addrLen);
m_addresses["FCS002"] = entry;
CUDPSocket::lookup("fcs003.xreflector.net", FCS_PORT, addr, addrLen);
entry = std::make_pair(addr, addrLen);
m_addresses["FCS003"] = entry;
CUDPSocket::lookup("fcs004.xreflector.net", FCS_PORT, addr, addrLen);
entry = std::make_pair(addr, addrLen);
m_addresses["FCS004"] = entry;
CUDPSocket::lookup("fcs005.xreflector.net", FCS_PORT, addr, addrLen);
entry = std::make_pair(addr, addrLen);
m_addresses["FCS005"] = entry;
CUDPSocket::lookup("fcs222.xreflector.net", FCS_PORT, addr, addrLen);
entry = std::make_pair(addr, addrLen);
m_addresses["FCS222"] = entry;
CUDPSocket::lookup("fcs224.xreflector.net", FCS_PORT, addr, addrLen);
entry = std::make_pair(addr, addrLen);
m_addresses["FCS224"] = entry;
CUDPSocket::lookup("fcs232.xreflector.net", FCS_PORT, addr, addrLen);
entry = std::make_pair(addr, addrLen);
m_addresses["FCS232"] = entry;
CUDPSocket::lookup("fcs260.xreflector.net", FCS_PORT, addr, addrLen);
entry = std::make_pair(addr, addrLen);
m_addresses["FCS260"] = entry;
CUDPSocket::lookup("fcs262.xreflector.net", FCS_PORT, addr, addrLen);
entry = std::make_pair(addr, addrLen);
m_addresses["FCS262"] = entry;
LogMessage("Opening FCS network connection"); LogMessage("Opening FCS network connection");
@ -131,6 +105,7 @@ void CFCSNetwork::write(const unsigned char* data)
unsigned char buffer[130U]; unsigned char buffer[130U];
::memset(buffer + 0U, ' ', 130U); ::memset(buffer + 0U, ' ', 130U);
::memcpy(buffer + 0U, data + 35U, 120U); ::memcpy(buffer + 0U, data + 35U, 120U);
::memcpy(buffer + 120U, data + 34U, 1U);
::memcpy(buffer + 121U, m_reflector.c_str(), 8U); ::memcpy(buffer + 121U, m_reflector.c_str(), 8U);
if (m_debug) if (m_debug)
@ -143,15 +118,23 @@ bool CFCSNetwork::writeLink(const std::string& reflector)
{ {
if (m_state != FCS_LINKED) { if (m_state != FCS_LINKED) {
std::string name = reflector.substr(0U, 6U); std::string name = reflector.substr(0U, 6U);
if (m_addresses.count(name) == 0U) { if (m_addresses.count(name) == 0U) {
LogError("Unknown FCS reflector - %s", name.c_str()); char url[30U];
::sprintf(url, "%s.xreflector.net", name.c_str());
sockaddr_storage addr;
unsigned int addrLen;
if (CUDPSocket::lookup(url, FCS_PORT, m_addr, m_addrLen) != 0) {
LogWarning("Unknown FCS reflector - %s", name.c_str());
return false; return false;
} }
} else {
std::pair<sockaddr_storage, unsigned int> entry = m_addresses[name]; std::pair<sockaddr_storage, unsigned int> entry = m_addresses[name];
m_addr = entry.first; m_addr = entry.first;
m_addrLen = entry.second; m_addrLen = entry.second;
} }
}
m_reflector = reflector; m_reflector = reflector;
::memcpy(m_ping + 10U, reflector.c_str(), 8U); ::memcpy(m_ping + 10U, reflector.c_str(), 8U);
@ -167,6 +150,11 @@ bool CFCSNetwork::writeLink(const std::string& reflector)
return true; return true;
} }
void CFCSNetwork::setOptions(const std::string& options)
{
m_opt = options;
}
void CFCSNetwork::writeUnlink(unsigned int count) void CFCSNetwork::writeUnlink(unsigned int count)
{ {
if (m_state != FCS_LINKED) if (m_state != FCS_LINKED)
@ -212,12 +200,14 @@ void CFCSNetwork::clock(unsigned int ms)
LogMessage("Linked to %s", m_print.c_str()); LogMessage("Linked to %s", m_print.c_str());
m_state = FCS_LINKED; m_state = FCS_LINKED;
writeInfo(); writeInfo();
writeOptions();
} }
if (length == 10 && m_state == FCS_LINKING) { if (length == 10 && m_state == FCS_LINKING) {
LogMessage("Linked to %s", m_print.c_str()); LogMessage("Linked to %s", m_print.c_str());
m_state = FCS_LINKED; m_state = FCS_LINKED;
writeInfo(); writeInfo();
writeOptions();
} }
if (length == 7 || length == 10 || length == 130) { if (length == 7 || length == 10 || length == 130) {
@ -294,3 +284,20 @@ void CFCSNetwork::writePing()
m_socket.write(m_ping, 25U, m_addr, m_addrLen); m_socket.write(m_ping, 25U, m_addr, m_addrLen);
} }
void CFCSNetwork::writeOptions()
{
if (m_state != FCS_LINKED)
return;
if (m_opt.size() < 1)
return;
::memset(m_options + 14U, 0x20U, 36U);
::memcpy(m_options + 14U, m_opt.c_str(), m_opt.size());
if (m_debug)
CUtils::dump(1U, "FCS Network Options Sent", m_options, 50U);
m_socket.write(m_options, 50U, m_address, FCS_PORT);
}

Loading…
Cancel
Save