Is there a simple (non-iterative) way to bind two sockets, one TCP and one UDP, that guarantees both have the same ephemeral port?
I have a simple server that's connected to via TCP initially, but also transmits over UDP. I don't want to send a UDP packet post-connect from the client just for the server to discover the client's UDP ephemeral port. I don't want to send the port number via the initial TCP connection message unless I have to.
Right now I explicitly bind the client UDP socket's port after a getsockname on the TCP socket to discover the OS-assigned ephemeral port. It hasn't failed yet, but it feels fragile.
Edit: To clarify, the current implementation assumes that the operating system will never assign an ephemeral port for a TCP socket that is already used by a UDP socket.