Dev/fix port size (#805)

* port datatype changing from int to uint16_t
* throwing for -1 given for uint16_t ports
This commit is contained in:
2023-09-28 09:36:39 +02:00
committed by GitHub
parent 77d13f0794
commit 9834b07b47
61 changed files with 519 additions and 345 deletions

View File

@@ -10,6 +10,7 @@
#include <cstring>
#include <ifaddrs.h>
#include <iomanip>
#include <limits>
#include <net/if.h>
#include <netdb.h>
#include <sstream>
@@ -203,4 +204,18 @@ MacAddr InterfaceNameToMac(const std::string &inf) {
return MacAddr(mac);
}
void validatePortNumber(uint16_t port) {
// random local port. might work if internal = bad practise
if (port == 0) {
throw RuntimeError("Invalid port number. Must be between 1 - 65535.");
}
}
void validatePortRange(uint16_t startPort, int numPorts) {
validatePortNumber(startPort);
if ((startPort + numPorts) > std::numeric_limits<uint16_t>::max()) {
throw RuntimeError("Invalid port range. Must be between 1 - 65535.");
}
}
} // namespace sls