Skip to content

Commit

Permalink
UDP does not bind on send only port. Fixes: #3127
Browse files Browse the repository at this point in the history
  • Loading branch information
LeStarch committed Jan 16, 2025
1 parent 334c525 commit 195d16d
Showing 1 changed file with 19 additions and 8 deletions.
27 changes: 19 additions & 8 deletions Drv/Ip/UdpSocket.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -151,23 +151,34 @@ SocketIpStatus UdpSocket::openProtocol(SocketDescriptor& socketDescriptor) {
memcpy(&this->m_state->m_addr_send, &address, sizeof(this->m_state->m_addr_send));
}

// When we are setting up for receiving as well, then we must bind to a port
if ((status = this->bind(socketFd)) != SOCK_SUCCESS) {
::close(socketFd);
return status; // Not closing FD as it is still a valid send FD
}
// Receive port set up only done when configure receive was called
U16 recv_port = this->m_recv_port;
if (recv_port != 0) {
// When we are setting up for receiving as well, then we must bind to a port
if ((status = this->bind(socketFd)) != SOCK_SUCCESS) {

Check warning

Code scanning / CodeQL

Side effect in a Boolean expression Warning

This Boolean expression is not side-effect free.
::close(socketFd); // Closing FD as a retry will reopen send side

Check warning

Code scanning / CodeQL

Unchecked return value Warning

The return value of non-void function
close
is not checked.
return status;
}
}

// Log message for UDP
if (port == 0) {
Fw::Logger::log("Setup to receive udp at %s:%hu\n", m_recv_hostname,
if ((port == 0) && (recv_port > 0)) {
Fw::Logger::log("Setup to only receive udp at %s:%hu\n", m_recv_hostname,
recv_port);
} else {
} else if ((port > 0) && (recv_port == 0)) {
Fw::Logger::log("Setup to only send udp at %s:%hu\n", m_hostname,
port);
} else if ((port > 0) && (recv_port > 0)) {
Fw::Logger::log("Setup to receive udp at %s:%hu and send to %s:%hu\n",
m_recv_hostname,
recv_port,
m_hostname,
port);
}
// Neither configuration method was called
else {
FW_ASSERT(port > 0 || recv_port > 0, port, recv_port);
}
FW_ASSERT(status == SOCK_SUCCESS, status);
socketDescriptor.fd = socketFd;
return status;
Expand Down

0 comments on commit 195d16d

Please sign in to comment.