Skip to content

Commit

Permalink
NXDNIcomNetwork: IPv6 support
Browse files Browse the repository at this point in the history
  • Loading branch information
jg1uaa committed Jul 2, 2020
1 parent 6de0bdb commit 8a0db8c
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 16 deletions.
22 changes: 8 additions & 14 deletions NXDNIcomNetwork.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,15 +31,15 @@ const unsigned int BUFFER_LENGTH = 200U;
CNXDNIcomNetwork::CNXDNIcomNetwork(const std::string& localAddress, unsigned int localPort, const std::string& gatewayAddress, unsigned int gatewayPort, bool debug) :
m_socket(localAddress, localPort),
m_address(),
m_port(gatewayPort),
m_addrlen(),
m_debug(debug),
m_enabled(false),
m_buffer(1000U, "NXDN Network")
{
assert(gatewayPort > 0U);
assert(!gatewayAddress.empty());

m_address = CUDPSocket::lookup(gatewayAddress);
CUDPSocket::lookup(gatewayAddress, gatewayPort, m_address, m_addrlen);
}

CNXDNIcomNetwork::~CNXDNIcomNetwork()
Expand All @@ -50,7 +50,7 @@ bool CNXDNIcomNetwork::open()
{
LogMessage("Opening NXDN network connection");

if (m_address.s_addr == INADDR_NONE)
if (CUDPSocket::isnone(m_address))
return false;

return m_socket.open();
Expand Down Expand Up @@ -100,25 +100,19 @@ bool CNXDNIcomNetwork::write(const unsigned char* data, NXDN_NETWORK_MESSAGE_TYP
if (m_debug)
CUtils::dump(1U, "NXDN Network Data Sent", buffer, 102U);

return m_socket.write(buffer, 102U, m_address, m_port);
return m_socket.write(buffer, 102U, m_address, m_addrlen);
}

void CNXDNIcomNetwork::clock(unsigned int ms)
{
unsigned char buffer[BUFFER_LENGTH];

in_addr address;
unsigned int port;
int length = m_socket.read(buffer, BUFFER_LENGTH, address, port);
if (length <= 0)
sockaddr_storage address;
unsigned int addrlen;
int length = m_socket.read(buffer, BUFFER_LENGTH, address, addrlen);
if (length <= 0 || !CUDPSocket::match(m_address, address))
return;

// Check if the data is for us
if (m_address.s_addr != address.s_addr || port != m_port) {
LogMessage("NXDN packet received from an invalid source, %08X != %08X and/or %u != %u", m_address.s_addr, address.s_addr, m_port, port);
return;
}

// Invalid packet type?
if (::memcmp(buffer, "ICOM", 4U) != 0)
return;
Expand Down
4 changes: 2 additions & 2 deletions NXDNIcomNetwork.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,8 @@ class CNXDNIcomNetwork : public INXDNNetwork {

private:
CUDPSocket m_socket;
in_addr m_address;
unsigned int m_port;
sockaddr_storage m_address;
unsigned int m_addrlen;
bool m_debug;
bool m_enabled;
CRingBuffer<unsigned char> m_buffer;
Expand Down

0 comments on commit 8a0db8c

Please sign in to comment.