I have created four sockets with different port configurations. With the select function I read from one of the four file descriptors. But how can I find out on which port I received the UDP packet, I do only have the file descriptor, right? Depending on the port I need to process received packets differently. The recv_from function fills a struct sockaddr from which I can read out the source port of the packet, but not the destination port.
Thanks in advance for your help.
With
selectyou add all four sockets to the set you want to check, and whenselectreturns the set will contain the active sockets.You now have two ways of figuring out which specific socket/port you get back from
select:getsockname) and compare to the ports.I recommend the first alternative.