From 13e39b09274845051c8596e0bf498022ee5db441 Mon Sep 17 00:00:00 2001 From: Bryan Biedenkapp Date: Wed, 28 Apr 2021 19:35:36 +0000 Subject: [PATCH] upstream: fix network ports data type; --- host/Host.cpp | 8 ++++---- modem/port/UDPPort.cpp | 2 +- modem/port/UDPPort.h | 2 +- network/BaseNetwork.cpp | 2 +- network/BaseNetwork.h | 2 +- network/Network.cpp | 4 ++-- network/Network.h | 4 ++-- network/RemoteControl.cpp | 2 +- network/RemoteControl.h | 2 +- network/UDPSocket.cpp | 14 ++++++-------- network/UDPSocket.h | 10 +++++----- 11 files changed, 25 insertions(+), 27 deletions(-) diff --git a/host/Host.cpp b/host/Host.cpp index 834290f0..548af8e0 100644 --- a/host/Host.cpp +++ b/host/Host.cpp @@ -1354,7 +1354,7 @@ bool Host::createModem() yaml::Node udpProtocol = modemProtocol["udp"]; std::string udpMode = udpProtocol["mode"].as("master"); std::string udpAddress = udpProtocol["endpointAddress"].as(); - uint32_t udpPort = udpProtocol["port"].as(REMOTE_MODEM_PORT); + uint16_t udpPort = (uint16_t)udpProtocol["port"].as(REMOTE_MODEM_PORT); bool rxInvert = modemConf["rxInvert"].as(false); bool txInvert = modemConf["txInvert"].as(false); @@ -1513,11 +1513,11 @@ bool Host::createNetwork() { yaml::Node networkConf = m_conf["network"]; std::string address = networkConf["address"].as(); - uint32_t port = networkConf["port"].as(TRAFFIC_DEFAULT_PORT); - uint32_t local = networkConf["local"].as(0U); + uint16_t port = (uint16_t)networkConf["port"].as(TRAFFIC_DEFAULT_PORT); + uint16_t local = (uint16_t)networkConf["local"].as(0U); bool rconEnable = networkConf["rconEnable"].as(false); std::string rconAddress = networkConf["rconAddress"].as("127.0.0.1"); - uint32_t rconPort = networkConf["rconPort"].as(RCON_DEFAULT_PORT); + uint16_t rconPort = (uint16_t)networkConf["rconPort"].as(RCON_DEFAULT_PORT); std::string rconPassword = networkConf["rconPassword"].as(); bool rconDebug = networkConf["rconDebug"].as(false); uint32_t id = networkConf["id"].as(0U); diff --git a/modem/port/UDPPort.cpp b/modem/port/UDPPort.cpp index 1010271e..291ddc84 100644 --- a/modem/port/UDPPort.cpp +++ b/modem/port/UDPPort.cpp @@ -54,7 +54,7 @@ const uint32_t BUFFER_LENGTH = 2000U; /// Hostname/IP address to connect to. /// Port number. /// -UDPPort::UDPPort(const std::string& address, uint32_t modemPort) : +UDPPort::UDPPort(const std::string& address, uint16_t modemPort) : m_socket(modemPort), m_addr(), m_addrLen(0U), diff --git a/modem/port/UDPPort.h b/modem/port/UDPPort.h index 5772f50b..e0ad8d44 100644 --- a/modem/port/UDPPort.h +++ b/modem/port/UDPPort.h @@ -50,7 +50,7 @@ namespace modem class HOST_SW_API UDPPort : public IModemPort { public: /// Initializes a new instance of the UDPPort class. - UDPPort(const std::string& modemAddress, uint32_t modemPort); + UDPPort(const std::string& modemAddress, uint16_t modemPort); /// Finalizes a instance of the UDPPort class. virtual ~UDPPort(); diff --git a/network/BaseNetwork.cpp b/network/BaseNetwork.cpp index 8576a723..7755fb70 100644 --- a/network/BaseNetwork.cpp +++ b/network/BaseNetwork.cpp @@ -54,7 +54,7 @@ using namespace network; /// Flag indicating whether DMR slot 2 is enabled for network traffic. /// Flag indicating that the system activity logs will be sent to the network. /// Flag indicating that the system diagnostic logs will be sent to the network. -BaseNetwork::BaseNetwork(uint32_t localPort, uint32_t id, bool duplex, bool debug, bool slot1, bool slot2, bool allowActivityTransfer, bool allowDiagnosticTransfer) : +BaseNetwork::BaseNetwork(uint16_t localPort, uint32_t id, bool duplex, bool debug, bool slot1, bool slot2, bool allowActivityTransfer, bool allowDiagnosticTransfer) : m_id(id), m_slot1(slot1), m_slot2(slot2), diff --git a/network/BaseNetwork.h b/network/BaseNetwork.h index 53bc4c04..d9b19dbf 100644 --- a/network/BaseNetwork.h +++ b/network/BaseNetwork.h @@ -190,7 +190,7 @@ namespace network class HOST_SW_API BaseNetwork { public: /// Initializes a new instance of the BaseNetwork class. - BaseNetwork(uint32_t localPort, uint32_t id, bool duplex, bool debug, bool slot1, bool slot2, bool transferActivityLog, bool transferDiagnosticLog); + BaseNetwork(uint16_t localPort, uint32_t id, bool duplex, bool debug, bool slot1, bool slot2, bool transferActivityLog, bool transferDiagnosticLog); /// Finalizes a instance of the BaseNetwork class. virtual ~BaseNetwork(); diff --git a/network/Network.cpp b/network/Network.cpp index 34e20331..c450c73a 100644 --- a/network/Network.cpp +++ b/network/Network.cpp @@ -58,7 +58,7 @@ using namespace network; /// Flag indicating that the system activity logs will be sent to the network. /// Flag indicating that the system diagnostic logs will be sent to the network. /// Flag indicating that the system will accept radio ID and talkgroup ID lookups from the network. -Network::Network(const std::string& address, uint32_t port, uint32_t local, uint32_t id, const std::string& password, +Network::Network(const std::string& address, uint16_t port, uint16_t local, uint32_t id, const std::string& password, bool duplex, bool debug, bool slot1, bool slot2, bool allowActivityTransfer, bool allowDiagnosticTransfer, bool updateLookup) : BaseNetwork(local, id, duplex, debug, slot1, slot2, allowActivityTransfer, allowDiagnosticTransfer), m_address(address), @@ -185,7 +185,7 @@ void Network::clock(uint32_t ms) } sockaddr_storage address; - unsigned int addrLen; + uint32_t addrLen; int length = m_socket.read(m_buffer, DATA_PACKET_LENGTH, address, addrLen); if (length < 0) { LogError(LOG_NET, "Socket has failed, retrying connection to the master"); diff --git a/network/Network.h b/network/Network.h index b737d14e..c7d767b3 100644 --- a/network/Network.h +++ b/network/Network.h @@ -49,7 +49,7 @@ namespace network class HOST_SW_API Network : public BaseNetwork { public: /// Initializes a new instance of the Network class. - Network(const std::string& address, uint32_t port, uint32_t local, uint32_t id, const std::string& password, + Network(const std::string& address, uint16_t port, uint16_t local, uint32_t id, const std::string& password, bool duplex, bool debug, bool slot1, bool slot2, bool transferActivityLog, bool transferDiagnosticLog, bool updateLookup); /// Finalizes a instance of the Network class. ~Network(); @@ -78,7 +78,7 @@ namespace network private: std::string m_address; - unsigned int m_port; + uint16_t m_port; std::string m_password; diff --git a/network/RemoteControl.cpp b/network/RemoteControl.cpp index 8a6aea40..39b4161a 100644 --- a/network/RemoteControl.cpp +++ b/network/RemoteControl.cpp @@ -108,7 +108,7 @@ const uint32_t RC_BUFFER_LENGTH = 140U; /// Network port number. /// Authentication password. /// -RemoteControl::RemoteControl(const std::string& address, uint32_t port, const std::string& password, bool debug) : +RemoteControl::RemoteControl(const std::string& address, uint16_t port, const std::string& password, bool debug) : m_socket(address, port), m_p25MFId(p25::P25_MFG_STANDARD), m_password(password), diff --git a/network/RemoteControl.h b/network/RemoteControl.h index 249f57de..8e6e70c0 100644 --- a/network/RemoteControl.h +++ b/network/RemoteControl.h @@ -57,7 +57,7 @@ namespace p25 { class HOST_SW_API Control; } class HOST_SW_API RemoteControl { public: /// Initializes a new instance of the RemoteControl class. - RemoteControl(const std::string& address, uint32_t port, const std::string& password, bool debug); + RemoteControl(const std::string& address, uint16_t port, const std::string& password, bool debug); /// Finalizes a instance of the RemoteControl class. ~RemoteControl(); diff --git a/network/UDPSocket.cpp b/network/UDPSocket.cpp index 7ea661ff..00586a77 100644 --- a/network/UDPSocket.cpp +++ b/network/UDPSocket.cpp @@ -49,7 +49,7 @@ using namespace network; /// /// Hostname/IP address to connect to. /// Port number. -UDPSocket::UDPSocket(const std::string& address, uint32_t port) : +UDPSocket::UDPSocket(const std::string& address, uint16_t port) : m_address_save(address), m_port_save(port), m_counter(0U) @@ -66,7 +66,7 @@ UDPSocket::UDPSocket(const std::string& address, uint32_t port) : /// Initializes a new instance of the UDPSocket class. /// /// Port number. -UDPSocket::UDPSocket(uint32_t port) : +UDPSocket::UDPSocket(uint16_t port) : m_address_save(), m_port_save(port), m_counter(0U) @@ -115,7 +115,7 @@ bool UDPSocket::open(uint32_t af) /// /// /// True, if UDP socket is opened, otherwise false. -bool UDPSocket::open(const uint32_t index, const uint32_t af, const std::string& address, const uint32_t port) +bool UDPSocket::open(const uint32_t index, const uint32_t af, const std::string& address, const uint16_t port) { sockaddr_storage addr; uint32_t addrlen; @@ -362,7 +362,7 @@ void UDPSocket::shutdown() /// Socket address structure. /// /// Zero if no error during lookup, otherwise error. -int UDPSocket::lookup(const std::string& hostname, uint32_t port, sockaddr_storage& addr, uint32_t& addrLen) +int UDPSocket::lookup(const std::string& hostname, uint16_t port, sockaddr_storage& addr, uint32_t& addrLen) { struct addrinfo hints; ::memset(&hints, 0, sizeof(hints)); @@ -379,12 +379,12 @@ int UDPSocket::lookup(const std::string& hostname, uint32_t port, sockaddr_stora /// /// /// Zero if no error during lookup, otherwise error. -int UDPSocket::lookup(const std::string& hostname, uint32_t port, sockaddr_storage& addr, uint32_t& addrLen, struct addrinfo& hints) +int UDPSocket::lookup(const std::string& hostname, uint16_t port, sockaddr_storage& addr, uint32_t& addrLen, struct addrinfo& hints) { std::string portstr = std::to_string(port); struct addrinfo* res; - /* port is always digits, no needs to lookup service */ + // port is always digits, no needs to lookup service hints.ai_flags |= AI_NUMERICSERV; int err = getaddrinfo(hostname.empty() ? NULL : hostname.c_str(), portstr.c_str(), &hints, &res); @@ -464,8 +464,6 @@ std::string UDPSocket::address(const sockaddr_storage& addr) std::string address = std::string(); char str[INET_ADDRSTRLEN]; - - switch (addr.ss_family) { case AF_INET: { diff --git a/network/UDPSocket.h b/network/UDPSocket.h index 16ef0246..85b2753f 100644 --- a/network/UDPSocket.h +++ b/network/UDPSocket.h @@ -69,9 +69,9 @@ namespace network class HOST_SW_API UDPSocket { public: /// Initializes a new instance of the UDPSocket class. - UDPSocket(const std::string& address, uint32_t port = 0U); + UDPSocket(const std::string& address, uint16_t port = 0U); /// Initializes a new instance of the UDPSocket class. - UDPSocket(uint32_t port = 0U); + UDPSocket(uint16_t port = 0U); /// Initializes a new instance of the UDPSocket class. ~UDPSocket(); @@ -80,7 +80,7 @@ namespace network /// Opens UDP socket connection. bool open(const sockaddr_storage& address); /// Opens UDP socket connection. - bool open(const uint32_t index, const uint32_t af, const std::string& address, const uint32_t port); + bool open(const uint32_t index, const uint32_t af, const std::string& address, const uint16_t port); /// Read data from the UDP socket. int read(uint8_t* buffer, uint32_t length, sockaddr_storage& address, uint32_t& addrLen); @@ -98,9 +98,9 @@ namespace network static void shutdown(); /// Helper to lookup a hostname and resolve it to an IP address. - static int lookup(const std::string& hostName, uint32_t port, sockaddr_storage& address, uint32_t& addrLen); + static int lookup(const std::string& hostName, uint16_t port, sockaddr_storage& address, uint32_t& addrLen); /// Helper to lookup a hostname and resolve it to an IP address. - static int lookup(const std::string& hostName, uint32_t port, sockaddr_storage& address, uint32_t& addrLen, struct addrinfo& hints); + static int lookup(const std::string& hostName, uint16_t port, sockaddr_storage& address, uint32_t& addrLen, struct addrinfo& hints); /// static bool match(const sockaddr_storage& addr1, const sockaddr_storage& addr2, IPMATCHTYPE type = IMT_ADDRESS_AND_PORT);