The question is the title. But I'd like to describe my problem so that someone can suggest an alternative solution. I know that when the client sends a message on a socket to 12.34.56.78:40, the router on the client's side sets a rule for some time that any data received from the 12.34.56.78:40 is allowed and will be sent to the client machine on the network. so the problem I have is that the client is sending to the server on some port but the server needs to reply using a different socket (thus a different port). but ofcourse the server's ip didnt change. so that was my first idea of solving the problem spoof the outgoing port
Asked
Active
Viewed 414 times
1
-
Learn about *raw sockets*. http://en.wikipedia.org/wiki/Raw_socket – hek2mgl May 26 '15 at 07:36
-
*Why* does the server 'need to reply using a different socket'? A UDP server only needs one socket. – user207421 May 26 '15 at 09:57
-
@EJP well, I have a lot of classes that are sending/receiving. I thought it would be a bad design to keep passing on the same socket all over the functions. – bubakazouba May 26 '15 at 19:48
-
Well you were mistaken about that. All you accomplished was to create this extra, imaginary, problem. And waste resources. – user207421 May 27 '15 at 23:26
1 Answers
1
Multiple sockets can bind to the same port, and thus send packets with the same source port number, if the each socket sets the SO_REUSEPORT socket option. See the SO_REUSEPORT socket option and the difference between SO_REUSEADDR and SO_REUSEPORT.

Community
- 1
- 1

Hugh White
- 468
- 4
- 7