Merge pull request #171 from f1rmb/f1rmb_network_port_datatype

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:
Jonathan Naylor 2021-04-25 09:38:10 +01:00 committed by GitHub
commit 1060962c12
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
27 changed files with 99 additions and 97 deletions

View File

@ -24,7 +24,7 @@
#include <cstring>
#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_callsign(callsign),
m_debug(debug),

View File

@ -42,7 +42,7 @@
class CAPRSWriter {
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();
bool open();

View File

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

View File

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

View File

@ -26,7 +26,7 @@
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_addr(),
m_addrLen(0U),

View File

@ -27,7 +27,7 @@
class CIcomNetwork : public IRptNetwork {
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 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;
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_rtcpSocket(localPort + 1U),
m_rtcpAddr(),

View File

@ -29,7 +29,7 @@
class CKenwoodNetwork : public IRptNetwork {
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 bool open();

View File

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

View File

@ -24,7 +24,7 @@
#include <cassert>
#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_socket(),
m_port(port),

View File

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

View File

@ -46,13 +46,13 @@ CReflectors::~CReflectors()
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_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_nxdn2dmrPort = port;
@ -79,7 +79,7 @@ bool CReflectors::load()
if (p1 != NULL && p2 != NULL && p3 != NULL) {
std::string host = std::string(p2);
unsigned int port = (unsigned int)::atoi(p3);
unsigned short port = (unsigned short)::atoi(p3);
sockaddr_storage addr;
unsigned int addrLen;
@ -114,7 +114,7 @@ bool CReflectors::load()
unsigned int id = (unsigned int)::atoi(p1);
if (find(id) == NULL) {
std::string host = std::string(p2);
unsigned int port = (unsigned int)::atoi(p3);
unsigned short port = (unsigned short)::atoi(p3);
sockaddr_storage addr;
unsigned int addrLen;

View File

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

View File

@ -28,11 +28,12 @@
#if defined(HAVE_LOG_H)
#include "Log.h"
#else
#define LogMessage(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__)
#endif
CUDPSocket::CUDPSocket(const std::string& address, unsigned int port) :
CUDPSocket::CUDPSocket(const std::string& address, unsigned short port) :
m_address_save(address),
m_port_save(port),
m_counter(0U)
@ -45,7 +46,7 @@ m_counter(0U)
}
}
CUDPSocket::CUDPSocket(unsigned int port) :
CUDPSocket::CUDPSocket(unsigned short port) :
m_address_save(),
m_port_save(port),
m_counter(0U)
@ -79,7 +80,7 @@ void CUDPSocket::shutdown()
#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;
::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);
}
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);
struct addrinfo *res;
@ -170,7 +171,7 @@ bool CUDPSocket::open(unsigned int af)
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;
unsigned int addrlen;
@ -224,7 +225,7 @@ bool CUDPSocket::open(const unsigned int index, const unsigned int af, const std
return false;
}
LogInfo("Opening UDP port on %u", port);
LogInfo("Opening UDP port on %hu", port);
}
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);
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();
open();
}

View File

@ -46,13 +46,13 @@ enum IPMATCHTYPE {
class CUDPSocket {
public:
CUDPSocket(const std::string& address, unsigned int port = 0U);
CUDPSocket(unsigned int port = 0U);
CUDPSocket(const std::string& address, unsigned short port = 0U);
CUDPSocket(unsigned short port = 0U);
~CUDPSocket();
bool open(unsigned int af = AF_UNSPEC);
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);
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 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 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);
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);

View File

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

View File

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

View File

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

View File

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

View File

@ -33,7 +33,7 @@
#define LogInfo(fmt, ...) ::fprintf(stderr, fmt "\n", ## __VA_ARGS__)
#endif
CUDPSocket::CUDPSocket(const std::string& address, unsigned int port) :
CUDPSocket::CUDPSocket(const std::string& address, unsigned short port) :
m_address_save(address),
m_port_save(port),
m_counter(0U)
@ -46,7 +46,7 @@ m_counter(0U)
}
}
CUDPSocket::CUDPSocket(unsigned int port) :
CUDPSocket::CUDPSocket(unsigned short port) :
m_address_save(),
m_port_save(port),
m_counter(0U)
@ -80,7 +80,7 @@ void CUDPSocket::shutdown()
#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;
::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);
}
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);
struct addrinfo *res;
@ -171,7 +171,7 @@ bool CUDPSocket::open(unsigned int af)
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;
unsigned int addrlen;
@ -225,7 +225,7 @@ bool CUDPSocket::open(const unsigned int index, const unsigned int af, const std
return false;
}
LogInfo("Opening UDP port on %u", port);
LogInfo("Opening UDP port on %hu", port);
}
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);
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();
open();
}

View File

@ -46,13 +46,13 @@ enum IPMATCHTYPE {
class CUDPSocket {
public:
CUDPSocket(const std::string& address, unsigned int port = 0U);
CUDPSocket(unsigned int port = 0U);
CUDPSocket(const std::string& address, unsigned short port = 0U);
CUDPSocket(unsigned short port = 0U);
~CUDPSocket();
bool open(unsigned int af = AF_UNSPEC);
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);
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 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 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);
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);

View File

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

View File

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

View File

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

View File

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

View File

@ -28,11 +28,12 @@
#if defined(HAVE_LOG_H)
#include "Log.h"
#else
#define LogMessage(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__)
#endif
CUDPSocket::CUDPSocket(const std::string& address, unsigned int port) :
CUDPSocket::CUDPSocket(const std::string& address, unsigned short port) :
m_address_save(address),
m_port_save(port),
m_counter(0U)
@ -45,7 +46,7 @@ m_counter(0U)
}
}
CUDPSocket::CUDPSocket(unsigned int port) :
CUDPSocket::CUDPSocket(unsigned short port) :
m_address_save(),
m_port_save(port),
m_counter(0U)
@ -79,7 +80,7 @@ void CUDPSocket::shutdown()
#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;
::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);
}
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);
struct addrinfo *res;
@ -198,7 +199,7 @@ bool CUDPSocket::open(unsigned int af)
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;
unsigned int addrlen;
@ -252,7 +253,7 @@ bool CUDPSocket::open(const unsigned int index, const unsigned int af, const std
return false;
}
LogInfo("Opening UDP port on %u", port);
LogInfo("Opening UDP port on %hu", port);
}
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);
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();
open();
}
@ -373,7 +374,7 @@ bool CUDPSocket::write(const unsigned char* buffer, unsigned int length, const s
void CUDPSocket::close()
{
for (int i = 0; i < UDP_SOCKET_MAX; i++)
for (unsigned int i = 0; i < UDP_SOCKET_MAX; i++)
close(i);
}

View File

@ -46,13 +46,13 @@ enum IPMATCHTYPE {
class CUDPSocket {
public:
CUDPSocket(const std::string& address, unsigned int port = 0U);
CUDPSocket(unsigned int port = 0U);
CUDPSocket(const std::string& address, unsigned short port = 0U);
CUDPSocket(unsigned short port = 0U);
~CUDPSocket();
bool open(unsigned int af = AF_UNSPEC);
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);
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 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 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);
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);