More IPv6 work.

This commit is contained in:
Jonathan Naylor 2020-11-15 22:51:21 +00:00
parent e550499242
commit 87012ff6f5
17 changed files with 282 additions and 283 deletions

View file

@ -66,7 +66,7 @@ m_rptCall2()
{
wxASSERT(protoHandler != NULL);
wxASSERT(handler != NULL);
wxASSERT(port > 0U);
wxASSERT(addrLen > 0U);
m_myPort = protoHandler->getPort();
@ -182,15 +182,13 @@ void CDCSHandler::getInfo(IReflectorCallback* handler, CRemoteRepeaterData& data
void CDCSHandler::process(CAMBEData& data)
{
sockaddr_storage yourAddr = data.getYourAddr();
unsigned int yourAddrLen = data.getYourAddrLen();
unsigned int myPort = data.getMyPort();
for (unsigned int i = 0U; i < m_maxReflectors; i++) {
CDCSHandler* reflector = m_reflectors[i];
if (reflector != NULL) {
if (reflector->m_yourAddress.s_addr == yourAddress.s_addr &&
reflector->m_yourPort == yourPort &&
reflector->m_myPort == myPort) {
if (CUDPReaderWriter::match(reflector->m_yourAddr, yourAddr) &&
reflector->m_myPort == myPort) {
reflector->processInt(data);
return;
}
@ -203,7 +201,6 @@ void CDCSHandler::process(CPollData& poll)
wxString reflector = poll.getData1();
wxString repeater = poll.getData2();
sockaddr_storage yourAddr = poll.getYourAddr();
unsigned int yourAddrLen = poll.getYourAddrLen();
unsigned int myPort = poll.getMyPort();
unsigned int length = poll.getLength();
@ -214,8 +211,7 @@ void CDCSHandler::process(CPollData& poll)
if (handler != NULL) {
if (handler->m_reflector.IsSameAs(reflector) &&
handler->m_repeater.IsSameAs(repeater) &&
handler->m_yourAddress.s_addr == yourAddress.s_addr &&
handler->m_yourPort == yourPort &&
CUDPReaderWriter::match(handler->m_yourAddr, yourAddr) &&
handler->m_myPort == myPort &&
handler->m_direction == DIR_OUTGOING &&
handler->m_linkState == DCS_LINKED &&
@ -225,8 +221,7 @@ void CDCSHandler::process(CPollData& poll)
handler->m_handler->writePoll(reply);
return;
} else if (handler->m_reflector.Left(LONG_CALLSIGN_LENGTH - 1U).IsSameAs(reflector.Left(LONG_CALLSIGN_LENGTH - 1U)) &&
handler->m_yourAddress.s_addr == yourAddress.s_addr &&
handler->m_yourPort == yourPort &&
CUDPReaderWriter::match(handler->m_yourAddr, yourAddr) &&
handler->m_myPort == myPort &&
handler->m_direction == DIR_INCOMING &&
handler->m_linkState == DCS_LINKED &&
@ -259,9 +254,9 @@ void CDCSHandler::process(CConnectData& connect)
}
// else if type == CT_LINK1 or type == CT_LINK2
in_addr yourAddr = connect.getYourAddr();
unsigned int yourAddrLen = connect.getYourAddrLen();
unsigned int myPort = connect.getMyPort();
sockaddr_storage yourAddr = connect.getYourAddr();
unsigned int yourAddrLen = connect.getYourAddrLen();
unsigned int myPort = connect.getMyPort();
wxString repeaterCallsign = connect.getRepeater();
wxString reflectorCallsign = connect.getReflector();
@ -269,9 +264,9 @@ void CDCSHandler::process(CConnectData& connect)
// Check that it isn't a duplicate
for (unsigned int i = 0U; i < m_maxReflectors; i++) {
if (m_reflectors[i] != NULL) {
if (m_reflectors[i]->m_direction == DIR_INCOMING &&
CUDPReaderWriter::match(m_yourAddr, yourAddr) &&
m_reflectors[i]->m_myPort == myPort &&
if (m_reflectors[i]->m_direction == DIR_INCOMING &&
CUDPReaderWriter::match(m_reflectors[i]->m_yourAddr, yourAddr) &&
m_reflectors[i]->m_myPort == myPort &&
m_reflectors[i]->m_repeater.IsSameAs(reflectorCallsign) &&
m_reflectors[i]->m_reflector.IsSameAs(repeaterCallsign))
return;
@ -282,7 +277,7 @@ void CDCSHandler::process(CConnectData& connect)
IReflectorCallback* handler = CRepeaterHandler::findDVRepeater(reflectorCallsign);
if (handler == NULL) {
wxLogMessage(wxT("DCS connect to unknown reflector %s from %s"), reflectorCallsign.c_str(), repeaterCallsign.c_str());
CConnectData reply(repeaterCallsign, reflectorCallsign, CT_NAK, connect.getYourAddress(), connect.getYourPort());
CConnectData reply(repeaterCallsign, reflectorCallsign, CT_NAK, connect.getYourAddr(), connect.getYourAddrLen());
m_incoming->writeConnect(reply);
return;
}
@ -313,7 +308,7 @@ void CDCSHandler::process(CConnectData& connect)
}
}
void CDCSHandler::link(IReflectorCallback* handler, const wxString& repeater, const wxString &gateway, const in_addr& address)
void CDCSHandler::link(IReflectorCallback* handler, const wxString& repeater, const wxString &gateway, const sockaddr_storage& addr, unsigned int addrLen)
{
for (unsigned int i = 0U; i < m_maxReflectors; i++) {
if (m_reflectors[i] != NULL) {
@ -326,7 +321,7 @@ void CDCSHandler::link(IReflectorCallback* handler, const wxString& repeater, co
if (protoHandler == NULL)
return;
CDCSHandler* dcs = new CDCSHandler(handler, gateway, repeater, protoHandler, address, DCS_PORT, DIR_OUTGOING);
CDCSHandler* dcs = new CDCSHandler(handler, gateway, repeater, protoHandler, addr, addrLen, DIR_OUTGOING);
bool found = false;
@ -339,7 +334,7 @@ void CDCSHandler::link(IReflectorCallback* handler, const wxString& repeater, co
}
if (found) {
CConnectData reply(m_gatewayType, repeater, gateway, CT_LINK1, address, DCS_PORT);
CConnectData reply(m_gatewayType, repeater, gateway, CT_LINK1, addr, addrLen);
protoHandler->writeConnect(reply);
} else {
wxLogError(wxT("No space to add new DCS link, ignoring"));
@ -457,7 +452,7 @@ void CDCSHandler::gatewayUpdate(const wxString& reflector, const wxString& addre
if (!address.IsEmpty()) {
// A new address, change the value
wxLogMessage(wxT("Changing IP address of DCS gateway or reflector %s to %s"), reflector->m_reflector.c_str(), address.c_str());
reflector->m_yourAddress.s_addr = ::inet_addr(address.mb_str());
CUDPReaderWriter::lookup(address, DCS_PORT, reflector->m_yourAddr, reflector->m_yourAddrLen);
} else {
wxLogMessage(wxT("IP address for DCS gateway or reflector %s has been removed"), reflector->m_reflector.c_str());
@ -627,11 +622,10 @@ void CDCSHandler::processInt(CAMBEData& data)
bool CDCSHandler::processInt(CConnectData& connect, CD_TYPE type)
{
sockaddr_storage yourAddr = connect.getYourAddr();
unsigned int yourAddrLen = connect.getYourAddrLen();
unsigned int myPort = connect.getMyPort();
wxString repeater = connect.getRepeater();
if (m_yourAddress.s_addr != yourAddress.s_addr || m_yourPort != yourPort || m_myPort != myPort)
if (!CUDPReaderWriter::match(m_yourAddr, yourAddr) || m_myPort != myPort)
return false;
switch (type) {

View file

@ -1,5 +1,5 @@
/*
* Copyright (C) 2012,2013 by Jonathan Naylor G4KLX
* Copyright (C) 2012,2013,2020 by Jonathan Naylor G4KLX
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@ -30,8 +30,8 @@ m_socket(addr, port),
m_type(DC_NONE),
m_buffer(NULL),
m_length(0U),
m_yourAddress(),
m_yourPort(0U),
m_yourAddr(),
m_yourAddrLen(0U),
m_myPort(port)
{
m_buffer = new unsigned char[BUFFER_LENGTH];
@ -61,7 +61,7 @@ bool CDCSProtocolHandler::writeData(const CAMBEData& data)
CUtils::dump(wxT("Sending Data"), buffer, length);
#endif
return m_socket.write(buffer, length, data.getYourAddress(), data.getYourPort());
return m_socket.write(buffer, length, data.getYourAddr(), data.getYourAddrLen());
}
bool CDCSProtocolHandler::writePoll(const CPollData& poll)
@ -73,7 +73,7 @@ bool CDCSProtocolHandler::writePoll(const CPollData& poll)
CUtils::dump(wxT("Sending Poll"), buffer, length);
#endif
return m_socket.write(buffer, length, poll.getYourAddress(), poll.getYourPort());
return m_socket.write(buffer, length, poll.getYourAddr(), poll.getYourAddrLen());
}
bool CDCSProtocolHandler::writeConnect(const CConnectData& connect)
@ -85,7 +85,7 @@ bool CDCSProtocolHandler::writeConnect(const CConnectData& connect)
CUtils::dump(wxT("Sending Connect"), buffer, length);
#endif
return m_socket.write(buffer, length, connect.getYourAddress(), connect.getYourPort());
return m_socket.write(buffer, length, connect.getYourAddr(), connect.getYourAddrLen());
}
DCS_TYPE CDCSProtocolHandler::read()
@ -104,7 +104,7 @@ bool CDCSProtocolHandler::readPackets()
m_type = DC_NONE;
// No more data?
int length = m_socket.read(m_buffer, BUFFER_LENGTH, m_yourAddress, m_yourPort);
int length = m_socket.read(m_buffer, BUFFER_LENGTH, m_yourAddr, m_yourAddrLen);
if (length <= 0)
return false;
@ -149,7 +149,7 @@ CAMBEData* CDCSProtocolHandler::readData()
CAMBEData* data = new CAMBEData;
bool res = data->setDCSData(m_buffer, m_length, m_yourAddress, m_yourPort, m_myPort);
bool res = data->setDCSData(m_buffer, m_length, m_yourAddr, m_yourAddrLen, m_myPort);
if (!res) {
delete data;
return NULL;
@ -165,7 +165,7 @@ CPollData* CDCSProtocolHandler::readPoll()
CPollData* poll = new CPollData;
bool res = poll->setDCSData(m_buffer, m_length, m_yourAddress, m_yourPort, m_myPort);
bool res = poll->setDCSData(m_buffer, m_length, m_yourAddr, m_yourAddrLen, m_myPort);
if (!res) {
delete poll;
return NULL;
@ -181,7 +181,7 @@ CConnectData* CDCSProtocolHandler::readConnect()
CConnectData* connect = new CConnectData;
bool res = connect->setDCSData(m_buffer, m_length, m_yourAddress, m_yourPort, m_myPort);
bool res = connect->setDCSData(m_buffer, m_length, m_yourAddr, m_yourAddrLen, m_myPort);
if (!res) {
delete connect;
return NULL;

View file

@ -1,5 +1,5 @@
/*
* Copyright (C) 2011,2013 by Jonathan Naylor G4KLX
* Copyright (C) 2011,2013,2020 by Jonathan Naylor G4KLX
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@ -46,12 +46,12 @@ CDDData::~CDDData()
delete[] m_frame;
}
bool CDDData::setIcomRepeaterData(const unsigned char *data, unsigned int length, const in_addr& yourAddress, unsigned int yourPort)
bool CDDData::setIcomRepeaterData(const unsigned char *data, unsigned int length, const sockaddr_storage& yourAddr, unsigned int yourAddrLen)
{
wxASSERT(data != NULL);
wxASSERT(length >= 29U);
bool ret = m_header.setIcomRepeaterData(data, length, true, yourAddress, yourPort);
bool ret = m_header.setIcomRepeaterData(data, length, true, yourAddr, yourAddrLen);
if (!ret)
return false;
@ -65,7 +65,7 @@ bool CDDData::setIcomRepeaterData(const unsigned char *data, unsigned int length
return true;
}
bool CDDData::setHBRepeaterData(const unsigned char *data, unsigned int length, const in_addr&, unsigned int)
bool CDDData::setHBRepeaterData(const unsigned char *data, unsigned int length, const sockaddr_storage&, unsigned int)
{
wxASSERT(data != NULL);
wxASSERT(length >= 60U);
@ -262,19 +262,19 @@ void CDDData::setRepeaters(const wxString& rpt1, const wxString& rpt2)
m_header.setRepeaters(rpt1, rpt2);
}
void CDDData::setDestination(const in_addr& address, unsigned int port)
void CDDData::setDestination(const sockaddr_storage& addr, unsigned int addrLen)
{
m_header.setDestination(address, port);
m_header.setDestination(addr, addrLen);
}
in_addr CDDData::getYourAddress() const
sockaddr_storage CDDData::getYourAddr() const
{
return m_header.getYourAddress();
return m_header.getYourAddr();
}
unsigned int CDDData::getYourPort() const
unsigned int CDDData::getYourAddrLen() const
{
return m_header.getYourPort();
return m_header.getYourAddrLen();
}
void CDDData::setEthernetFrame(const unsigned char *frame, unsigned int length)

View file

@ -1,5 +1,5 @@
/*
* Copyright (C) 2010-2015 by Jonathan Naylor G4KLX
* Copyright (C) 2010-2015,2020 by Jonathan Naylor G4KLX
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@ -37,12 +37,12 @@ CCallsignList* CDExtraHandler::m_whiteList = NULL;
CCallsignList* CDExtraHandler::m_blackList = NULL;
CDExtraHandler::CDExtraHandler(IReflectorCallback* handler, const wxString& reflector, const wxString& repeater, CDExtraProtocolHandler* protoHandler, const in_addr& address, unsigned int port, DIRECTION direction) :
CDExtraHandler::CDExtraHandler(IReflectorCallback* handler, const wxString& reflector, const wxString& repeater, CDExtraProtocolHandler* protoHandler, const sockaddr_storage& addr, unsigned int addrLen, DIRECTION direction) :
m_reflector(reflector.Clone()),
m_repeater(repeater.Clone()),
m_handler(protoHandler),
m_yourAddress(address),
m_yourPort(port),
m_yourAddr(addr),
m_yourAddrLen(addrLen),
m_direction(direction),
m_linkState(DEXTRA_LINKING),
m_destination(handler),
@ -58,7 +58,7 @@ m_header(NULL)
{
wxASSERT(protoHandler != NULL);
wxASSERT(handler != NULL);
wxASSERT(port > 0U);
wxASSERT(addrLen > 0U);
m_pollInactivityTimer.start();
@ -74,12 +74,12 @@ m_header(NULL)
}
}
CDExtraHandler::CDExtraHandler(CDExtraProtocolHandler* protoHandler, const wxString& reflector, const in_addr& address, unsigned int port, DIRECTION direction) :
CDExtraHandler::CDExtraHandler(CDExtraProtocolHandler* protoHandler, const wxString& reflector, const sockaddr_storage& addr, unsigned int addrLen, DIRECTION direction) :
m_reflector(reflector.Clone()),
m_repeater(),
m_handler(protoHandler),
m_yourAddress(address),
m_yourPort(port),
m_yourAddr(addr),
m_yourAddrLen(addrLen),
m_direction(direction),
m_linkState(DEXTRA_LINKING),
m_destination(NULL),
@ -94,7 +94,7 @@ m_inactivityTimer(1000U, NETWORK_TIMEOUT),
m_header(NULL)
{
wxASSERT(protoHandler != NULL);
wxASSERT(port > 0U);
wxASSERT(addrLen > 0U);
m_pollInactivityTimer.start();
@ -227,14 +227,12 @@ wxString CDExtraHandler::getDongles()
void CDExtraHandler::process(CHeaderData& header)
{
in_addr yourAddress = header.getYourAddress();
unsigned int yourPort = header.getYourPort();
sockaddr_storage yourAddr = header.getYourAddr();
for (unsigned int i = 0U; i < m_maxReflectors; i++) {
CDExtraHandler* reflector = m_reflectors[i];
if (reflector != NULL) {
if (reflector->m_yourAddress.s_addr == yourAddress.s_addr &&
reflector->m_yourPort == yourPort)
if (CUDPReaderWriter::match(reflector->m_yourAddr, yourAddr))
reflector->processInt(header);
}
}
@ -242,14 +240,12 @@ void CDExtraHandler::process(CHeaderData& header)
void CDExtraHandler::process(CAMBEData& data)
{
in_addr yourAddress = data.getYourAddress();
unsigned int yourPort = data.getYourPort();
sockaddr_storage yourAddr = data.getYourAddr();
for (unsigned int i = 0U; i < m_maxReflectors; i++) {
CDExtraHandler* reflector = m_reflectors[i];
if (reflector != NULL) {
if (reflector->m_yourAddress.s_addr == yourAddress.s_addr &&
reflector->m_yourPort == yourPort)
if (CUDPReaderWriter::match(reflector->m_yourAddr, yourAddr))
reflector->processInt(data);
}
}
@ -259,17 +255,16 @@ void CDExtraHandler::process(const CPollData& poll)
{
bool found = false;
wxString reflector = poll.getData1();
in_addr yourAddress = poll.getYourAddress();
unsigned int yourPort = poll.getYourPort();
wxString reflector = poll.getData1();
sockaddr_storage yourAddr = poll.getYourAddr();
unsigned int yourAddrLen = poll.getYourAddrLen();
// Check to see if we already have a link
for (unsigned int i = 0U; i < m_maxReflectors; i++) {
if (m_reflectors[i] != NULL) {
if (m_reflectors[i]->m_reflector.Left(LONG_CALLSIGN_LENGTH - 1U).IsSameAs(reflector.Left(LONG_CALLSIGN_LENGTH - 1U)) &&
m_reflectors[i]->m_yourAddress.s_addr == yourAddress.s_addr &&
m_reflectors[i]->m_yourPort == yourPort &&
m_reflectors[i]->m_linkState == DEXTRA_LINKED) {
CUDPReaderWriter::match(m_reflectors[i]->m_yourAddr, yourAddr) &&
m_reflectors[i]->m_linkState == DEXTRA_LINKED) {
m_reflectors[i]->m_pollInactivityTimer.start();
found = true;
}
@ -298,7 +293,7 @@ void CDExtraHandler::process(const CPollData& poll)
// An unmatched poll indicates the need for a new entry
wxLogMessage(wxT("New incoming DExtra Dongle from %s"), reflector.c_str());
CDExtraHandler* handler = new CDExtraHandler(m_incoming, reflector, yourAddress, yourPort, DIR_INCOMING);
CDExtraHandler* handler = new CDExtraHandler(m_incoming, reflector, yourAddr, yourAddrLen, DIR_INCOMING);
found = false;
@ -312,7 +307,7 @@ void CDExtraHandler::process(const CPollData& poll)
if (found) {
// Return the poll
CPollData poll(m_callsign, yourAddress, yourPort);
CPollData poll(m_callsign, yourAddr, yourAddrLen);
m_incoming->writePoll(poll);
} else {
wxLogError(wxT("No space to add new DExtra Dongle, ignoring"));
@ -339,8 +334,8 @@ void CDExtraHandler::process(CConnectData& connect)
}
// else if type == CT_LINK1 or type == CT_LINK2
in_addr yourAddress = connect.getYourAddress();
unsigned int yourPort = connect.getYourPort();
sockaddr_storage yourAddr = connect.getYourAddr();
unsigned int yourAddrLen = connect.getYourAddrLen();
wxString repeaterCallsign = connect.getRepeater();
@ -352,9 +347,8 @@ void CDExtraHandler::process(CConnectData& connect)
// Check that it isn't a duplicate
for (unsigned int i = 0U; i < m_maxReflectors; i++) {
if (m_reflectors[i] != NULL) {
if (m_reflectors[i]->m_direction == DIR_INCOMING &&
m_reflectors[i]->m_yourAddress.s_addr == yourAddress.s_addr &&
m_reflectors[i]->m_yourPort == yourPort &&
if (m_reflectors[i]->m_direction == DIR_INCOMING &&
CUDPReaderWriter::match(m_reflectors[i]->m_yourAddr, yourAddr) &&
m_reflectors[i]->m_repeater.IsSameAs(reflectorCallsign) &&
m_reflectors[i]->m_reflector.IsSameAs(repeaterCallsign))
return;
@ -365,7 +359,7 @@ void CDExtraHandler::process(CConnectData& connect)
IReflectorCallback* handler = CRepeaterHandler::findDVRepeater(reflectorCallsign);
if (handler == NULL) {
wxLogMessage(wxT("DExtra connect to unknown reflector %s from %s"), reflectorCallsign.c_str(), repeaterCallsign.c_str());
CConnectData reply(repeaterCallsign, reflectorCallsign, CT_NAK, yourAddress, yourPort);
CConnectData reply(repeaterCallsign, reflectorCallsign, CT_NAK, yourAddr, yourAddrLen);
m_incoming->writeConnect(reply);
return;
}
@ -373,7 +367,7 @@ void CDExtraHandler::process(CConnectData& connect)
// A new connect packet indicates the need for a new entry
wxLogMessage(wxT("New incoming DExtra link to %s from %s"), reflectorCallsign.c_str(), repeaterCallsign.c_str());
CDExtraHandler* dextra = new CDExtraHandler(handler, repeaterCallsign, reflectorCallsign, m_incoming, yourAddress, yourPort, DIR_INCOMING);
CDExtraHandler* dextra = new CDExtraHandler(handler, repeaterCallsign, reflectorCallsign, m_incoming, yourAddr, yourAddrLen, DIR_INCOMING);
bool found = false;
for (unsigned int i = 0U; i < m_maxReflectors; i++) {
@ -385,15 +379,15 @@ void CDExtraHandler::process(CConnectData& connect)
}
if (found) {
CConnectData reply(repeaterCallsign, reflectorCallsign, CT_ACK, yourAddress, yourPort);
CConnectData reply(repeaterCallsign, reflectorCallsign, CT_ACK, yourAddr, yourAddrLen);
m_incoming->writeConnect(reply);
wxString callsign = repeaterCallsign;
callsign.SetChar(LONG_CALLSIGN_LENGTH - 1U, wxT(' '));
CPollData poll(callsign, yourAddress, yourPort);
CPollData poll(callsign, yourAddr, yourAddrLen);
m_incoming->writePoll(poll);
} else {
CConnectData reply(repeaterCallsign, reflectorCallsign, CT_NAK, yourAddress, yourPort);
CConnectData reply(repeaterCallsign, reflectorCallsign, CT_NAK, yourAddr, yourAddrLen);
m_incoming->writeConnect(reply);
wxLogError(wxT("No space to add new DExtra repeater, ignoring"));
@ -401,13 +395,13 @@ void CDExtraHandler::process(CConnectData& connect)
}
}
void CDExtraHandler::link(IReflectorCallback* handler, const wxString& repeater, const wxString &gateway, const in_addr& address)
void CDExtraHandler::link(IReflectorCallback* handler, const wxString& repeater, const wxString &gateway, const sockaddr_storage& addr, unsigned int addrLen)
{
CDExtraProtocolHandler* protoHandler = m_pool->getHandler();
if (protoHandler == NULL)
return;
CDExtraHandler* dextra = new CDExtraHandler(handler, gateway, repeater, protoHandler, address, DEXTRA_PORT, DIR_OUTGOING);
CDExtraHandler* dextra = new CDExtraHandler(handler, gateway, repeater, protoHandler, addr, addrLen, DIR_OUTGOING);
bool found = false;
@ -420,7 +414,7 @@ void CDExtraHandler::link(IReflectorCallback* handler, const wxString& repeater,
}
if (found) {
CConnectData reply(repeater, gateway, CT_LINK1, address, DEXTRA_PORT);
CConnectData reply(repeater, gateway, CT_LINK1, addr, addrLen);
protoHandler->writeConnect(reply);
} else {
wxLogError(wxT("No space to add new DExtra link, ignoring"));
@ -441,7 +435,7 @@ void CDExtraHandler::unlink(IReflectorCallback* handler, const wxString& callsig
wxLogMessage(wxT("Removing outgoing DExtra link %s, %s"), reflector->m_repeater.c_str(), reflector->m_reflector.c_str());
if (reflector->m_linkState == DEXTRA_LINKING || reflector->m_linkState == DEXTRA_LINKED) {
CConnectData connect(reflector->m_repeater, reflector->m_yourAddress, reflector->m_yourPort);
CConnectData connect(reflector->m_repeater, reflector->m_yourAddr, reflector->m_yourAddrLen);
reflector->m_handler->writeConnect(connect);
reflector->m_linkState = DEXTRA_UNLINKING;
@ -456,7 +450,7 @@ void CDExtraHandler::unlink(IReflectorCallback* handler, const wxString& callsig
wxLogMessage(wxT("Removing DExtra link %s, %s"), reflector->m_repeater.c_str(), reflector->m_reflector.c_str());
if (reflector->m_linkState == DEXTRA_LINKING || reflector->m_linkState == DEXTRA_LINKED) {
CConnectData connect(reflector->m_repeater, reflector->m_yourAddress, reflector->m_yourPort);
CConnectData connect(reflector->m_repeater, reflector->m_yourAddr, reflector->m_yourAddrLen);
reflector->m_handler->writeConnect(connect);
reflector->m_linkState = DEXTRA_UNLINKING;
@ -502,7 +496,7 @@ void CDExtraHandler::unlink()
if (!reflector->m_repeater.IsEmpty()) {
wxLogMessage(wxT("Unlinking from DExtra reflector %s"), reflector->m_reflector.c_str());
CConnectData connect(reflector->m_repeater, reflector->m_yourAddress, reflector->m_yourPort);
CConnectData connect(reflector->m_repeater, reflector->m_yourAddr, reflector->m_yourAddrLen);
reflector->m_handler->writeConnect(connect);
reflector->m_linkState = DEXTRA_UNLINKING;
@ -539,7 +533,7 @@ void CDExtraHandler::gatewayUpdate(const wxString& reflector, const wxString& ad
if (!address.IsEmpty()) {
// A new address, change the value
wxLogMessage(wxT("Changing IP address of DExtra gateway or reflector %s to %s"), reflector->m_reflector.c_str(), address.c_str());
reflector->m_yourAddress.s_addr = ::inet_addr(address.mb_str());
CUDPReaderWriter::lookup(address, DEXTRA_PORT, reflector->m_yourAddr, reflector->m_yourAddrLen);
} else {
wxLogMessage(wxT("IP address for DExtra gateway or reflector %s has been removed"), reflector->m_reflector.c_str());
@ -728,11 +722,10 @@ void CDExtraHandler::processInt(CAMBEData& data)
bool CDExtraHandler::processInt(CConnectData& connect, CD_TYPE type)
{
in_addr yourAddress = connect.getYourAddress();
unsigned int yourPort = connect.getYourPort();
wxString repeater = connect.getRepeater();
sockaddr_storage yourAddr = connect.getYourAddr();
wxString repeater = connect.getRepeater();
if (m_yourAddress.s_addr != yourAddress.s_addr || m_yourPort != yourPort)
if (!CUDPReaderWriter::match(m_yourAddr, yourAddr))
return false;
switch (type) {
@ -823,7 +816,7 @@ bool CDExtraHandler::clockInt(unsigned int ms)
if (m_direction == DIR_OUTGOING) {
bool reconnect = m_destination->linkFailed(DP_DEXTRA, m_reflector, true);
if (reconnect) {
CConnectData reply(m_repeater, m_reflector, CT_LINK1, m_yourAddress, m_yourPort);
CConnectData reply(m_repeater, m_reflector, CT_LINK1, m_yourAddr, m_yourAddrLen);
m_handler->writeConnect(reply);
m_linkState = DEXTRA_LINKING;
m_tryTimer.start(1U);
@ -840,10 +833,10 @@ bool CDExtraHandler::clockInt(unsigned int ms)
if (!m_repeater.IsEmpty()) {
wxString callsign = m_repeater;
callsign.SetChar(LONG_CALLSIGN_LENGTH - 1U, wxT(' '));
CPollData poll(callsign, m_yourAddress, m_yourPort);
CPollData poll(callsign, m_yourAddr, m_yourAddrLen);
m_handler->writePoll(poll);
} else {
CPollData poll(m_callsign, m_yourAddress, m_yourPort);
CPollData poll(m_callsign, m_yourAddr, m_yourAddrLen);
m_handler->writePoll(poll);
}
}
@ -863,7 +856,7 @@ bool CDExtraHandler::clockInt(unsigned int ms)
if (m_linkState == DEXTRA_LINKING) {
if (m_tryTimer.isRunning() && m_tryTimer.hasExpired()) {
CConnectData reply(m_repeater, m_reflector, CT_LINK1, m_yourAddress, m_yourPort);
CConnectData reply(m_repeater, m_reflector, CT_LINK1, m_yourAddr, m_yourAddrLen);
m_handler->writeConnect(reply);
unsigned int timeout = calcBackoff();
@ -890,14 +883,14 @@ void CDExtraHandler::writeHeaderInt(IReflectorCallback* handler, CHeaderData& he
switch (m_direction) {
case DIR_OUTGOING:
if (m_destination == handler) {
header.setDestination(m_yourAddress, m_yourPort);
header.setDestination(m_yourAddr, m_yourAddrLen);
m_handler->writeHeader(header);
}
break;
case DIR_INCOMING:
if (m_repeater.IsEmpty() || m_destination == handler) {
header.setDestination(m_yourAddress, m_yourPort);
header.setDestination(m_yourAddr, m_yourAddrLen);
m_handler->writeHeader(header);
}
break;
@ -920,14 +913,14 @@ void CDExtraHandler::writeAMBEInt(IReflectorCallback* handler, CAMBEData& data,
switch (m_direction) {
case DIR_OUTGOING:
if (m_destination == handler) {
data.setDestination(m_yourAddress, m_yourPort);
data.setDestination(m_yourAddr, m_yourAddrLen);
m_handler->writeAMBE(data);
}
break;
case DIR_INCOMING:
if (m_repeater.IsEmpty() || m_destination == handler) {
data.setDestination(m_yourAddress, m_yourPort);
data.setDestination(m_yourAddr, m_yourAddrLen);
m_handler->writeAMBE(data);
}
break;

View file

@ -1,5 +1,5 @@
/*
* Copyright (C) 2010-2013 by Jonathan Naylor G4KLX
* Copyright (C) 2010-2013,2020 by Jonathan Naylor G4KLX
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@ -30,8 +30,8 @@ m_socket(addr, port),
m_type(DE_NONE),
m_buffer(NULL),
m_length(0U),
m_yourAddress(),
m_yourPort(0U),
m_yourAddr(),
m_yourAddrLen(0U),
m_myPort(port)
{
m_buffer = new unsigned char[BUFFER_LENGTH];
@ -62,7 +62,7 @@ bool CDExtraProtocolHandler::writeHeader(const CHeaderData& header)
#endif
for (unsigned int i = 0U; i < 5U; i++) {
bool res = m_socket.write(buffer, length, header.getYourAddress(), header.getYourPort());
bool res = m_socket.write(buffer, length, header.getYourAddr(), header.getYourAddrLen());
if (!res)
return false;
}
@ -79,7 +79,7 @@ bool CDExtraProtocolHandler::writeAMBE(const CAMBEData& data)
CUtils::dump(wxT("Sending Data"), buffer, length);
#endif
return m_socket.write(buffer, length, data.getYourAddress(), data.getYourPort());
return m_socket.write(buffer, length, data.getYourAddr(), data.getYourAddrLen());
}
bool CDExtraProtocolHandler::writePoll(const CPollData& poll)
@ -91,7 +91,7 @@ bool CDExtraProtocolHandler::writePoll(const CPollData& poll)
CUtils::dump(wxT("Sending Poll"), buffer, length);
#endif
return m_socket.write(buffer, length, poll.getYourAddress(), poll.getYourPort());
return m_socket.write(buffer, length, poll.getYourAddr(), poll.getYourAddrLen());
}
bool CDExtraProtocolHandler::writeConnect(const CConnectData& connect)
@ -104,7 +104,7 @@ bool CDExtraProtocolHandler::writeConnect(const CConnectData& connect)
#endif
for (unsigned int i = 0U; i < 2U; i++) {
bool res = m_socket.write(buffer, length, connect.getYourAddress(), connect.getYourPort());
bool res = m_socket.write(buffer, length, connect.getYourAddr(), connect.getYourAddrLen());
if (!res)
return false;
}
@ -128,7 +128,7 @@ bool CDExtraProtocolHandler::readPackets()
m_type = DE_NONE;
// No more data?
int length = m_socket.read(m_buffer, BUFFER_LENGTH, m_yourAddress, m_yourPort);
int length = m_socket.read(m_buffer, BUFFER_LENGTH, m_yourAddr, m_yourAddrLen);
if (length <= 0)
return false;
@ -165,7 +165,7 @@ CHeaderData* CDExtraProtocolHandler::readHeader()
CHeaderData* header = new CHeaderData;
// DExtra checksums are unreliable
bool res = header->setDExtraData(m_buffer, m_length, false, m_yourAddress, m_yourPort, m_myPort);
bool res = header->setDExtraData(m_buffer, m_length, false, m_yourAddr, m_yourAddrLen, m_myPort);
if (!res) {
delete header;
return NULL;
@ -181,7 +181,7 @@ CAMBEData* CDExtraProtocolHandler::readAMBE()
CAMBEData* data = new CAMBEData;
bool res = data->setDExtraData(m_buffer, m_length, m_yourAddress, m_yourPort, m_myPort);
bool res = data->setDExtraData(m_buffer, m_length, m_yourAddr, m_yourAddrLen, m_myPort);
if (!res) {
delete data;
return NULL;
@ -197,7 +197,7 @@ CPollData* CDExtraProtocolHandler::readPoll()
CPollData* poll = new CPollData;
bool res = poll->setDExtraData(m_buffer, m_length, m_yourAddress, m_yourPort, m_myPort);
bool res = poll->setDExtraData(m_buffer, m_length, m_yourAddr, m_yourAddrLen, m_myPort);
if (!res) {
delete poll;
return NULL;
@ -213,7 +213,7 @@ CConnectData* CDExtraProtocolHandler::readConnect()
CConnectData* connect = new CConnectData;
bool res = connect->setDExtraData(m_buffer, m_length, m_yourAddress, m_yourPort, m_myPort);
bool res = connect->setDExtraData(m_buffer, m_length, m_yourAddr, m_yourAddrLen, m_myPort);
if (!res) {
delete connect;
return NULL;

View file

@ -1,5 +1,5 @@
/*
* Copyright (C) 2010-2015,2018,2019 by Jonathan Naylor G4KLX
* Copyright (C) 2010-2015,2018,2019,2020 by Jonathan Naylor G4KLX
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@ -244,13 +244,14 @@ bool CDPlusAuthenticator::poll(const wxString& callsign, const wxString& hostnam
buffer[45U] = '5';
buffer[46U] = '7';
in_addr address = socket.lookup(hostname);
if (address.s_addr == INADDR_NONE) {
sockaddr_storage addr;
unsigned int addrLen;
if (CUDPReaderWriter::lookup(hostname, port, addr, addrLen) != 0) {
socket.close();
return false;
}
ret = socket.write(buffer, 56U, address, port);
ret = socket.write(buffer, 56U, addr, addrLen);
socket.close();

View file

@ -1,5 +1,5 @@
/*
* Copyright (C) 2010-2015 by Jonathan Naylor G4KLX
* Copyright (C) 2010-2015,2020 by Jonathan Naylor G4KLX
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@ -41,13 +41,13 @@ CCallsignList* CDPlusHandler::m_whiteList = NULL;
CCallsignList* CDPlusHandler::m_blackList = NULL;
CDPlusHandler::CDPlusHandler(IReflectorCallback* handler, const wxString& repeater, const wxString& reflector, CDPlusProtocolHandler* protoHandler, const in_addr& address, unsigned int port) :
CDPlusHandler::CDPlusHandler(IReflectorCallback* handler, const wxString& repeater, const wxString& reflector, CDPlusProtocolHandler* protoHandler, const sockaddr_storage& addr, unsigned int addrLen) :
m_repeater(repeater.Clone()),
m_callsign(m_dplusLogin.Clone()),
m_reflector(reflector.Clone()),
m_handler(protoHandler),
m_yourAddress(address),
m_yourPort(port),
m_yourAddr(addr),
m_yourAddrLen(addrLen),
m_myPort(0U),
m_direction(DIR_OUTGOING),
m_linkState(DPLUS_LINKING),
@ -64,7 +64,7 @@ m_header(NULL)
{
wxASSERT(protoHandler != NULL);
wxASSERT(handler != NULL);
wxASSERT(port > 0U);
wxASSERT(addrLen > 0U);
m_myPort = protoHandler->getPort();
@ -78,13 +78,13 @@ m_header(NULL)
m_callsign.SetChar(LONG_CALLSIGN_LENGTH - 1U, band);
}
CDPlusHandler::CDPlusHandler(CDPlusProtocolHandler* protoHandler, const in_addr& address, unsigned int port) :
CDPlusHandler::CDPlusHandler(CDPlusProtocolHandler* protoHandler, const sockaddr_storage& addr, unsigned int addrLen) :
m_repeater(),
m_callsign(),
m_reflector(),
m_handler(protoHandler),
m_yourAddress(address),
m_yourPort(port),
m_yourAddr(addr),
m_yourAddrLen(addrLen),
m_myPort(0U),
m_direction(DIR_INCOMING),
m_linkState(DPLUS_LINKING),
@ -100,7 +100,7 @@ m_inactivityTimer(1000U, NETWORK_TIMEOUT),
m_header(NULL)
{
wxASSERT(protoHandler != NULL);
wxASSERT(port > 0U);
wxASSERT(addrLen > 0U);
m_myPort = protoHandler->getPort();
@ -217,17 +217,15 @@ wxString CDPlusHandler::getDongles()
void CDPlusHandler::process(CHeaderData& header)
{
in_addr yourAddress = header.getYourAddress();
unsigned int yourPort = header.getYourPort();
unsigned int myPort = header.getMyPort();
sockaddr_storage yourAddr = header.getYourAddr();
unsigned int myPort = header.getMyPort();
for (unsigned int i = 0U; i < m_maxReflectors; i++) {
CDPlusHandler* reflector = m_reflectors[i];
if (reflector != NULL) {
if (reflector->m_yourAddress.s_addr == yourAddress.s_addr &&
reflector->m_yourPort == yourPort &&
reflector->m_myPort == myPort) {
if (CUDPReaderWriter::match(reflector->m_yourAddr, yourAddr) &&
reflector->m_myPort == myPort) {
reflector->processInt(header);
return;
}
@ -237,17 +235,15 @@ void CDPlusHandler::process(CHeaderData& header)
void CDPlusHandler::process(CAMBEData& data)
{
in_addr yourAddress = data.getYourAddress();
unsigned int yourPort = data.getYourPort();
unsigned int myPort = data.getMyPort();
sockaddr_storage yourAddr = data.getYourAddr();
unsigned int myPort = data.getMyPort();
for (unsigned int i = 0U; i < m_maxReflectors; i++) {
CDPlusHandler* reflector = m_reflectors[i];
if (reflector != NULL) {
if (reflector->m_yourAddress.s_addr == yourAddress.s_addr &&
reflector->m_yourPort == yourPort &&
reflector->m_myPort == myPort) {
if (CUDPReaderWriter::match(reflector->m_yourAddr, yourAddr) &&
reflector->m_myPort == myPort) {
reflector->processInt(data);
return;
}
@ -257,17 +253,15 @@ void CDPlusHandler::process(CAMBEData& data)
void CDPlusHandler::process(const CPollData& poll)
{
in_addr yourAddress = poll.getYourAddress();
unsigned int yourPort = poll.getYourPort();
unsigned int myPort = poll.getMyPort();
sockaddr_storage yourAddr = poll.getYourAddr();
unsigned int myPort = poll.getMyPort();
for (unsigned int i = 0U; i < m_maxReflectors; i++) {
CDPlusHandler* reflector = m_reflectors[i];
if (reflector != NULL) {
if (reflector->m_yourAddress.s_addr == yourAddress.s_addr &&
reflector->m_yourPort == yourPort &&
reflector->m_myPort == myPort) {
if (CUDPReaderWriter::match(reflector->m_yourAddr, yourAddr) &&
reflector->m_myPort == myPort) {
reflector->m_pollInactivityTimer.start();
return;
}
@ -280,18 +274,17 @@ void CDPlusHandler::process(const CPollData& poll)
void CDPlusHandler::process(CConnectData& connect)
{
CD_TYPE type = connect.getType();
in_addr yourAddress = connect.getYourAddress();
unsigned int yourPort = connect.getYourPort();
unsigned int myPort = connect.getMyPort();
CD_TYPE type = connect.getType();
sockaddr_storage yourAddr = connect.getYourAddr();
unsigned int yourAddrLen = connect.getYourAddrLen();
unsigned int myPort = connect.getMyPort();
for (unsigned int i = 0U; i < m_maxReflectors; i++) {
CDPlusHandler* reflector = m_reflectors[i];
if (reflector != NULL) {
if (reflector->m_yourAddress.s_addr == yourAddress.s_addr &&
reflector->m_yourPort == yourPort &&
reflector->m_myPort == myPort) {
if (CUDPReaderWriter::match(reflector->m_yourAddr, yourAddr) &&
reflector->m_myPort == myPort) {
bool res = m_reflectors[i]->processInt(connect, type);
if (res) {
delete m_reflectors[i];
@ -306,9 +299,8 @@ void CDPlusHandler::process(CConnectData& connect)
CDPlusHandler* reflector = m_reflectors[i];
if (reflector != NULL) {
if (reflector->m_yourAddress.s_addr == yourAddress.s_addr &&
reflector->m_yourPort == yourPort &&
reflector->m_myPort == myPort)
if (CUDPReaderWriter::match(reflector->m_yourAddr, yourAddr) &&
reflector->m_myPort == myPort)
return;
}
}
@ -332,7 +324,7 @@ void CDPlusHandler::process(CConnectData& connect)
if (count >= m_maxDongles)
return;
CDPlusHandler* dplus = new CDPlusHandler(m_incoming, yourAddress, yourPort);
CDPlusHandler* dplus = new CDPlusHandler(m_incoming, yourAddr, yourAddrLen);
bool found = false;
@ -345,7 +337,7 @@ void CDPlusHandler::process(CConnectData& connect)
}
if (found) {
CConnectData connect(CT_LINK1, yourAddress, yourPort);
CConnectData connect(CT_LINK1, yourAddr, yourAddrLen);
m_incoming->writeConnect(connect);
} else {
wxLogError(wxT("No space to add new D-Plus dongle, ignoring"));
@ -353,13 +345,13 @@ void CDPlusHandler::process(CConnectData& connect)
}
}
void CDPlusHandler::link(IReflectorCallback* handler, const wxString& repeater, const wxString &gateway, const in_addr& address)
void CDPlusHandler::link(IReflectorCallback* handler, const wxString& repeater, const wxString &gateway, const sockaddr_storage& addr, unsigned int addrLen)
{
CDPlusProtocolHandler* protoHandler = m_pool->getHandler();
if (protoHandler == NULL)
return;
CDPlusHandler* dplus = new CDPlusHandler(handler, repeater, gateway, protoHandler, address, DPLUS_PORT);
CDPlusHandler* dplus = new CDPlusHandler(handler, repeater, gateway, protoHandler, addr, addrLen);
bool found = false;
@ -372,7 +364,7 @@ void CDPlusHandler::link(IReflectorCallback* handler, const wxString& repeater,
}
if (found) {
CConnectData connect(CT_LINK1, address, DPLUS_PORT);
CConnectData connect(CT_LINK1, addr, addrLen);
protoHandler->writeConnect(connect);
m_stateChange = true;
} else {
@ -409,7 +401,7 @@ void CDPlusHandler::unlink(IReflectorCallback* handler, const wxString& callsign
wxLogMessage(wxT("Removing outgoing D-Plus link %s, %s"), reflector->m_repeater.c_str(), reflector->m_reflector.c_str());
if (reflector->m_linkState == DPLUS_LINKING || reflector->m_linkState == DPLUS_LINKED) {
CConnectData connect(CT_UNLINK, reflector->m_yourAddress, DPLUS_PORT);
CConnectData connect(CT_UNLINK, reflector->m_yourAddr, reflector->m_yourAddrLen);
reflector->m_handler->writeConnect(connect);
reflector->m_handler->writeConnect(connect);
@ -427,7 +419,7 @@ void CDPlusHandler::unlink(IReflectorCallback* handler, const wxString& callsign
wxLogMessage(wxT("Removing D-Plus link %s, %s"), reflector->m_repeater.c_str(), reflector->m_reflector.c_str());
if (reflector->m_linkState == DPLUS_LINKING || reflector->m_linkState == DPLUS_LINKED) {
CConnectData connect(CT_UNLINK, reflector->m_yourAddress, DPLUS_PORT);
CConnectData connect(CT_UNLINK, reflector->m_yourAddr, reflector->m_yourAddrLen);
reflector->m_handler->writeConnect(connect);
reflector->m_handler->writeConnect(connect);
@ -472,7 +464,7 @@ void CDPlusHandler::unlink()
if (!reflector->m_reflector.IsEmpty())
wxLogMessage(wxT("Unlinking from D-Plus reflector or dongle %s"), reflector->m_reflector.c_str());
CConnectData connect(CT_UNLINK, reflector->m_yourAddress, reflector->m_yourPort);
CConnectData connect(CT_UNLINK, reflector->m_yourAddr, reflector->m_yourAddrLen);
reflector->m_handler->writeConnect(connect);
reflector->m_handler->writeConnect(connect);
reflector->m_tryTimer.start(1U);
@ -511,7 +503,7 @@ void CDPlusHandler::gatewayUpdate(const wxString& gateway, const wxString& addre
if (!address.IsEmpty()) {
// A new address, change the value
wxLogMessage(wxT("Changing IP address of D-Plus gateway or reflector %s to %s"), gatewayBase.c_str(), address.c_str());
reflector->m_yourAddress.s_addr = ::inet_addr(address.mb_str());
CUDPReaderWriter::lookup(address, DPLUS_PORT, reflector->m_yourAddr, reflector->m_yourAddrLen);
} else {
wxLogMessage(wxT("IP address for D-Plus gateway or reflector %s has been removed"), gatewayBase.c_str());
@ -689,7 +681,7 @@ bool CDPlusHandler::processInt(CConnectData& connect, CD_TYPE type)
if (m_linkState == DPLUS_LINKING) {
wxLogMessage(wxT("D-Plus NAK message received from %s"), m_reflector.c_str());
m_destination->linkRefused(DP_DPLUS, m_reflector);
CConnectData reply(CT_UNLINK, connect.getYourAddress(), connect.getYourPort());
CConnectData reply(CT_UNLINK, connect.getYourAddr(), connect.getYourAddrLen());
m_handler->writeConnect(reply);
m_tryTimer.stop();
}
@ -705,7 +697,7 @@ bool CDPlusHandler::processInt(CConnectData& connect, CD_TYPE type)
return true;
case CT_LINK1: {
CConnectData reply(m_dplusLogin, CT_LINK2, connect.getYourAddress(), connect.getYourPort());
CConnectData reply(m_dplusLogin, CT_LINK2, connect.getYourAddr(), connect.getYourAddrLen());
m_handler->writeConnect(reply);
m_tryTimer.stop();
}
@ -721,7 +713,7 @@ bool CDPlusHandler::processInt(CConnectData& connect, CD_TYPE type)
case CT_LINK2: {
m_reflector = connect.getRepeater();
wxLogMessage(wxT("D-Plus dongle link to %s has started"), m_reflector.c_str());
CConnectData reply(CT_ACK, m_yourAddress, m_yourPort);
CConnectData reply(CT_ACK, m_yourAddr, m_yourAddrLen);
m_handler->writeConnect(reply);
m_linkState = DPLUS_LINKED;
m_stateChange = true;
@ -781,7 +773,7 @@ bool CDPlusHandler::clockInt(unsigned int ms)
if (m_direction == DIR_OUTGOING) {
bool reconnect = m_destination->linkFailed(DP_DPLUS, m_reflector, true);
if (reconnect) {
CConnectData connect(CT_LINK1, m_yourAddress, DPLUS_PORT);
CConnectData connect(CT_LINK1, m_yourAddr, m_yourAddrLen);
m_handler->writeConnect(connect);
m_linkState = DPLUS_LINKING;
m_tryTimer.start(1U);
@ -794,7 +786,7 @@ bool CDPlusHandler::clockInt(unsigned int ms)
}
if (m_pollTimer.isRunning() && m_pollTimer.hasExpired()) {
CPollData poll(m_yourAddress, m_yourPort);
CPollData poll(m_yourAddr, m_yourAddrLen);
m_handler->writePoll(poll);
m_pollTimer.start();
@ -803,13 +795,13 @@ bool CDPlusHandler::clockInt(unsigned int ms)
if (m_tryTimer.isRunning() && m_tryTimer.hasExpired()) {
switch (m_linkState) {
case DPLUS_LINKING: {
CConnectData connect(CT_LINK1, m_yourAddress, DPLUS_PORT);
CConnectData connect(CT_LINK1, m_yourAddr, m_yourAddrLen);
m_handler->writeConnect(connect);
}
break;
case DPLUS_UNLINKING: {
CConnectData connect(CT_UNLINK, m_yourAddress, m_yourPort);
CConnectData connect(CT_UNLINK, m_yourAddr, m_yourAddrLen);
m_handler->writeConnect(connect);
m_handler->writeConnect(connect);
}
@ -854,13 +846,13 @@ void CDPlusHandler::writeHeaderInt(IReflectorCallback* handler, CHeaderData& hea
case DIR_OUTGOING:
if (m_destination == handler) {
header.setRepeaters(m_callsign, m_reflector);
header.setDestination(m_yourAddress, m_yourPort);
header.setDestination(m_yourAddr, m_yourAddrLen);
m_handler->writeHeader(header);
}
break;
case DIR_INCOMING:
header.setDestination(m_yourAddress, m_yourPort);
header.setDestination(m_yourAddr, m_yourAddrLen);
m_handler->writeHeader(header);
break;
}
@ -881,13 +873,13 @@ void CDPlusHandler::writeAMBEInt(IReflectorCallback* handler, CAMBEData& data, D
switch (m_direction) {
case DIR_OUTGOING:
if (m_destination == handler) {
data.setDestination(m_yourAddress, m_yourPort);
data.setDestination(m_yourAddr, m_yourAddrLen);
m_handler->writeAMBE(data);
}
break;
case DIR_INCOMING:
data.setDestination(m_yourAddress, m_yourPort);
data.setDestination(m_yourAddr, m_yourAddrLen);
m_handler->writeAMBE(data);
break;
}

View file

@ -1,5 +1,5 @@
/*
* Copyright (C) 2010-2013 by Jonathan Naylor G4KLX
* Copyright (C) 2010-2013,2020 by Jonathan Naylor G4KLX
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@ -30,8 +30,8 @@ m_socket(addr, port),
m_type(DP_NONE),
m_buffer(NULL),
m_length(0U),
m_yourAddress(),
m_yourPort(0U),
m_yourAddr(),
m_yourAddrLen(0U),
m_myPort(port)
{
m_buffer = new unsigned char[BUFFER_LENGTH];
@ -62,7 +62,7 @@ bool CDPlusProtocolHandler::writeHeader(const CHeaderData& header)
#endif
for (unsigned int i = 0U; i < 5U; i++) {
bool res = m_socket.write(buffer, length, header.getYourAddress(), header.getYourPort());
bool res = m_socket.write(buffer, length, header.getYourAddr(), header.getYourAddrLen());
if (!res)
return false;
}
@ -79,7 +79,7 @@ bool CDPlusProtocolHandler::writeAMBE(const CAMBEData& data)
CUtils::dump(wxT("Sending Data"), buffer, length);
#endif
return m_socket.write(buffer, length, data.getYourAddress(), data.getYourPort());
return m_socket.write(buffer, length, data.getYourAddr(), data.getYourAddrLen());
}
bool CDPlusProtocolHandler::writePoll(const CPollData& poll)
@ -91,7 +91,7 @@ bool CDPlusProtocolHandler::writePoll(const CPollData& poll)
CUtils::dump(wxT("Sending Poll"), buffer, length);
#endif
return m_socket.write(buffer, length, poll.getYourAddress(), poll.getYourPort());
return m_socket.write(buffer, length, poll.getYourAddr(), poll.getYourAddrLen());
}
bool CDPlusProtocolHandler::writeConnect(const CConnectData& connect)
@ -103,7 +103,7 @@ bool CDPlusProtocolHandler::writeConnect(const CConnectData& connect)
CUtils::dump(wxT("Sending Connect"), buffer, length);
#endif
return m_socket.write(buffer, length, connect.getYourAddress(), connect.getYourPort());
return m_socket.write(buffer, length, connect.getYourAddr(), connect.getYourAddrLen());
}
DPLUS_TYPE CDPlusProtocolHandler::read()
@ -122,7 +122,7 @@ bool CDPlusProtocolHandler::readPackets()
m_type = DP_NONE;
// No more data?
int length = m_socket.read(m_buffer, BUFFER_LENGTH, m_yourAddress, m_yourPort);
int length = m_socket.read(m_buffer, BUFFER_LENGTH, m_yourAddr, m_yourAddrLen);
if (length <= 0)
return false;
@ -170,7 +170,7 @@ CHeaderData* CDPlusProtocolHandler::readHeader()
CHeaderData* header = new CHeaderData;
// DPlus checksums are unreliable
bool res = header->setDPlusData(m_buffer, m_length, false, m_yourAddress, m_yourPort, m_myPort);
bool res = header->setDPlusData(m_buffer, m_length, false, m_yourAddr, m_yourAddrLen, m_myPort);
if (!res) {
delete header;
return NULL;
@ -186,7 +186,7 @@ CAMBEData* CDPlusProtocolHandler::readAMBE()
CAMBEData* data = new CAMBEData;
bool res = data->setDPlusData(m_buffer, m_length, m_yourAddress, m_yourPort, m_myPort);
bool res = data->setDPlusData(m_buffer, m_length, m_yourAddr, m_yourAddrLen, m_myPort);
if (!res) {
delete data;
return NULL;
@ -202,7 +202,7 @@ CPollData* CDPlusProtocolHandler::readPoll()
CPollData* poll = new CPollData;
bool res = poll->setDPlusData(m_buffer, m_length, m_yourAddress, m_yourPort, m_myPort);
bool res = poll->setDPlusData(m_buffer, m_length, m_yourAddr, m_yourAddrLen, m_myPort);
if (!res) {
delete poll;
return NULL;
@ -218,7 +218,7 @@ CConnectData* CDPlusProtocolHandler::readConnect()
CConnectData* connect = new CConnectData;
bool res = connect->setDPlusData(m_buffer, m_length, m_yourAddress, m_yourPort, m_myPort);
bool res = connect->setDPlusData(m_buffer, m_length, m_yourAddr, m_yourAddrLen, m_myPort);
if (!res) {
delete connect;
return NULL;

View file

@ -1,5 +1,5 @@
/*
* Copyright (C) 2013 by Jonathan Naylor G4KLX
* Copyright (C) 2013,2020 by Jonathan Naylor G4KLX
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@ -39,7 +39,7 @@ bool CDummyRepeaterProtocolHandler::writeHeader(CHeaderData& header)
unsigned char buffer[50U];
unsigned int length = header.getHBRepeaterData(buffer, 50U, true);
wxLogMessage(wxT("Sending Header to port: %u, id: %04X"), header.getYourPort(), header.getId());
wxLogMessage(wxT("Sending Header, id: %04X"), header.getId());
CUtils::dump(wxT("Data"), buffer + 8U, length - 8U);
@ -51,7 +51,7 @@ bool CDummyRepeaterProtocolHandler::writeAMBE(CAMBEData& data)
unsigned char buffer[30U];
unsigned int length = data.getHBRepeaterData(buffer, 30U);
wxLogMessage(wxT("Sending AMBE to port: %u, seq: %02X, id: %04X"), data.getYourPort(), data.getSeq(), data.getId());
wxLogMessage(wxT("Sending AMBE, seq: %02X, id: %04X"), data.getSeq(), data.getId());
CUtils::dump(wxT("Data"), buffer + 9U, length - 9U);

View file

@ -1,5 +1,5 @@
/*
* Copyright (C) 2010-2014 by Jonathan Naylor G4KLX
* Copyright (C) 2010-2014,2020 by Jonathan Naylor G4KLX
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@ -29,9 +29,10 @@ CG2ProtocolHandler* CG2Handler::m_handler = NULL;
CHeaderLogger* CG2Handler::m_headerLogger = NULL;
CG2Handler::CG2Handler(CRepeaterHandler* repeater, const in_addr& address, unsigned int id) :
CG2Handler::CG2Handler(CRepeaterHandler* repeater, const sockaddr_storage& addr, unsigned int addrLen, unsigned int id) :
m_repeater(repeater),
m_address(address),
m_addr(addr),
m_addrLen(addrLen),
m_id(id),
m_inactivityTimer(1000U, NETWORK_TIMEOUT)
{
@ -91,8 +92,9 @@ void CG2Handler::process(CHeaderData& header)
if (m_maxRoutes == 0U)
return;
in_addr address = header.getYourAddress();
unsigned int id = header.getId();
sockaddr_storage addr = header.getYourAddr();
unsigned int addrLen = header.getYourAddrLen();
unsigned int id = header.getId();
for (unsigned int i = 0U; i < m_maxRoutes; i++) {
CG2Handler* route = m_routes[i];
@ -110,7 +112,7 @@ void CG2Handler::process(CHeaderData& header)
return; // Not found, ignore
}
CG2Handler* route = new CG2Handler(repeater, address, id);
CG2Handler* route = new CG2Handler(repeater, addr, addrLen, id);
for (unsigned int i = 0U; i < m_maxRoutes; i++) {
if (m_routes[i] == NULL) {

View file

@ -1,5 +1,5 @@
/*
* Copyright (C) 2010,2011,2013 by Jonathan Naylor G4KLX
* Copyright (C) 2010,2011,2013,2020 by Jonathan Naylor G4KLX
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@ -30,8 +30,8 @@ m_socket(addr, port),
m_type(GT_NONE),
m_buffer(NULL),
m_length(0U),
m_address(),
m_port(0U)
m_addr(),
m_addrLen(0U)
{
m_buffer = new unsigned char[BUFFER_LENGTH];
}
@ -56,7 +56,7 @@ bool CG2ProtocolHandler::writeHeader(const CHeaderData& header)
#endif
for (unsigned int i = 0U; i < 5U; i++) {
bool res = m_socket.write(buffer, length, header.getYourAddress(), header.getYourPort());
bool res = m_socket.write(buffer, length, header.getYourAddr(), header.getYourAddrLen());
if (!res)
return false;
}
@ -73,7 +73,7 @@ bool CG2ProtocolHandler::writeAMBE(const CAMBEData& data)
CUtils::dump(wxT("Sending Data"), buffer, length);
#endif
return m_socket.write(buffer, length, data.getYourAddress(), data.getYourPort());
return m_socket.write(buffer, length, data.getYourAddr(), data.getYourAddrLen());
}
G2_TYPE CG2ProtocolHandler::read()
@ -92,7 +92,7 @@ bool CG2ProtocolHandler::readPackets()
m_type = GT_NONE;
// No more data?
int length = m_socket.read(m_buffer, BUFFER_LENGTH, m_address, m_port);
int length = m_socket.read(m_buffer, BUFFER_LENGTH, m_addr, m_addrLen);
if (length <= 0)
return false;
@ -119,7 +119,7 @@ CHeaderData* CG2ProtocolHandler::readHeader()
CHeaderData* header = new CHeaderData;
// G2 checksums are unreliable
bool res = header->setG2Data(m_buffer, m_length, false, m_address, m_port);
bool res = header->setG2Data(m_buffer, m_length, false, m_addr, m_addrLen);
if (!res) {
delete header;
return NULL;
@ -135,7 +135,7 @@ CAMBEData* CG2ProtocolHandler::readAMBE()
CAMBEData* data = new CAMBEData;
bool res = data->setG2Data(m_buffer, m_length, m_address, m_port);
bool res = data->setG2Data(m_buffer, m_length, m_addr, m_addrLen);
if (!res) {
delete data;
return NULL;
@ -150,11 +150,13 @@ void CG2ProtocolHandler::traverseNat(const wxString& address)
unsigned char buffer[1];
::memset(buffer, 0, 1);
in_addr addr = CUDPReaderWriter::lookup(address);
sockaddr_storage addr;
unsigned int addrLen;
CUDPReaderWriter::lookup(address, G2_DV_PORT, addr, addrLen);
//wxLogError(wxT("Punching hole to %s"), address.mb_str());
m_socket.write(buffer, 1, addr, G2_DV_PORT);
m_socket.write(buffer, 1, addr, addrLen);
}
#endif

View file

@ -1,5 +1,5 @@
/*
* Copyright (C) 2010,2011,2012 by Jonathan Naylor G4KLX
* Copyright (C) 2010,2011,2012,2020 by Jonathan Naylor G4KLX
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@ -18,6 +18,8 @@
#include "GatewayCache.h"
#include "UDPReaderWriter.h"
const unsigned int CACHE_SIZE = 500U;
CGatewayCache::CGatewayCache() :
@ -40,15 +42,31 @@ void CGatewayCache::update(const wxString& gateway, const wxString& address, DST
{
CGatewayRecord* rec = m_cache[gateway];
in_addr addr_in;
addr_in.s_addr = ::inet_addr(address.mb_str());
sockaddr_storage addr;
unsigned int addrLen;
switch (protocol) {
case DP_LOOPBACK:
case DP_DCS:
CUDPReaderWriter::lookup(address, DCS_PORT, addr, addrLen);
break;
case DP_DPLUS:
CUDPReaderWriter::lookup(address, DPLUS_PORT, addr, addrLen);
break;
case DP_DEXTRA:
CUDPReaderWriter::lookup(address, DEXTRA_PORT, addr, addrLen);
break;
default:
CUDPReaderWriter::lookup(address, G2_DV_PORT, addr, addrLen);
break;
}
if (rec == NULL)
// A brand new record is needed
m_cache[gateway] = new CGatewayRecord(gateway, addr_in, protocol, addrLock, protoLock);
m_cache[gateway] = new CGatewayRecord(gateway, addr, addrLen, protocol, addrLock, protoLock);
else
// Update an existing record
rec->setData(addr_in, protocol, addrLock, protoLock);
rec->setData(addr, addrLen, protocol, addrLock, protoLock);
}
unsigned int CGatewayCache::getCount() const

View file

@ -1,5 +1,5 @@
/*
* Copyright (C) 2010-2013 by Jonathan Naylor G4KLX
* Copyright (C) 2010-2013,2020 by Jonathan Naylor G4KLX
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@ -29,8 +29,8 @@ m_socket(address, port),
m_type(RT_NONE),
m_buffer(NULL),
m_length(0U),
m_address(),
m_port(0U)
m_addr(),
m_addrLen(0U)
{
wxASSERT(!address.IsEmpty());
wxASSERT(port > 0U);
@ -57,7 +57,7 @@ bool CHBRepeaterProtocolHandler::writeHeader(CHeaderData& header)
CUtils::dump(wxT("Sending Header"), buffer, length);
return true;
#else
return m_socket.write(buffer, length, header.getYourAddress(), header.getYourPort());
return m_socket.write(buffer, length, header.getYourAddr(), header.getYourAddrLen());
#endif
}
@ -70,7 +70,7 @@ bool CHBRepeaterProtocolHandler::writeAMBE(CAMBEData& data)
CUtils::dump(wxT("Sending Data"), buffer, length);
return true;
#else
return m_socket.write(buffer, length, data.getYourAddress(), data.getYourPort());
return m_socket.write(buffer, length, data.getYourAddr(), data.getYourAddrLen());
#endif
}
@ -83,7 +83,7 @@ bool CHBRepeaterProtocolHandler::writeDD(CDDData& data)
CUtils::dump(wxT("Sending DD Data"), buffer, length);
return true;
#else
return m_socket.write(buffer, length, data.getYourAddress(), data.getYourPort());
return m_socket.write(buffer, length, data.getYourAddr(), data.getYourAddrLen());
#endif
}
@ -96,7 +96,7 @@ bool CHBRepeaterProtocolHandler::writeText(CTextData& text)
CUtils::dump(wxT("Sending Text"), buffer, length);
return true;
#else
return m_socket.write(buffer, length, text.getAddress(), text.getPort());
return m_socket.write(buffer, length, text.getAddr(), text.getAddrLen());
#endif
}
@ -109,7 +109,7 @@ bool CHBRepeaterProtocolHandler::writeStatus(CStatusData& status)
CUtils::dump(wxT("Sending Status"), buffer, length);
return true;
#else
return m_socket.write(buffer, length, status.getAddress(), status.getPort());
return m_socket.write(buffer, length, status.getAddr(), status.getAddrLen());
#endif
}
@ -129,7 +129,7 @@ bool CHBRepeaterProtocolHandler::readPackets()
m_type = RT_NONE;
// No more data?
int length = m_socket.read(m_buffer, BUFFER_LENGTH, m_address, m_port);
int length = m_socket.read(m_buffer, BUFFER_LENGTH, m_addr, m_addrLen);
if (length <= 0)
return false;
@ -186,7 +186,7 @@ CPollData* CHBRepeaterProtocolHandler::readPoll()
wxString text = wxString((char*)(m_buffer + 5U), wxConvLocal);
return new CPollData(text, m_address, m_port, m_socket.getPort());
return new CPollData(text, m_addr, m_addrLen, m_socket.getPort());
}
CHeaderData* CHBRepeaterProtocolHandler::readHeader()
@ -196,7 +196,7 @@ CHeaderData* CHBRepeaterProtocolHandler::readHeader()
CHeaderData* header = new CHeaderData;
bool res = header->setHBRepeaterData(m_buffer, m_length, true, m_address, m_port);
bool res = header->setHBRepeaterData(m_buffer, m_length, true, m_addr, m_addrLen);
if (!res) {
wxLogError(wxT("Invalid checksum from the repeater"));
delete header;
@ -213,7 +213,7 @@ CAMBEData* CHBRepeaterProtocolHandler::readAMBE()
CAMBEData* data = new CAMBEData;
bool res = data->setHBRepeaterData(m_buffer, m_length, m_address, m_port);
bool res = data->setHBRepeaterData(m_buffer, m_length, m_addr, m_addrLen);
if (!res) {
wxLogError(wxT("Invalid AMBE data from the repeater"));
delete data;
@ -230,7 +230,7 @@ CHeaderData* CHBRepeaterProtocolHandler::readBusyHeader()
CHeaderData* header = new CHeaderData;
bool res = header->setHBRepeaterData(m_buffer, m_length, true, m_address, m_port);
bool res = header->setHBRepeaterData(m_buffer, m_length, true, m_addr, m_addrLen);
if (!res) {
wxLogError(wxT("Invalid checksum from the repeater"));
delete header;
@ -247,7 +247,7 @@ CAMBEData* CHBRepeaterProtocolHandler::readBusyAMBE()
CAMBEData* data = new CAMBEData;
bool res = data->setHBRepeaterData(m_buffer, m_length, m_address, m_port);
bool res = data->setHBRepeaterData(m_buffer, m_length, m_addr, m_addrLen);
if (!res) {
wxLogError(wxT("Invalid AMBE data from the repeater"));
delete data;
@ -269,7 +269,7 @@ CDDData* CHBRepeaterProtocolHandler::readDD()
CDDData* data = new CDDData;
bool res = data->setHBRepeaterData(m_buffer, m_length, m_address, m_port);
bool res = data->setHBRepeaterData(m_buffer, m_length, m_addr, m_addrLen);
if (!res) {
wxLogError(wxT("Invalid DD data from the repeater"));
delete data;

View file

@ -1,5 +1,5 @@
/*
* Copyright (C) 2010-2014 by Jonathan Naylor G4KLX
* Copyright (C) 2010-2014,2020 by Jonathan Naylor G4KLX
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@ -53,8 +53,8 @@ m_myCall2(NULL),
m_yourCall(NULL),
m_rptCall1(NULL),
m_rptCall2(NULL),
m_yourAddress(),
m_yourPort(0U),
m_yourAddr(),
m_yourAddrLen(0U),
m_myPort(0U),
m_errors(0U)
{
@ -85,8 +85,8 @@ m_myCall2(NULL),
m_yourCall(NULL),
m_rptCall1(NULL),
m_rptCall2(NULL),
m_yourAddress(header.m_yourAddress),
m_yourPort(header.m_yourPort),
m_yourAddr(header.m_yourAddr),
m_yourAddrLen(header.m_yourAddrLen),
m_myPort(header.m_myPort),
m_errors(header.m_errors)
{
@ -119,8 +119,8 @@ m_myCall2(NULL),
m_yourCall(NULL),
m_rptCall1(NULL),
m_rptCall2(NULL),
m_yourAddress(),
m_yourPort(0U),
m_yourAddr(),
m_yourAddrLen(0U),
m_myPort(0U),
m_errors(0U)
{
@ -161,7 +161,7 @@ CHeaderData::~CHeaderData()
delete[] m_rptCall2;
}
bool CHeaderData::setIcomRepeaterData(const unsigned char *data, unsigned int length, bool check, const in_addr& yourAddress, unsigned int yourPort)
bool CHeaderData::setIcomRepeaterData(const unsigned char *data, unsigned int length, bool check, const sockaddr_storage& yourAddr, unsigned int yourAddrLen)
{
wxASSERT(data != NULL);
wxASSERT(length >= 58U);
@ -182,8 +182,8 @@ bool CHeaderData::setIcomRepeaterData(const unsigned char *data, unsigned int le
::memcpy(m_myCall1, data + 44U, LONG_CALLSIGN_LENGTH);
::memcpy(m_myCall2, data + 52U, SHORT_CALLSIGN_LENGTH);
m_yourAddress = yourAddress;
m_yourPort = yourPort;
m_yourAddr = yourAddr;
m_yourAddrLen = yourAddrLen;
if (check) {
CCCITTChecksum cksum;
@ -199,7 +199,7 @@ bool CHeaderData::setIcomRepeaterData(const unsigned char *data, unsigned int le
}
}
bool CHeaderData::setHBRepeaterData(const unsigned char *data, unsigned int length, bool check, const in_addr& yourAddress, unsigned int yourPort)
bool CHeaderData::setHBRepeaterData(const unsigned char *data, unsigned int length, bool check, const sockaddr_storage& yourAddr, unsigned int yourAddrLen)
{
wxASSERT(data != NULL);
wxASSERT(length >= 49U);
@ -217,8 +217,8 @@ bool CHeaderData::setHBRepeaterData(const unsigned char *data, unsigned int leng
::memcpy(m_myCall1, data + 35U, LONG_CALLSIGN_LENGTH);
::memcpy(m_myCall2, data + 43U, SHORT_CALLSIGN_LENGTH);
m_yourAddress = yourAddress;
m_yourPort = yourPort;
m_yourAddr = yourAddr;
m_yourAddrLen = yourAddrLen;
if (check) {
CCCITTChecksum cksum;
@ -234,7 +234,7 @@ bool CHeaderData::setHBRepeaterData(const unsigned char *data, unsigned int leng
}
}
void CHeaderData::setDCSData(const unsigned char *data, unsigned int length, const in_addr& yourAddress, unsigned int yourPort, unsigned int myPort)
void CHeaderData::setDCSData(const unsigned char *data, unsigned int length, const sockaddr_storage& yourAddr, unsigned int yourAddrLen, unsigned int myPort)
{
wxASSERT(data != NULL);
wxASSERT(length >= 100U);
@ -251,12 +251,12 @@ void CHeaderData::setDCSData(const unsigned char *data, unsigned int length, con
::memcpy(m_myCall1, data + 31U, LONG_CALLSIGN_LENGTH);
::memcpy(m_myCall2, data + 39U, SHORT_CALLSIGN_LENGTH);
m_yourAddress = yourAddress;
m_yourPort = yourPort;
m_yourAddr = yourAddr;
m_yourAddrLen = yourAddrLen;
m_myPort = myPort;
}
void CHeaderData::setCCSData(const unsigned char *data, unsigned int length, const in_addr& yourAddress, unsigned int yourPort, unsigned int myPort)
void CHeaderData::setCCSData(const unsigned char *data, unsigned int length, const sockaddr_storage& yourAddr, unsigned int yourAddrLen, unsigned int myPort)
{
wxASSERT(data != NULL);
wxASSERT(length >= 100U);
@ -269,12 +269,12 @@ void CHeaderData::setCCSData(const unsigned char *data, unsigned int length, con
::memcpy(m_myCall1, data + 31U, LONG_CALLSIGN_LENGTH);
::memcpy(m_myCall2, data + 39U, SHORT_CALLSIGN_LENGTH);
m_yourAddress = yourAddress;
m_yourPort = yourPort;
m_yourAddr = yourAddr;
m_yourAddrLen = yourAddrLen;
m_myPort = myPort;
}
bool CHeaderData::setG2Data(const unsigned char *data, unsigned int length, bool check, const in_addr& yourAddress, unsigned int yourPort)
bool CHeaderData::setG2Data(const unsigned char *data, unsigned int length, bool check, const sockaddr_storage& yourAddr, unsigned int yourAddrLen)
{
wxASSERT(data != NULL);
wxASSERT(length >= 56U);
@ -294,8 +294,8 @@ bool CHeaderData::setG2Data(const unsigned char *data, unsigned int length, bool
::memcpy(m_myCall1, data + 42U, LONG_CALLSIGN_LENGTH);
::memcpy(m_myCall2, data + 50U, SHORT_CALLSIGN_LENGTH);
m_yourAddress = yourAddress;
m_yourPort = yourPort;
m_yourAddr = yourAddr;
m_yourAddrLen = yourAddrLen;
if (check) {
CCCITTChecksum cksum;
@ -311,7 +311,7 @@ bool CHeaderData::setG2Data(const unsigned char *data, unsigned int length, bool
}
}
bool CHeaderData::setDExtraData(const unsigned char *data, unsigned int length, bool check, const in_addr& yourAddress, unsigned int yourPort, unsigned int myPort)
bool CHeaderData::setDExtraData(const unsigned char *data, unsigned int length, bool check, const sockaddr_storage& yourAddr, unsigned int yourAddrLen, unsigned int myPort)
{
wxASSERT(data != NULL);
wxASSERT(length >= 56U);
@ -331,8 +331,8 @@ bool CHeaderData::setDExtraData(const unsigned char *data, unsigned int length,
::memcpy(m_myCall1, data + 42U, LONG_CALLSIGN_LENGTH);
::memcpy(m_myCall2, data + 50U, SHORT_CALLSIGN_LENGTH);
m_yourAddress = yourAddress;
m_yourPort = yourPort;
m_yourAddr = yourAddr;
m_yourAddrLen = yourAddrLen;
m_myPort = myPort;
if (check) {
@ -349,7 +349,7 @@ bool CHeaderData::setDExtraData(const unsigned char *data, unsigned int length,
}
}
bool CHeaderData::setDPlusData(const unsigned char *data, unsigned int length, bool check, const in_addr& yourAddress, unsigned int yourPort, unsigned int myPort)
bool CHeaderData::setDPlusData(const unsigned char *data, unsigned int length, bool check, const sockaddr_storage& yourAddr, unsigned int yourAddrLen, unsigned int myPort)
{
wxASSERT(data != NULL);
wxASSERT(length >= 58U);
@ -374,8 +374,8 @@ bool CHeaderData::setDPlusData(const unsigned char *data, unsigned int length, b
::memcpy(m_myCall1, data + 44U, LONG_CALLSIGN_LENGTH);
::memcpy(m_myCall2, data + 52U, SHORT_CALLSIGN_LENGTH);
m_yourAddress = yourAddress;
m_yourPort = yourPort;
m_yourAddr = yourAddr;
m_yourAddrLen = yourAddrLen;
m_myPort = myPort;
if (check) {
@ -903,20 +903,20 @@ unsigned int CHeaderData::getData(unsigned char *data, unsigned int length, bool
}
}
void CHeaderData::setDestination(const in_addr& address, unsigned int port)
void CHeaderData::setDestination(const sockaddr_storage& addr, unsigned int addrLen)
{
m_yourAddress = address;
m_yourPort = port;
m_yourAddr = addr;
m_yourAddrLen = addrLen;
}
in_addr CHeaderData::getYourAddress() const
sockaddr_storage CHeaderData::getYourAddr() const
{
return m_yourAddress;
return m_yourAddr;
}
unsigned int CHeaderData::getYourPort() const
unsigned int CHeaderData::getYourAddrLen() const
{
return m_yourPort;
return m_yourAddrLen;
}
unsigned int CHeaderData::getMyPort() const
@ -935,8 +935,8 @@ CHeaderData& CHeaderData::operator =(const CHeaderData& header)
m_flag1 = header.m_flag1;
m_flag2 = header.m_flag2;
m_flag3 = header.m_flag3;
m_yourAddress = header.m_yourAddress;
m_yourPort = header.m_yourPort;
m_yourAddr = header.m_yourAddr;
m_yourAddrLen = header.m_yourAddrLen;
m_myPort = header.m_myPort;
m_errors = header.m_errors;

View file

@ -1,5 +1,5 @@
/*
* Copyright (C) 2010,2011,2012,2014 by Jonathan Naylor G4KLX
* Copyright (C) 2010,2011,2012,2014,2020 by Jonathan Naylor G4KLX
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@ -65,15 +65,12 @@ void CHeaderLogger::write(const wxChar* type, const CHeaderData& header)
time_t timeNow = ::time(NULL);
struct tm* tm = ::gmtime(&timeNow);
char* t = ::inet_ntoa(header.getYourAddress());
wxString address(t, wxConvLocal);
wxString text;
text.Printf(wxT("%04d-%02d-%02d %02d:%02d:%02d: %s header - My: %s/%s Your: %s Rpt1: %s Rpt2: %s Flags: %02X %02X %02X (%s:%u)\n"),
text.Printf(wxT("%04d-%02d-%02d %02d:%02d:%02d: %s header - My: %s/%s Your: %s Rpt1: %s Rpt2: %s Flags: %02X %02X %02X\n"),
tm->tm_year + 1900, tm->tm_mon + 1, tm->tm_mday, tm->tm_hour, tm->tm_min, tm->tm_sec, type,
header.getMyCall1().c_str(), header.getMyCall2().c_str(), header.getYourCall().c_str(),
header.getRptCall1().c_str(), header.getRptCall2().c_str(), header.getFlag1(), header.getFlag2(),
header.getFlag3(), address.c_str(), header.getYourPort());
header.getFlag3());
m_file.Write(text);
m_file.Flush();

View file

@ -1,5 +1,5 @@
/*
* Copyright (C) 2012,2013 by Jonathan Naylor G4KLX
* Copyright (C) 2012,2013,2020 by Jonathan Naylor G4KLX
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@ -23,8 +23,8 @@ m_reflector(),
m_repeater(),
m_user(),
m_ext(),
m_address(),
m_port(0U)
m_addr(),
m_addrLen(0U)
{
}
@ -33,8 +33,8 @@ m_reflector(data.m_reflector),
m_repeater(data.m_repeater),
m_user(data.m_user),
m_ext(data.m_ext),
m_address(data.m_address),
m_port(data.m_port)
m_addr(data.m_addr),
m_addrLen(data.m_addrLen)
{
}
@ -43,8 +43,8 @@ m_reflector(reflector),
m_repeater(repeater),
m_user(),
m_ext(),
m_address(),
m_port()
m_addr(),
m_addrLen(0U)
{
m_user = data.getMyCall1();
m_ext = data.getMyCall2();
@ -54,7 +54,7 @@ CHeardData::~CHeardData()
{
}
bool CHeardData::setIcomRepeaterData(const unsigned char *data, unsigned int length, const in_addr& address, unsigned int port)
bool CHeardData::setIcomRepeaterData(const unsigned char *data, unsigned int length, const sockaddr_storage& addr, unsigned int addrLen)
{
wxASSERT(data != NULL);
wxASSERT(length >= 26U);
@ -62,8 +62,8 @@ bool CHeardData::setIcomRepeaterData(const unsigned char *data, unsigned int len
m_user = wxString((char*)(data + 10U), wxConvLocal, LONG_CALLSIGN_LENGTH);
m_repeater = wxString((char*)(data + 18U), wxConvLocal, LONG_CALLSIGN_LENGTH);
m_address = address;
m_port = port;
m_addr = addr;
m_addrLen = addrLen;
return true;
}
@ -117,18 +117,18 @@ wxString CHeardData::getUser() const
return m_user;
}
void CHeardData::setDestination(const in_addr& address, unsigned int port)
void CHeardData::setDestination(const sockaddr_storage& addr, unsigned int addrLen)
{
m_address = address;
m_port = port;
m_addr = addr;
m_addrLen = addrLen;
}
in_addr CHeardData::getAddress() const
sockaddr_storage CHeardData::getAddr() const
{
return m_address;
return m_addr;
}
unsigned int CHeardData::getPort() const
unsigned int CHeardData::getAddrLen() const
{
return m_port;
return m_addrLen;
}

View file

@ -36,8 +36,8 @@ public:
unsigned int getHBRepeaterData(unsigned char* data, unsigned int length) const;
// sockaddr_storage getAddr() const;
// unsigned int getAddrLen() const;
sockaddr_storage getAddr() const;
unsigned int getAddrLen() const;
private:
LINK_STATUS m_status;