Unfix address and port

This commit is contained in:
Geoffrey Merck F4FXL - KC3FRA 2018-11-17 18:18:28 +01:00
parent 05e66c15d1
commit 21b1b967be
5 changed files with 33 additions and 26 deletions

View file

@ -29,9 +29,7 @@ CG2ProtocolHandler::CG2ProtocolHandler(unsigned int port, const wxString& addr)
m_socket(addr, port),
m_type(GT_NONE),
m_buffer(NULL),
m_length(0U),
m_address(),
m_port(0U)
m_length(0U)
{
m_buffer = new unsigned char[BUFFER_LENGTH];
}
@ -76,23 +74,23 @@ bool CG2ProtocolHandler::writeAMBE(const CAMBEData& data)
return m_socket.write(buffer, length, data.getYourAddress(), data.getYourPort());
}
G2_TYPE CG2ProtocolHandler::read()
G2_TYPE CG2ProtocolHandler::read(in_addr& incomingAddress, unsigned int& incomingPort)
{
bool res = true;
// Loop until we have no more data from the socket or we have data for the higher layers
while (res)
res = readPackets();
res = readPackets(incomingAddress, incomingPort);
return m_type;
}
bool CG2ProtocolHandler::readPackets()
bool CG2ProtocolHandler::readPackets(in_addr& incomingAddress, unsigned int& incomingPort)
{
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, incomingAddress, incomingPort);
if (length <= 0)
return false;
@ -111,7 +109,7 @@ bool CG2ProtocolHandler::readPackets()
}
}
CHeaderData* CG2ProtocolHandler::readHeader()
CHeaderData* CG2ProtocolHandler::readHeader(in_addr incomingAddress, unsigned int incomingPort)
{
if (m_type != GT_HEADER)
return NULL;
@ -119,7 +117,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, incomingAddress, incomingPort);
if (!res) {
delete header;
return NULL;
@ -128,14 +126,14 @@ CHeaderData* CG2ProtocolHandler::readHeader()
return header;
}
CAMBEData* CG2ProtocolHandler::readAMBE()
CAMBEData* CG2ProtocolHandler::readAMBE(in_addr incomingAddress, unsigned int incomingPort)
{
if (m_type != GT_AMBE)
return NULL;
CAMBEData* data = new CAMBEData;
bool res = data->setG2Data(m_buffer, m_length, m_address, m_port);
bool res = data->setG2Data(m_buffer, m_length, incomingAddress, incomingPort);
if (!res) {
delete data;
return NULL;