Fix network ports datatype (unsigned int -> unsigned short). UDPSocket: fix old bug using m_port instead of m_port[x].

This commit is contained in:
Daniel Caujolle-Bert 2021-04-25 07:48:10 +02:00
parent d37a175bdc
commit ae9d88d254
No known key found for this signature in database
GPG Key ID: 51AED7171EC00614
27 changed files with 99 additions and 97 deletions

View File

@ -24,7 +24,7 @@
#include <cstring> #include <cstring>
#include <cmath> #include <cmath>
CAPRSWriter::CAPRSWriter(const std::string& callsign, const std::string& suffix, const std::string& address, unsigned int port, bool debug) : CAPRSWriter::CAPRSWriter(const std::string& callsign, const std::string& suffix, const std::string& address, unsigned short port, bool debug) :
m_idTimer(1000U), m_idTimer(1000U),
m_callsign(callsign), m_callsign(callsign),
m_debug(debug), m_debug(debug),

View File

@ -42,7 +42,7 @@
class CAPRSWriter { class CAPRSWriter {
public: public:
CAPRSWriter(const std::string& callsign, const std::string& suffix, const std::string& address, unsigned int port, bool debug); CAPRSWriter(const std::string& callsign, const std::string& suffix, const std::string& address, unsigned short port, bool debug);
~CAPRSWriter(); ~CAPRSWriter();
bool open(); bool open();

View File

@ -177,9 +177,9 @@ bool CConf::read()
else if (::strcmp(key, "RptAddress") == 0) else if (::strcmp(key, "RptAddress") == 0)
m_rptAddress = value; m_rptAddress = value;
else if (::strcmp(key, "RptPort") == 0) else if (::strcmp(key, "RptPort") == 0)
m_rptPort = (unsigned int)::atoi(value); m_rptPort = (unsigned short)::atoi(value);
else if (::strcmp(key, "LocalPort") == 0) else if (::strcmp(key, "LocalPort") == 0)
m_myPort = (unsigned int)::atoi(value); m_myPort = (unsigned short)::atoi(value);
else if (::strcmp(key, "Debug") == 0) else if (::strcmp(key, "Debug") == 0)
m_debug = ::atoi(value) == 1; m_debug = ::atoi(value) == 1;
else if (::strcmp(key, "Daemon") == 0) else if (::strcmp(key, "Daemon") == 0)
@ -230,14 +230,14 @@ bool CConf::read()
else if (::strcmp(key, "Address") == 0) else if (::strcmp(key, "Address") == 0)
m_aprsAddress = value; m_aprsAddress = value;
else if (::strcmp(key, "Port") == 0) else if (::strcmp(key, "Port") == 0)
m_aprsPort = (unsigned int)::atoi(value); m_aprsPort = (unsigned short)::atoi(value);
else if (::strcmp(key, "Suffix") == 0) else if (::strcmp(key, "Suffix") == 0)
m_aprsSuffix = value; m_aprsSuffix = value;
else if (::strcmp(key, "Description") == 0) else if (::strcmp(key, "Description") == 0)
m_aprsDescription = value; m_aprsDescription = value;
} else if (section == SECTION_NETWORK) { } else if (section == SECTION_NETWORK) {
if (::strcmp(key, "Port") == 0) if (::strcmp(key, "Port") == 0)
m_networkPort = (unsigned int)::atoi(value); m_networkPort = (unsigned short)::atoi(value);
else if (::strcmp(key, "HostsFile1") == 0) else if (::strcmp(key, "HostsFile1") == 0)
m_networkHosts1 = value; m_networkHosts1 = value;
else if (::strcmp(key, "HostsFile2") == 0) else if (::strcmp(key, "HostsFile2") == 0)
@ -247,11 +247,11 @@ bool CConf::read()
else if (::strcmp(key, "ParrotAddress") == 0) else if (::strcmp(key, "ParrotAddress") == 0)
m_networkParrotAddress = value; m_networkParrotAddress = value;
else if (::strcmp(key, "ParrotPort") == 0) else if (::strcmp(key, "ParrotPort") == 0)
m_networkParrotPort = (unsigned int)::atoi(value); m_networkParrotPort = (unsigned short)::atoi(value);
else if (::strcmp(key, "NXDN2DMRAddress") == 0) else if (::strcmp(key, "NXDN2DMRAddress") == 0)
m_networkNXDN2DMRAddress = value; m_networkNXDN2DMRAddress = value;
else if (::strcmp(key, "NXDN2DMRPort") == 0) else if (::strcmp(key, "NXDN2DMRPort") == 0)
m_networkNXDN2DMRPort = (unsigned int)::atoi(value); m_networkNXDN2DMRPort = (unsigned short)::atoi(value);
else if (::strcmp(key, "Static") == 0) { else if (::strcmp(key, "Static") == 0) {
char* p = ::strtok(value, ",\r\n"); char* p = ::strtok(value, ",\r\n");
while (p != NULL) { while (p != NULL) {
@ -276,7 +276,7 @@ bool CConf::read()
if (::strcmp(key, "Enable") == 0) if (::strcmp(key, "Enable") == 0)
m_remoteCommandsEnabled = ::atoi(value) == 1; m_remoteCommandsEnabled = ::atoi(value) == 1;
else if (::strcmp(key, "Port") == 0) else if (::strcmp(key, "Port") == 0)
m_remoteCommandsPort = (unsigned int)::atoi(value); m_remoteCommandsPort = (unsigned short)::atoi(value);
} }
} }
@ -305,12 +305,12 @@ std::string CConf::getRptAddress() const
return m_rptAddress; return m_rptAddress;
} }
unsigned int CConf::getRptPort() const unsigned short CConf::getRptPort() const
{ {
return m_rptPort; return m_rptPort;
} }
unsigned int CConf::getMyPort() const unsigned short CConf::getMyPort() const
{ {
return m_myPort; return m_myPort;
} }
@ -400,7 +400,7 @@ std::string CConf::getAPRSAddress() const
return m_aprsAddress; return m_aprsAddress;
} }
unsigned int CConf::getAPRSPort() const unsigned short CConf::getAPRSPort() const
{ {
return m_aprsPort; return m_aprsPort;
} }
@ -440,7 +440,7 @@ bool CConf::getLogFileRotate() const
return m_logFileRotate; return m_logFileRotate;
} }
unsigned int CConf::getNetworkPort() const unsigned short CConf::getNetworkPort() const
{ {
return m_networkPort; return m_networkPort;
} }
@ -465,7 +465,7 @@ std::string CConf::getNetworkParrotAddress() const
return m_networkParrotAddress; return m_networkParrotAddress;
} }
unsigned int CConf::getNetworkParrotPort() const unsigned short CConf::getNetworkParrotPort() const
{ {
return m_networkParrotPort; return m_networkParrotPort;
} }
@ -475,7 +475,7 @@ std::string CConf::getNetworkNXDN2DMRAddress() const
return m_networkNXDN2DMRAddress; return m_networkNXDN2DMRAddress;
} }
unsigned int CConf::getNetworkNXDN2DMRPort() const unsigned short CConf::getNetworkNXDN2DMRPort() const
{ {
return m_networkNXDN2DMRPort; return m_networkNXDN2DMRPort;
} }
@ -520,7 +520,7 @@ bool CConf::getRemoteCommandsEnabled() const
return m_remoteCommandsEnabled; return m_remoteCommandsEnabled;
} }
unsigned int CConf::getRemoteCommandsPort() const unsigned short CConf::getRemoteCommandsPort() const
{ {
return m_remoteCommandsPort; return m_remoteCommandsPort;
} }

View File

@ -35,8 +35,8 @@ public:
std::string getSuffix() const; std::string getSuffix() const;
std::string getRptProtocol() const; std::string getRptProtocol() const;
std::string getRptAddress() const; std::string getRptAddress() const;
unsigned int getRptPort() const; unsigned short getRptPort() const;
unsigned int getMyPort() const; unsigned short getMyPort() const;
bool getDebug() const; bool getDebug() const;
bool getDaemon() const; bool getDaemon() const;
@ -62,7 +62,7 @@ public:
// The APRS section // The APRS section
bool getAPRSEnabled() const; bool getAPRSEnabled() const;
std::string getAPRSAddress() const; std::string getAPRSAddress() const;
unsigned int getAPRSPort() const; unsigned short getAPRSPort() const;
std::string getAPRSSuffix() const; std::string getAPRSSuffix() const;
std::string getAPRSDescription() const; std::string getAPRSDescription() const;
@ -74,14 +74,14 @@ public:
bool getLogFileRotate() const; bool getLogFileRotate() const;
// The Network section // The Network section
unsigned int getNetworkPort() const; unsigned short getNetworkPort() const;
std::string getNetworkHosts1() const; std::string getNetworkHosts1() const;
std::string getNetworkHosts2() const; std::string getNetworkHosts2() const;
unsigned int getNetworkReloadTime() const; unsigned int getNetworkReloadTime() const;
std::string getNetworkParrotAddress() const; std::string getNetworkParrotAddress() const;
unsigned int getNetworkParrotPort() const; unsigned short getNetworkParrotPort() const;
std::string getNetworkNXDN2DMRAddress() const; std::string getNetworkNXDN2DMRAddress() const;
unsigned int getNetworkNXDN2DMRPort() const; unsigned short getNetworkNXDN2DMRPort() const;
std::vector<unsigned short> getNetworkStatic() const; std::vector<unsigned short> getNetworkStatic() const;
unsigned int getNetworkRFHangTime() const; unsigned int getNetworkRFHangTime() const;
unsigned int getNetworkNetHangTime() const; unsigned int getNetworkNetHangTime() const;
@ -94,7 +94,7 @@ public:
// The Remote Commands section // The Remote Commands section
bool getRemoteCommandsEnabled() const; bool getRemoteCommandsEnabled() const;
unsigned int getRemoteCommandsPort() const; unsigned short getRemoteCommandsPort() const;
private: private:
std::string m_file; std::string m_file;
@ -102,8 +102,8 @@ private:
std::string m_suffix; std::string m_suffix;
std::string m_rptProtocol; std::string m_rptProtocol;
std::string m_rptAddress; std::string m_rptAddress;
unsigned int m_rptPort; unsigned short m_rptPort;
unsigned int m_myPort; unsigned short m_myPort;
bool m_debug; bool m_debug;
bool m_daemon; bool m_daemon;
@ -131,18 +131,18 @@ private:
bool m_aprsEnabled; bool m_aprsEnabled;
std::string m_aprsAddress; std::string m_aprsAddress;
unsigned int m_aprsPort; unsigned short m_aprsPort;
std::string m_aprsSuffix; std::string m_aprsSuffix;
std::string m_aprsDescription; std::string m_aprsDescription;
unsigned int m_networkPort; unsigned short m_networkPort;
std::string m_networkHosts1; std::string m_networkHosts1;
std::string m_networkHosts2; std::string m_networkHosts2;
unsigned int m_networkReloadTime; unsigned int m_networkReloadTime;
std::string m_networkParrotAddress; std::string m_networkParrotAddress;
unsigned int m_networkParrotPort; unsigned short m_networkParrotPort;
std::string m_networkNXDN2DMRAddress; std::string m_networkNXDN2DMRAddress;
unsigned int m_networkNXDN2DMRPort; unsigned short m_networkNXDN2DMRPort;
std::vector<unsigned short> m_networkStatic; std::vector<unsigned short> m_networkStatic;
unsigned int m_networkRFHangTime; unsigned int m_networkRFHangTime;
unsigned int m_networkNetHangTime; unsigned int m_networkNetHangTime;
@ -153,7 +153,7 @@ private:
std::string m_gpsdPort; std::string m_gpsdPort;
bool m_remoteCommandsEnabled; bool m_remoteCommandsEnabled;
unsigned int m_remoteCommandsPort; unsigned short m_remoteCommandsPort;
}; };
#endif #endif

View File

@ -26,7 +26,7 @@
const unsigned int BUFFER_LENGTH = 200U; const unsigned int BUFFER_LENGTH = 200U;
CIcomNetwork::CIcomNetwork(unsigned int localPort, const std::string& rptAddress, unsigned int rptPort, bool debug) : CIcomNetwork::CIcomNetwork(unsigned short localPort, const std::string& rptAddress, unsigned short rptPort, bool debug) :
m_socket(localPort), m_socket(localPort),
m_addr(), m_addr(),
m_addrLen(0U), m_addrLen(0U),

View File

@ -27,7 +27,7 @@
class CIcomNetwork : public IRptNetwork { class CIcomNetwork : public IRptNetwork {
public: public:
CIcomNetwork(unsigned int localPort, const std::string& rptAddress, unsigned int rptPort, bool debug); CIcomNetwork(unsigned short localPort, const std::string& rptAddress, unsigned short rptPort, bool debug);
virtual ~CIcomNetwork(); virtual ~CIcomNetwork();
virtual bool open(); virtual bool open();

View File

@ -33,7 +33,7 @@ const unsigned char BIT_MASK_TABLE[] = { 0x80U, 0x40U, 0x20U, 0x10U, 0x08U, 0x04
const unsigned int BUFFER_LENGTH = 200U; const unsigned int BUFFER_LENGTH = 200U;
CKenwoodNetwork::CKenwoodNetwork(unsigned int localPort, const std::string& rptAddress, unsigned int rptPort, bool debug) : CKenwoodNetwork::CKenwoodNetwork(unsigned short localPort, const std::string& rptAddress, unsigned short rptPort, bool debug) :
m_rtpSocket(localPort + 0U), m_rtpSocket(localPort + 0U),
m_rtcpSocket(localPort + 1U), m_rtcpSocket(localPort + 1U),
m_rtcpAddr(), m_rtcpAddr(),

View File

@ -29,7 +29,7 @@
class CKenwoodNetwork : public IRptNetwork { class CKenwoodNetwork : public IRptNetwork {
public: public:
CKenwoodNetwork(unsigned int localPort, const std::string& rptAddress, unsigned int rptPort, bool debug); CKenwoodNetwork(unsigned short localPort, const std::string& rptAddress, unsigned short rptPort, bool debug);
virtual ~CKenwoodNetwork(); virtual ~CKenwoodNetwork();
virtual bool open(); virtual bool open();

View File

@ -628,7 +628,7 @@ void CNXDNGateway::createGPS()
std::string callsign = m_conf.getCallsign(); std::string callsign = m_conf.getCallsign();
std::string rptSuffix = m_conf.getSuffix(); std::string rptSuffix = m_conf.getSuffix();
std::string address = m_conf.getAPRSAddress(); std::string address = m_conf.getAPRSAddress();
unsigned int port = m_conf.getAPRSPort(); unsigned short port = m_conf.getAPRSPort();
std::string suffix = m_conf.getAPRSSuffix(); std::string suffix = m_conf.getAPRSSuffix();
bool debug = m_conf.getDebug(); bool debug = m_conf.getDebug();

View File

@ -24,7 +24,7 @@
#include <cassert> #include <cassert>
#include <cstring> #include <cstring>
CNXDNNetwork::CNXDNNetwork(unsigned int port, const std::string& callsign, bool debug) : CNXDNNetwork::CNXDNNetwork(unsigned short port, const std::string& callsign, bool debug) :
m_callsign(callsign), m_callsign(callsign),
m_socket(), m_socket(),
m_port(port), m_port(port),

View File

@ -26,7 +26,7 @@
class CNXDNNetwork { class CNXDNNetwork {
public: public:
CNXDNNetwork(unsigned int port, const std::string& callsign, bool debug); CNXDNNetwork(unsigned short port, const std::string& callsign, bool debug);
~CNXDNNetwork(); ~CNXDNNetwork();
bool open(); bool open();
@ -44,7 +44,7 @@ public:
private: private:
std::string m_callsign; std::string m_callsign;
CUDPSocket m_socket; CUDPSocket m_socket;
unsigned int m_port; unsigned short m_port;
bool m_debug; bool m_debug;
}; };

View File

@ -46,13 +46,13 @@ CReflectors::~CReflectors()
m_reflectors.clear(); m_reflectors.clear();
} }
void CReflectors::setParrot(const std::string& address, unsigned int port) void CReflectors::setParrot(const std::string& address, unsigned short port)
{ {
m_parrotAddress = address; m_parrotAddress = address;
m_parrotPort = port; m_parrotPort = port;
} }
void CReflectors::setNXDN2DMR(const std::string& address, unsigned int port) void CReflectors::setNXDN2DMR(const std::string& address, unsigned short port)
{ {
m_nxdn2dmrAddress = address; m_nxdn2dmrAddress = address;
m_nxdn2dmrPort = port; m_nxdn2dmrPort = port;
@ -79,7 +79,7 @@ bool CReflectors::load()
if (p1 != NULL && p2 != NULL && p3 != NULL) { if (p1 != NULL && p2 != NULL && p3 != NULL) {
std::string host = std::string(p2); std::string host = std::string(p2);
unsigned int port = (unsigned int)::atoi(p3); unsigned short port = (unsigned short)::atoi(p3);
sockaddr_storage addr; sockaddr_storage addr;
unsigned int addrLen; unsigned int addrLen;
@ -114,7 +114,7 @@ bool CReflectors::load()
unsigned int id = (unsigned int)::atoi(p1); unsigned int id = (unsigned int)::atoi(p1);
if (find(id) == NULL) { if (find(id) == NULL) {
std::string host = std::string(p2); std::string host = std::string(p2);
unsigned int port = (unsigned int)::atoi(p3); unsigned short port = (unsigned short)::atoi(p3);
sockaddr_storage addr; sockaddr_storage addr;
unsigned int addrLen; unsigned int addrLen;

View File

@ -44,8 +44,8 @@ public:
CReflectors(const std::string& hostsFile1, const std::string& hostsFile2, unsigned int reloadTime); CReflectors(const std::string& hostsFile1, const std::string& hostsFile2, unsigned int reloadTime);
~CReflectors(); ~CReflectors();
void setParrot(const std::string& address, unsigned int port); void setParrot(const std::string& address, unsigned short port);
void setNXDN2DMR(const std::string& address, unsigned int port); void setNXDN2DMR(const std::string& address, unsigned short port);
bool load(); bool load();
@ -57,9 +57,9 @@ private:
std::string m_hostsFile1; std::string m_hostsFile1;
std::string m_hostsFile2; std::string m_hostsFile2;
std::string m_parrotAddress; std::string m_parrotAddress;
unsigned int m_parrotPort; unsigned short m_parrotPort;
std::string m_nxdn2dmrAddress; std::string m_nxdn2dmrAddress;
unsigned int m_nxdn2dmrPort; unsigned short m_nxdn2dmrPort;
std::vector<CNXDNReflector*> m_reflectors; std::vector<CNXDNReflector*> m_reflectors;
CTimer m_timer; CTimer m_timer;
}; };

View File

@ -28,11 +28,12 @@
#if defined(HAVE_LOG_H) #if defined(HAVE_LOG_H)
#include "Log.h" #include "Log.h"
#else #else
#define LogMessage(fmt, ...) ::fprintf(stderr, fmt "\n", ## __VA_ARGS__)
#define LogError(fmt, ...) ::fprintf(stderr, fmt "\n", ## __VA_ARGS__) #define LogError(fmt, ...) ::fprintf(stderr, fmt "\n", ## __VA_ARGS__)
#define LogInfo(fmt, ...) ::fprintf(stderr, fmt "\n", ## __VA_ARGS__) #define LogInfo(fmt, ...) ::fprintf(stderr, fmt "\n", ## __VA_ARGS__)
#endif #endif
CUDPSocket::CUDPSocket(const std::string& address, unsigned int port) : CUDPSocket::CUDPSocket(const std::string& address, unsigned short port) :
m_address_save(address), m_address_save(address),
m_port_save(port), m_port_save(port),
m_counter(0U) m_counter(0U)
@ -45,7 +46,7 @@ m_counter(0U)
} }
} }
CUDPSocket::CUDPSocket(unsigned int port) : CUDPSocket::CUDPSocket(unsigned short port) :
m_address_save(), m_address_save(),
m_port_save(port), m_port_save(port),
m_counter(0U) m_counter(0U)
@ -79,7 +80,7 @@ void CUDPSocket::shutdown()
#endif #endif
} }
int CUDPSocket::lookup(const std::string& hostname, unsigned int port, sockaddr_storage& addr, unsigned int& address_length) int CUDPSocket::lookup(const std::string& hostname, unsigned short port, sockaddr_storage& addr, unsigned int& address_length)
{ {
struct addrinfo hints; struct addrinfo hints;
::memset(&hints, 0, sizeof(hints)); ::memset(&hints, 0, sizeof(hints));
@ -87,7 +88,7 @@ int CUDPSocket::lookup(const std::string& hostname, unsigned int port, sockaddr_
return lookup(hostname, port, addr, address_length, hints); return lookup(hostname, port, addr, address_length, hints);
} }
int CUDPSocket::lookup(const std::string& hostname, unsigned int port, sockaddr_storage& addr, unsigned int& address_length, struct addrinfo& hints) int CUDPSocket::lookup(const std::string& hostname, unsigned short port, sockaddr_storage& addr, unsigned int& address_length, struct addrinfo& hints)
{ {
std::string portstr = std::to_string(port); std::string portstr = std::to_string(port);
struct addrinfo *res; struct addrinfo *res;
@ -170,7 +171,7 @@ bool CUDPSocket::open(unsigned int af)
return open(0, af, m_address_save, m_port_save); return open(0, af, m_address_save, m_port_save);
} }
bool CUDPSocket::open(const unsigned int index, const unsigned int af, const std::string& address, const unsigned int port) bool CUDPSocket::open(const unsigned int index, const unsigned int af, const std::string& address, const unsigned short port)
{ {
sockaddr_storage addr; sockaddr_storage addr;
unsigned int addrlen; unsigned int addrlen;
@ -224,7 +225,7 @@ bool CUDPSocket::open(const unsigned int index, const unsigned int af, const std
return false; return false;
} }
LogInfo("Opening UDP port on %u", port); LogInfo("Opening UDP port on %hu", port);
} }
return true; return true;
@ -293,7 +294,7 @@ int CUDPSocket::read(unsigned char* buffer, unsigned int length, sockaddr_storag
LogError("Error returned from recvfrom, err: %d", errno); LogError("Error returned from recvfrom, err: %d", errno);
if (len == -1 && errno == ENOTSOCK) { if (len == -1 && errno == ENOTSOCK) {
LogMessage("Re-opening UDP port on %u", m_port); LogMessage("Re-opening UDP port on %hu", m_port[index]);
close(); close();
open(); open();
} }

View File

@ -46,13 +46,13 @@ enum IPMATCHTYPE {
class CUDPSocket { class CUDPSocket {
public: public:
CUDPSocket(const std::string& address, unsigned int port = 0U); CUDPSocket(const std::string& address, unsigned short port = 0U);
CUDPSocket(unsigned int port = 0U); CUDPSocket(unsigned short port = 0U);
~CUDPSocket(); ~CUDPSocket();
bool open(unsigned int af = AF_UNSPEC); bool open(unsigned int af = AF_UNSPEC);
bool open(const sockaddr_storage& address); bool open(const sockaddr_storage& address);
bool open(const unsigned int index, const unsigned int af, const std::string& address, const unsigned int port); bool open(const unsigned int index, const unsigned int af, const std::string& address, const unsigned short port);
int read(unsigned char* buffer, unsigned int length, sockaddr_storage& address, unsigned int &address_length); int read(unsigned char* buffer, unsigned int length, sockaddr_storage& address, unsigned int &address_length);
bool write(const unsigned char* buffer, unsigned int length, const sockaddr_storage& address, unsigned int address_length); bool write(const unsigned char* buffer, unsigned int length, const sockaddr_storage& address, unsigned int address_length);
@ -63,8 +63,8 @@ public:
static void startup(); static void startup();
static void shutdown(); static void shutdown();
static int lookup(const std::string& hostName, unsigned int port, sockaddr_storage& address, unsigned int& address_length); static int lookup(const std::string& hostName, unsigned short port, sockaddr_storage& address, unsigned int& address_length);
static int lookup(const std::string& hostName, unsigned int port, sockaddr_storage& address, unsigned int& address_length, struct addrinfo& hints); static int lookup(const std::string& hostName, unsigned short port, sockaddr_storage& address, unsigned int& address_length, struct addrinfo& hints);
static bool match(const sockaddr_storage& addr1, const sockaddr_storage& addr2, IPMATCHTYPE type = IMT_ADDRESS_AND_PORT); static bool match(const sockaddr_storage& addr1, const sockaddr_storage& addr2, IPMATCHTYPE type = IMT_ADDRESS_AND_PORT);

View File

@ -22,7 +22,7 @@
#include <cassert> #include <cassert>
#include <cstring> #include <cstring>
CNXDNNetwork::CNXDNNetwork(unsigned int port) : CNXDNNetwork::CNXDNNetwork(unsigned short port) :
m_socket(port), m_socket(port),
m_addr(), m_addr(),
m_addrLen(0U) m_addrLen(0U)

View File

@ -26,7 +26,7 @@
class CNXDNNetwork { class CNXDNNetwork {
public: public:
CNXDNNetwork(unsigned int port); CNXDNNetwork(unsigned short port);
~CNXDNNetwork(); ~CNXDNNetwork();
bool open(); bool open();

View File

@ -35,7 +35,7 @@ int main(int argc, char** argv)
return 1; return 1;
} }
unsigned int port = ::atoi(argv[1U]); unsigned short port = (unsigned short)::atoi(argv[1U]);
if (port == 0U) { if (port == 0U) {
::fprintf(stderr, "NXDNParrot: invalid port number - %s\n", argv[1U]); ::fprintf(stderr, "NXDNParrot: invalid port number - %s\n", argv[1U]);
return 1; return 1;
@ -47,7 +47,7 @@ int main(int argc, char** argv)
return 0; return 0;
} }
CNXDNParrot::CNXDNParrot(unsigned int port) : CNXDNParrot::CNXDNParrot(unsigned short port) :
m_port(port) m_port(port)
{ {
CUDPSocket::startup(); CUDPSocket::startup();

View File

@ -22,13 +22,13 @@
class CNXDNParrot class CNXDNParrot
{ {
public: public:
CNXDNParrot(unsigned int port); CNXDNParrot(unsigned short port);
~CNXDNParrot(); ~CNXDNParrot();
void run(); void run();
private: private:
unsigned int m_port; unsigned short m_port;
}; };
#endif #endif

View File

@ -33,7 +33,7 @@
#define LogInfo(fmt, ...) ::fprintf(stderr, fmt "\n", ## __VA_ARGS__) #define LogInfo(fmt, ...) ::fprintf(stderr, fmt "\n", ## __VA_ARGS__)
#endif #endif
CUDPSocket::CUDPSocket(const std::string& address, unsigned int port) : CUDPSocket::CUDPSocket(const std::string& address, unsigned short port) :
m_address_save(address), m_address_save(address),
m_port_save(port), m_port_save(port),
m_counter(0U) m_counter(0U)
@ -46,7 +46,7 @@ m_counter(0U)
} }
} }
CUDPSocket::CUDPSocket(unsigned int port) : CUDPSocket::CUDPSocket(unsigned short port) :
m_address_save(), m_address_save(),
m_port_save(port), m_port_save(port),
m_counter(0U) m_counter(0U)
@ -80,7 +80,7 @@ void CUDPSocket::shutdown()
#endif #endif
} }
int CUDPSocket::lookup(const std::string& hostname, unsigned int port, sockaddr_storage& addr, unsigned int& address_length) int CUDPSocket::lookup(const std::string& hostname, unsigned short port, sockaddr_storage& addr, unsigned int& address_length)
{ {
struct addrinfo hints; struct addrinfo hints;
::memset(&hints, 0, sizeof(hints)); ::memset(&hints, 0, sizeof(hints));
@ -88,7 +88,7 @@ int CUDPSocket::lookup(const std::string& hostname, unsigned int port, sockaddr_
return lookup(hostname, port, addr, address_length, hints); return lookup(hostname, port, addr, address_length, hints);
} }
int CUDPSocket::lookup(const std::string& hostname, unsigned int port, sockaddr_storage& addr, unsigned int& address_length, struct addrinfo& hints) int CUDPSocket::lookup(const std::string& hostname, unsigned short port, sockaddr_storage& addr, unsigned int& address_length, struct addrinfo& hints)
{ {
std::string portstr = std::to_string(port); std::string portstr = std::to_string(port);
struct addrinfo *res; struct addrinfo *res;
@ -171,7 +171,7 @@ bool CUDPSocket::open(unsigned int af)
return open(0, af, m_address_save, m_port_save); return open(0, af, m_address_save, m_port_save);
} }
bool CUDPSocket::open(const unsigned int index, const unsigned int af, const std::string& address, const unsigned int port) bool CUDPSocket::open(const unsigned int index, const unsigned int af, const std::string& address, const unsigned short port)
{ {
sockaddr_storage addr; sockaddr_storage addr;
unsigned int addrlen; unsigned int addrlen;
@ -225,7 +225,7 @@ bool CUDPSocket::open(const unsigned int index, const unsigned int af, const std
return false; return false;
} }
LogInfo("Opening UDP port on %u", port); LogInfo("Opening UDP port on %hu", port);
} }
return true; return true;
@ -294,7 +294,7 @@ int CUDPSocket::read(unsigned char* buffer, unsigned int length, sockaddr_storag
LogError("Error returned from recvfrom, err: %d", errno); LogError("Error returned from recvfrom, err: %d", errno);
if (len == -1 && errno == ENOTSOCK) { if (len == -1 && errno == ENOTSOCK) {
LogMessage("Re-opening UDP port on %u", m_port); LogMessage("Re-opening UDP port on %hu", m_port[index]);
close(); close();
open(); open();
} }

View File

@ -46,13 +46,13 @@ enum IPMATCHTYPE {
class CUDPSocket { class CUDPSocket {
public: public:
CUDPSocket(const std::string& address, unsigned int port = 0U); CUDPSocket(const std::string& address, unsigned short port = 0U);
CUDPSocket(unsigned int port = 0U); CUDPSocket(unsigned short port = 0U);
~CUDPSocket(); ~CUDPSocket();
bool open(unsigned int af = AF_UNSPEC); bool open(unsigned int af = AF_UNSPEC);
bool open(const sockaddr_storage& address); bool open(const sockaddr_storage& address);
bool open(const unsigned int index, const unsigned int af, const std::string& address, const unsigned int port); bool open(const unsigned int index, const unsigned int af, const std::string& address, const unsigned short port);
int read(unsigned char* buffer, unsigned int length, sockaddr_storage& address, unsigned int &address_length); int read(unsigned char* buffer, unsigned int length, sockaddr_storage& address, unsigned int &address_length);
bool write(const unsigned char* buffer, unsigned int length, const sockaddr_storage& address, unsigned int address_length); bool write(const unsigned char* buffer, unsigned int length, const sockaddr_storage& address, unsigned int address_length);
@ -63,8 +63,8 @@ public:
static void startup(); static void startup();
static void shutdown(); static void shutdown();
static int lookup(const std::string& hostName, unsigned int port, sockaddr_storage& address, unsigned int& address_length); static int lookup(const std::string& hostName, unsigned short port, sockaddr_storage& address, unsigned int& address_length);
static int lookup(const std::string& hostName, unsigned int port, sockaddr_storage& address, unsigned int& address_length, struct addrinfo& hints); static int lookup(const std::string& hostName, unsigned short port, sockaddr_storage& address, unsigned int& address_length, struct addrinfo& hints);
static bool match(const sockaddr_storage& addr1, const sockaddr_storage& addr2, IPMATCHTYPE type = IMT_ADDRESS_AND_PORT); static bool match(const sockaddr_storage& addr1, const sockaddr_storage& addr2, IPMATCHTYPE type = IMT_ADDRESS_AND_PORT);

View File

@ -148,7 +148,7 @@ bool CConf::read()
m_logFileRotate = ::atoi(value) == 1; m_logFileRotate = ::atoi(value) == 1;
} else if (section == SECTION_NETWORK) { } else if (section == SECTION_NETWORK) {
if (::strcmp(key, "Port") == 0) if (::strcmp(key, "Port") == 0)
m_networkPort = (unsigned int)::atoi(value); m_networkPort = (unsigned short)::atoi(value);
else if (::strcmp(key, "Debug") == 0) else if (::strcmp(key, "Debug") == 0)
m_networkDebug = ::atoi(value) == 1; m_networkDebug = ::atoi(value) == 1;
} else if (section == SECTION_ICOM_NETWORK) { } else if (section == SECTION_ICOM_NETWORK) {
@ -226,7 +226,7 @@ bool CConf::getLogFileRotate() const
return m_logFileRotate; return m_logFileRotate;
} }
unsigned int CConf::getNetworkPort() const unsigned short CConf::getNetworkPort() const
{ {
return m_networkPort; return m_networkPort;
} }

View File

@ -46,7 +46,7 @@ public:
bool getLogFileRotate() const; bool getLogFileRotate() const;
// The Network section // The Network section
unsigned int getNetworkPort() const; unsigned short getNetworkPort() const;
bool getNetworkDebug() const; bool getNetworkDebug() const;
// The Icom Network section // The Icom Network section
@ -77,7 +77,7 @@ private:
std::string m_logFileRoot; std::string m_logFileRoot;
bool m_logFileRotate; bool m_logFileRotate;
unsigned int m_networkPort; unsigned short m_networkPort;
bool m_networkDebug; bool m_networkDebug;
bool m_icomEnabled; bool m_icomEnabled;

View File

@ -24,7 +24,7 @@
#include <cassert> #include <cassert>
#include <cstring> #include <cstring>
CNXDNNetwork::CNXDNNetwork(unsigned int port, bool debug) : CNXDNNetwork::CNXDNNetwork(unsigned short port, bool debug) :
m_socket(port), m_socket(port),
m_debug(debug) m_debug(debug)
{ {

View File

@ -26,7 +26,7 @@
class CNXDNNetwork { class CNXDNNetwork {
public: public:
CNXDNNetwork(unsigned int port, bool debug); CNXDNNetwork(unsigned short port, bool debug);
~CNXDNNetwork(); ~CNXDNNetwork();
bool open(); bool open();

View File

@ -28,11 +28,12 @@
#if defined(HAVE_LOG_H) #if defined(HAVE_LOG_H)
#include "Log.h" #include "Log.h"
#else #else
#define LogMessage(fmt, ...) ::fprintf(stderr, fmt "\n", ## __VA_ARGS__)
#define LogError(fmt, ...) ::fprintf(stderr, fmt "\n", ## __VA_ARGS__) #define LogError(fmt, ...) ::fprintf(stderr, fmt "\n", ## __VA_ARGS__)
#define LogInfo(fmt, ...) ::fprintf(stderr, fmt "\n", ## __VA_ARGS__) #define LogInfo(fmt, ...) ::fprintf(stderr, fmt "\n", ## __VA_ARGS__)
#endif #endif
CUDPSocket::CUDPSocket(const std::string& address, unsigned int port) : CUDPSocket::CUDPSocket(const std::string& address, unsigned short port) :
m_address_save(address), m_address_save(address),
m_port_save(port), m_port_save(port),
m_counter(0U) m_counter(0U)
@ -45,7 +46,7 @@ m_counter(0U)
} }
} }
CUDPSocket::CUDPSocket(unsigned int port) : CUDPSocket::CUDPSocket(unsigned short port) :
m_address_save(), m_address_save(),
m_port_save(port), m_port_save(port),
m_counter(0U) m_counter(0U)
@ -79,7 +80,7 @@ void CUDPSocket::shutdown()
#endif #endif
} }
int CUDPSocket::lookup(const std::string& hostname, unsigned int port, sockaddr_storage& addr, unsigned int& address_length) int CUDPSocket::lookup(const std::string& hostname, unsigned short port, sockaddr_storage& addr, unsigned int& address_length)
{ {
struct addrinfo hints; struct addrinfo hints;
::memset(&hints, 0, sizeof(hints)); ::memset(&hints, 0, sizeof(hints));
@ -87,7 +88,7 @@ int CUDPSocket::lookup(const std::string& hostname, unsigned int port, sockaddr_
return lookup(hostname, port, addr, address_length, hints); return lookup(hostname, port, addr, address_length, hints);
} }
int CUDPSocket::lookup(const std::string& hostname, unsigned int port, sockaddr_storage& addr, unsigned int& address_length, struct addrinfo& hints) int CUDPSocket::lookup(const std::string& hostname, unsigned short port, sockaddr_storage& addr, unsigned int& address_length, struct addrinfo& hints)
{ {
std::string portstr = std::to_string(port); std::string portstr = std::to_string(port);
struct addrinfo *res; struct addrinfo *res;
@ -171,14 +172,14 @@ char* CUDPSocket::display(const sockaddr_storage& addr, char* buffer, unsigned i
::inet_ntop(AF_INET, &in4, buffer, length); ::inet_ntop(AF_INET, &in4, buffer, length);
::sprintf(buffer + ::strlen(buffer), ":%u", in4->sin_port); ::sprintf(buffer + ::strlen(buffer), ":%u", in4->sin_port);
} }
break; break;
case AF_INET6: { case AF_INET6: {
struct sockaddr_in6* in6 = (struct sockaddr_in6*)&addr; struct sockaddr_in6* in6 = (struct sockaddr_in6*)&addr;
::inet_ntop(AF_INET6, &in6, buffer, length); ::inet_ntop(AF_INET6, &in6, buffer, length);
::sprintf(buffer + ::strlen(buffer), ":%u", in6->sin6_port); ::sprintf(buffer + ::strlen(buffer), ":%u", in6->sin6_port);
} }
break; break;
default: default:
::strcpy(buffer, "Unknown"); ::strcpy(buffer, "Unknown");
@ -198,7 +199,7 @@ bool CUDPSocket::open(unsigned int af)
return open(0, af, m_address_save, m_port_save); return open(0, af, m_address_save, m_port_save);
} }
bool CUDPSocket::open(const unsigned int index, const unsigned int af, const std::string& address, const unsigned int port) bool CUDPSocket::open(const unsigned int index, const unsigned int af, const std::string& address, const unsigned short port)
{ {
sockaddr_storage addr; sockaddr_storage addr;
unsigned int addrlen; unsigned int addrlen;
@ -252,7 +253,7 @@ bool CUDPSocket::open(const unsigned int index, const unsigned int af, const std
return false; return false;
} }
LogInfo("Opening UDP port on %u", port); LogInfo("Opening UDP port on %hu", port);
} }
return true; return true;
@ -321,7 +322,7 @@ int CUDPSocket::read(unsigned char* buffer, unsigned int length, sockaddr_storag
LogError("Error returned from recvfrom, err: %d", errno); LogError("Error returned from recvfrom, err: %d", errno);
if (len == -1 && errno == ENOTSOCK) { if (len == -1 && errno == ENOTSOCK) {
LogMessage("Re-opening UDP port on %u", m_port); LogMessage("Re-opening UDP port on %hu", m_port[index]);
close(); close();
open(); open();
} }
@ -373,7 +374,7 @@ bool CUDPSocket::write(const unsigned char* buffer, unsigned int length, const s
void CUDPSocket::close() void CUDPSocket::close()
{ {
for (int i = 0; i < UDP_SOCKET_MAX; i++) for (unsigned int i = 0; i < UDP_SOCKET_MAX; i++)
close(i); close(i);
} }

View File

@ -46,13 +46,13 @@ enum IPMATCHTYPE {
class CUDPSocket { class CUDPSocket {
public: public:
CUDPSocket(const std::string& address, unsigned int port = 0U); CUDPSocket(const std::string& address, unsigned short port = 0U);
CUDPSocket(unsigned int port = 0U); CUDPSocket(unsigned short port = 0U);
~CUDPSocket(); ~CUDPSocket();
bool open(unsigned int af = AF_UNSPEC); bool open(unsigned int af = AF_UNSPEC);
bool open(const sockaddr_storage& address); bool open(const sockaddr_storage& address);
bool open(const unsigned int index, const unsigned int af, const std::string& address, const unsigned int port); bool open(const unsigned int index, const unsigned int af, const std::string& address, const unsigned short port);
int read(unsigned char* buffer, unsigned int length, sockaddr_storage& address, unsigned int &address_length); int read(unsigned char* buffer, unsigned int length, sockaddr_storage& address, unsigned int &address_length);
bool write(const unsigned char* buffer, unsigned int length, const sockaddr_storage& address, unsigned int address_length); bool write(const unsigned char* buffer, unsigned int length, const sockaddr_storage& address, unsigned int address_length);
@ -63,8 +63,8 @@ public:
static void startup(); static void startup();
static void shutdown(); static void shutdown();
static int lookup(const std::string& hostName, unsigned int port, sockaddr_storage& address, unsigned int& address_length); static int lookup(const std::string& hostName, unsigned short port, sockaddr_storage& address, unsigned int& address_length);
static int lookup(const std::string& hostName, unsigned int port, sockaddr_storage& address, unsigned int& address_length, struct addrinfo& hints); static int lookup(const std::string& hostName, unsigned short port, sockaddr_storage& address, unsigned int& address_length, struct addrinfo& hints);
static bool match(const sockaddr_storage& addr1, const sockaddr_storage& addr2, IPMATCHTYPE type = IMT_ADDRESS_AND_PORT); static bool match(const sockaddr_storage& addr1, const sockaddr_storage& addr2, IPMATCHTYPE type = IMT_ADDRESS_AND_PORT);