mirror of
https://github.com/ShaYmez/P25Clients.git
synced 2025-02-03 09:44:12 -05:00
Merge pull request #198 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:
commit
bcb473d10a
@ -141,9 +141,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)
|
||||
@ -173,7 +173,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, "HostsFile1") == 0)
|
||||
m_networkHosts1 = value;
|
||||
else if (::strcmp(key, "HostsFile2") == 0)
|
||||
@ -183,11 +183,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, "P252DMRAddress") == 0)
|
||||
m_networkP252DMRAddress = value;
|
||||
else if (::strcmp(key, "P252DMRPort") == 0)
|
||||
m_networkP252DMRPort = (unsigned int)::atoi(value);
|
||||
m_networkP252DMRPort = (unsigned short)::atoi(value);
|
||||
else if (::strcmp(key, "Static") == 0) {
|
||||
char* p = ::strtok(value, ",\r\n");
|
||||
while (p != NULL) {
|
||||
@ -205,7 +205,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);
|
||||
}
|
||||
}
|
||||
|
||||
@ -224,12 +224,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;
|
||||
}
|
||||
@ -294,7 +294,7 @@ bool CConf::getLogFileRotate() const
|
||||
return m_logFileRotate;
|
||||
}
|
||||
|
||||
unsigned int CConf::getNetworkPort() const
|
||||
unsigned short CConf::getNetworkPort() const
|
||||
{
|
||||
return m_networkPort;
|
||||
}
|
||||
@ -319,7 +319,7 @@ std::string CConf::getNetworkParrotAddress() const
|
||||
return m_networkParrotAddress;
|
||||
}
|
||||
|
||||
unsigned int CConf::getNetworkParrotPort() const
|
||||
unsigned short CConf::getNetworkParrotPort() const
|
||||
{
|
||||
return m_networkParrotPort;
|
||||
}
|
||||
@ -329,7 +329,7 @@ std::string CConf::getNetworkP252DMRAddress() const
|
||||
return m_networkP252DMRAddress;
|
||||
}
|
||||
|
||||
unsigned int CConf::getNetworkP252DMRPort() const
|
||||
unsigned short CConf::getNetworkP252DMRPort() const
|
||||
{
|
||||
return m_networkP252DMRPort;
|
||||
}
|
||||
@ -359,7 +359,7 @@ bool CConf::getRemoteCommandsEnabled() const
|
||||
return m_remoteCommandsEnabled;
|
||||
}
|
||||
|
||||
unsigned int CConf::getRemoteCommandsPort() const
|
||||
unsigned short CConf::getRemoteCommandsPort() const
|
||||
{
|
||||
return m_remoteCommandsPort;
|
||||
}
|
||||
|
@ -33,8 +33,8 @@ public:
|
||||
// The General section
|
||||
std::string getCallsign() 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;
|
||||
|
||||
@ -55,14 +55,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 getNetworkP252DMRAddress() const;
|
||||
unsigned int getNetworkP252DMRPort() const;
|
||||
unsigned short getNetworkP252DMRPort() const;
|
||||
std::vector<unsigned int> getNetworkStatic() const;
|
||||
unsigned int getNetworkRFHangTime() const;
|
||||
unsigned int getNetworkNetHangTime() const;
|
||||
@ -70,14 +70,14 @@ public:
|
||||
|
||||
// The Remote Commands section
|
||||
bool getRemoteCommandsEnabled() const;
|
||||
unsigned int getRemoteCommandsPort() const;
|
||||
unsigned short getRemoteCommandsPort() const;
|
||||
|
||||
private:
|
||||
std::string m_file;
|
||||
std::string m_callsign;
|
||||
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;
|
||||
|
||||
@ -94,21 +94,21 @@ private:
|
||||
std::string m_logFileRoot;
|
||||
bool m_logFileRotate;
|
||||
|
||||
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_networkP252DMRAddress;
|
||||
unsigned int m_networkP252DMRPort;
|
||||
unsigned short m_networkP252DMRPort;
|
||||
std::vector<unsigned int> m_networkStatic;;
|
||||
unsigned int m_networkRFHangTime;
|
||||
unsigned int m_networkNetHangTime;
|
||||
bool m_networkDebug;
|
||||
|
||||
bool m_remoteCommandsEnabled;
|
||||
unsigned int m_remoteCommandsPort;
|
||||
unsigned short m_remoteCommandsPort;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
@ -24,7 +24,7 @@
|
||||
#include <cassert>
|
||||
#include <cstring>
|
||||
|
||||
CP25Network::CP25Network(unsigned int port, const std::string& callsign, bool debug) :
|
||||
CP25Network::CP25Network(unsigned short port, const std::string& callsign, bool debug) :
|
||||
m_callsign(callsign),
|
||||
m_socket(),
|
||||
m_port(port),
|
||||
|
@ -26,7 +26,7 @@
|
||||
|
||||
class CP25Network {
|
||||
public:
|
||||
CP25Network(unsigned int port, const std::string& callsign, bool debug);
|
||||
CP25Network(unsigned short port, const std::string& callsign, bool debug);
|
||||
~CP25Network();
|
||||
|
||||
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;
|
||||
};
|
||||
|
||||
|
@ -48,13 +48,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::setP252DMR(const std::string& address, unsigned int port)
|
||||
void CReflectors::setP252DMR(const std::string& address, unsigned short port)
|
||||
{
|
||||
m_p252dmrAddress = address;
|
||||
m_p252dmrPort = port;
|
||||
@ -81,7 +81,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;
|
||||
@ -116,7 +116,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;
|
||||
|
@ -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 setP252DMR(const std::string& address, unsigned int port);
|
||||
void setParrot(const std::string& address, unsigned short port);
|
||||
void setP252DMR(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_p252dmrAddress;
|
||||
unsigned int m_p252dmrPort;
|
||||
unsigned short m_p252dmrPort;
|
||||
std::vector<CP25Reflector*> m_reflectors;
|
||||
CTimer m_timer;
|
||||
};
|
||||
|
@ -24,7 +24,7 @@
|
||||
#include <cassert>
|
||||
#include <cstring>
|
||||
|
||||
CRptNetwork::CRptNetwork(unsigned int myPort, const sockaddr_storage& rptAddr, unsigned int rptAddrLen, const std::string& callsign, bool debug) :
|
||||
CRptNetwork::CRptNetwork(unsigned short myPort, const sockaddr_storage& rptAddr, unsigned int rptAddrLen, const std::string& callsign, bool debug) :
|
||||
m_rptAddr(rptAddr),
|
||||
m_rptAddrLen(rptAddrLen),
|
||||
m_callsign(callsign),
|
||||
|
@ -27,7 +27,7 @@
|
||||
|
||||
class CRptNetwork {
|
||||
public:
|
||||
CRptNetwork(unsigned int myPort, const sockaddr_storage& rptAddr, unsigned int rptAddrLen, const std::string& callsign, bool debug);
|
||||
CRptNetwork(unsigned short myPort, const sockaddr_storage& rptAddr, unsigned int rptAddrLen, const std::string& callsign, bool debug);
|
||||
~CRptNetwork();
|
||||
|
||||
bool open();
|
||||
|
@ -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();
|
||||
}
|
||||
|
@ -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);
|
||||
|
||||
|
@ -24,7 +24,7 @@
|
||||
|
||||
const unsigned int BUFFER_LENGTH = 200U;
|
||||
|
||||
CNetwork::CNetwork(unsigned int port) :
|
||||
CNetwork::CNetwork(unsigned short port) :
|
||||
m_socket(port),
|
||||
m_addr(),
|
||||
m_addrLen(0U)
|
||||
|
@ -26,7 +26,7 @@
|
||||
|
||||
class CNetwork {
|
||||
public:
|
||||
CNetwork(unsigned int port);
|
||||
CNetwork(unsigned short port);
|
||||
~CNetwork();
|
||||
|
||||
bool open();
|
||||
|
@ -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, "P25Parrot: invalid port number - %s\n", argv[1U]);
|
||||
return 1;
|
||||
@ -47,7 +47,7 @@ int main(int argc, char** argv)
|
||||
return 0;
|
||||
}
|
||||
|
||||
CP25Parrot::CP25Parrot(unsigned int port) :
|
||||
CP25Parrot::CP25Parrot(unsigned short port) :
|
||||
m_port(port)
|
||||
{
|
||||
CUDPSocket::startup();
|
||||
|
@ -22,13 +22,13 @@
|
||||
class CP25Parrot
|
||||
{
|
||||
public:
|
||||
CP25Parrot(unsigned int port);
|
||||
CP25Parrot(unsigned short port);
|
||||
~CP25Parrot();
|
||||
|
||||
void run();
|
||||
|
||||
private:
|
||||
unsigned int m_port;
|
||||
unsigned short m_port;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
@ -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();
|
||||
}
|
||||
|
@ -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);
|
||||
|
||||
|
@ -129,7 +129,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;
|
||||
}
|
||||
@ -180,7 +180,7 @@ bool CConf::getLogFileRotate() const
|
||||
return m_logFileRotate;
|
||||
}
|
||||
|
||||
unsigned int CConf::getNetworkPort() const
|
||||
unsigned short CConf::getNetworkPort() const
|
||||
{
|
||||
return m_networkPort;
|
||||
}
|
||||
|
@ -45,7 +45,7 @@ public:
|
||||
bool getLogFileRotate() const;
|
||||
|
||||
// The Network section
|
||||
unsigned int getNetworkPort() const;
|
||||
unsigned short getNetworkPort() const;
|
||||
bool getNetworkDebug() const;
|
||||
|
||||
private:
|
||||
@ -61,7 +61,7 @@ private:
|
||||
std::string m_logFileRoot;
|
||||
bool m_logFileRotate;
|
||||
|
||||
unsigned int m_networkPort;
|
||||
unsigned short m_networkPort;
|
||||
bool m_networkDebug;
|
||||
};
|
||||
|
||||
|
@ -24,7 +24,7 @@
|
||||
#include <cassert>
|
||||
#include <cstring>
|
||||
|
||||
CNetwork::CNetwork(unsigned int port, bool debug) :
|
||||
CNetwork::CNetwork(unsigned short port, bool debug) :
|
||||
m_socket(port),
|
||||
m_debug(debug)
|
||||
{
|
||||
|
@ -26,7 +26,7 @@
|
||||
|
||||
class CNetwork {
|
||||
public:
|
||||
CNetwork(unsigned int port, bool debug);
|
||||
CNetwork(unsigned short port, bool debug);
|
||||
~CNetwork();
|
||||
|
||||
bool open();
|
||||
|
@ -356,8 +356,8 @@ void CP25Reflector::dumpRepeaters() const
|
||||
for (std::vector<CP25Repeater*>::const_iterator it = m_repeaters.begin(); it != m_repeaters.end(); ++it) {
|
||||
char buffer[80U];
|
||||
LogMessage(" %s: %s %u/%u", (*it)->m_callsign.c_str(),
|
||||
CUDPSocket::display((*it)->m_addr, buffer, 80U),
|
||||
(*it)->m_timer.getTimeout(),
|
||||
(*it)->m_timer.getTimeout());
|
||||
CUDPSocket::display((*it)->m_addr, buffer, 80U),
|
||||
(*it)->m_timer.getTimeout(),
|
||||
(*it)->m_timer.getTimeout());
|
||||
}
|
||||
}
|
||||
|
@ -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;
|
||||
@ -167,17 +168,17 @@ char* CUDPSocket::display(const sockaddr_storage& addr, char* buffer, unsigned i
|
||||
|
||||
switch (addr.ss_family) {
|
||||
case AF_INET: {
|
||||
struct sockaddr_in* in4 = (struct sockaddr_in*)&addr;
|
||||
::inet_ntop(AF_INET, &in4, buffer, length);
|
||||
::sprintf(buffer + ::strlen(buffer), ":%u", in4->sin_port);
|
||||
}
|
||||
struct sockaddr_in* in4 = (struct sockaddr_in*)&addr;
|
||||
::inet_ntop(AF_INET, &in4, buffer, length);
|
||||
::sprintf(buffer + ::strlen(buffer), ":%u", in4->sin_port);
|
||||
}
|
||||
break;
|
||||
|
||||
case AF_INET6: {
|
||||
struct sockaddr_in6* in6 = (struct sockaddr_in6*)&addr;
|
||||
::inet_ntop(AF_INET6, &in6, buffer, length);
|
||||
::sprintf(buffer + ::strlen(buffer), ":%u", in6->sin6_port);
|
||||
}
|
||||
struct sockaddr_in6* in6 = (struct sockaddr_in6*)&addr;
|
||||
::inet_ntop(AF_INET6, &in6, buffer, length);
|
||||
::sprintf(buffer + ::strlen(buffer), ":%u", in6->sin6_port);
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
@ -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();
|
||||
}
|
||||
|
@ -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);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user