new ports

This commit is contained in:
Robin Müller 2020-07-05 18:22:39 +02:00
parent 9e2fa16550
commit 26ab1983dc
2 changed files with 48 additions and 2 deletions

View File

@ -39,6 +39,7 @@ TmTcUnixUdpBridge::TmTcUnixUdpBridge(object_id_t objectId,
"local port " << setServerPort << " to server socket!" "local port " << setServerPort << " to server socket!"
<< std::endl; << std::endl;
// check errno here. // check errno here.
handleBindError();
return; return;
} }
} }
@ -59,6 +60,7 @@ ReturnValue_t TmTcUnixUdpBridge::sendTm(const uint8_t *data, size_t dataLen) {
} }
void TmTcUnixUdpBridge::handleSocketError() { void TmTcUnixUdpBridge::handleSocketError() {
// See: https://man7.org/linux/man-pages/man2/socket.2.html // See: https://man7.org/linux/man-pages/man2/socket.2.html
switch(errno) { switch(errno) {
case(EACCES): case(EACCES):
@ -71,5 +73,46 @@ void TmTcUnixUdpBridge::handleSocketError() {
case(EPROTONOSUPPORT): case(EPROTONOSUPPORT):
sif::error << "TmTcUnixBridge::TmTcUnixBridge: Socket creation failed" sif::error << "TmTcUnixBridge::TmTcUnixBridge: Socket creation failed"
<< " with " << strerror(errno) << std::endl; << " with " << strerror(errno) << std::endl;
break;
default:
sif::error << "TmTcUnixBridge::TmTcUnixBridge: Unknown error"
<< std::endl;
break;
} }
} }
void TmTcUnixUdpBridge::handleBindError() {
// See: https://man7.org/linux/man-pages/man2/bind.2.html
switch(errno) {
case(EACCES):
/*
Ephermeral ports can be shown with following command:
sysctl -A | grep ip_local_port_range
*/
sif::error << "TmTcUnixBridge::TmTcUnixBridge: Port access issue."
"Ports 1-1024 are reserved on UNIX systems and require root "
"rights while ephermeral ports should not be used as well."
<< std::endl;
break;
case(EADDRINUSE):
case(EBADF):
case(EINVAL):
case(ENOTSOCK):
case(EADDRNOTAVAIL):
case(EFAULT):
case(ELOOP):
case(ENAMETOOLONG):
case(ENOENT):
case(ENOMEM):
case(ENOTDIR):
case(EROFS):
sif::error << "TmTcUnixBridge::TmTcUnixBridge: Socket creation failed"
<< " with " << strerror(errno) << std::endl;
break;
default:
sif::error << "TmTcUnixBridge::TmTcUnixBridge: Unknown error"
<< std::endl;
break;
}
}

View File

@ -8,8 +8,10 @@
class TmTcUnixUdpBridge: public TmTcBridge { class TmTcUnixUdpBridge: public TmTcBridge {
public: public:
static constexpr int DEFAULT_UDP_SERVER_PORT = 7; // The ports chosen here should not be used by any other process.
static constexpr int DEFAULT_UDP_CLIENT_PORT = 2008; // List of used ports on Linux: /etc/services
static constexpr int DEFAULT_UDP_SERVER_PORT = 7301;
static constexpr int DEFAULT_UDP_CLIENT_PORT = 7302;
TmTcUnixUdpBridge(object_id_t objectId, object_id_t ccsdsPacketDistributor, TmTcUnixUdpBridge(object_id_t objectId, object_id_t ccsdsPacketDistributor,
uint16_t serverPort = 0xFFFF,uint16_t clientPort = 0xFFFF); uint16_t serverPort = 0xFFFF,uint16_t clientPort = 0xFFFF);
@ -27,6 +29,7 @@ private:
struct sockaddr_in serverAddress; struct sockaddr_in serverAddress;
void handleSocketError(); void handleSocketError();
void handleBindError();
}; };