mirror of
https://github.com/ShaYmez/NXDNClients.git
synced 2024-11-21 23:15:14 -05:00
Re-add IPv4 and IPv6 capability to the NXDN networking.
This commit is contained in:
parent
80a32f358f
commit
7b458b8afb
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (C) 2009-2014,2016,2018,2020 by Jonathan Naylor G4KLX
|
||||
* Copyright (C) 2009-2014,2016,2018,2020,2024 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
|
||||
@ -26,7 +26,8 @@
|
||||
|
||||
CNXDNNetwork::CNXDNNetwork(unsigned short port, const std::string& callsign, bool debug) :
|
||||
m_callsign(callsign),
|
||||
m_socket(port),
|
||||
m_socket4(port),
|
||||
m_socket6(port),
|
||||
m_debug(debug)
|
||||
{
|
||||
assert(port > 0U);
|
||||
@ -42,7 +43,17 @@ bool CNXDNNetwork::open()
|
||||
{
|
||||
LogInfo("Opening NXDN network connection");
|
||||
|
||||
return m_socket.open();
|
||||
sockaddr_storage addr4;
|
||||
addr4.ss_family = AF_INET;
|
||||
|
||||
bool ret = m_socket4.open(addr4);
|
||||
if (!ret)
|
||||
return false;
|
||||
|
||||
sockaddr_storage addr6;
|
||||
addr6.ss_family = AF_INET6;
|
||||
|
||||
return m_socket6.open(addr6);
|
||||
}
|
||||
|
||||
bool CNXDNNetwork::writeData(const unsigned char* data, unsigned int length, unsigned short srcId, unsigned short dstId, bool grp, const sockaddr_storage& addr, unsigned int addrLen)
|
||||
@ -86,7 +97,15 @@ bool CNXDNNetwork::writeData(const unsigned char* data, unsigned int length, uns
|
||||
if (m_debug)
|
||||
CUtils::dump(1U, "NXDN Network Data Sent", buffer, 43U);
|
||||
|
||||
return m_socket.write(buffer, 43U, addr, addrLen);
|
||||
switch (addr.ss_family) {
|
||||
case AF_INET:
|
||||
return m_socket4.write(buffer, 43U, addr, addrLen);
|
||||
case AF_INET6:
|
||||
return m_socket6.write(buffer, 43U, addr, addrLen);
|
||||
default:
|
||||
LogError("Unknown socket address family - %u", addr.ss_family);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
bool CNXDNNetwork::writePoll(const sockaddr_storage& addr, unsigned int addrLen, unsigned short tg)
|
||||
@ -108,7 +127,15 @@ bool CNXDNNetwork::writePoll(const sockaddr_storage& addr, unsigned int addrLen,
|
||||
if (m_debug)
|
||||
CUtils::dump(1U, "NXDN Network Poll Sent", data, 17U);
|
||||
|
||||
return m_socket.write(data, 17U, addr, addrLen);
|
||||
switch (addr.ss_family) {
|
||||
case AF_INET:
|
||||
return m_socket4.write(data, 17U, addr, addrLen);
|
||||
case AF_INET6:
|
||||
return m_socket6.write(data, 17U, addr, addrLen);
|
||||
default:
|
||||
LogError("Unknown socket address family - %u", addr.ss_family);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
bool CNXDNNetwork::writeUnlink(const sockaddr_storage& addr, unsigned int addrLen, unsigned short tg)
|
||||
@ -130,7 +157,15 @@ bool CNXDNNetwork::writeUnlink(const sockaddr_storage& addr, unsigned int addrLe
|
||||
if (m_debug)
|
||||
CUtils::dump(1U, "NXDN Network Unlink Sent", data, 17U);
|
||||
|
||||
return m_socket.write(data, 17U, addr, addrLen);
|
||||
switch (addr.ss_family) {
|
||||
case AF_INET:
|
||||
return m_socket4.write(data, 17U, addr, addrLen);
|
||||
case AF_INET6:
|
||||
return m_socket6.write(data, 17U, addr, addrLen);
|
||||
default:
|
||||
LogError("Unknown socket address family - %u", addr.ss_family);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
unsigned int CNXDNNetwork::readData(unsigned char* data, unsigned int length, sockaddr_storage& addr, unsigned int& addrLen)
|
||||
@ -138,7 +173,9 @@ unsigned int CNXDNNetwork::readData(unsigned char* data, unsigned int length, so
|
||||
assert(data != NULL);
|
||||
assert(length > 0U);
|
||||
|
||||
int len = m_socket.read(data, length, addr, addrLen);
|
||||
int len = m_socket4.read(data, length, addr, addrLen);
|
||||
if (len <= 0)
|
||||
len = m_socket6.read(data, length, addr, addrLen);
|
||||
if (len <= 0)
|
||||
return 0U;
|
||||
|
||||
@ -154,7 +191,8 @@ unsigned int CNXDNNetwork::readData(unsigned char* data, unsigned int length, so
|
||||
|
||||
void CNXDNNetwork::close()
|
||||
{
|
||||
m_socket.close();
|
||||
m_socket4.close();
|
||||
m_socket6.close();
|
||||
|
||||
LogInfo("Closing NXDN network connection");
|
||||
}
|
||||
|
@ -43,7 +43,8 @@ public:
|
||||
|
||||
private:
|
||||
std::string m_callsign;
|
||||
CUDPSocket m_socket;
|
||||
CUDPSocket m_socket4;
|
||||
CUDPSocket m_socket6;
|
||||
bool m_debug;
|
||||
};
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user