1

I found I cannot understand my test. Setup two Linux PC, say moon and sun. The moon has two network interface, eth0=192.168.0.20, eth1=192.168.1.20. The sun has single network interface, eth0=192.168.0.10. Setup a route in sun allowing it can reach to 192.168.1.20 in moon. Ping test passed.

Now run 'nc -l -p 1234 -u' on moon, and then in sun, run 'nc 192.168.1.20 1234 -u'. It is always that the first message sent from sun can appear in moon. But the next message sent from sun in the same nc session will failed. The tcpdump show that the second message arrived moon, but the moon generated an 'ICMP unreachable' error back to sun which cause sun closed the socket. In same test with socat, I found the same result.

This is quite strange to me. I checked from tcpdump that the two messages sent from sun has the same source/dest ip and source/dst port numbers. Why the second message from sun cannot be recognized by moon's nc or socat?

Can someone give me any hint? thanks.

-woody

  • With my own write udp sender and receiver I found there is no problem with the same network setup. So I think the problem found with nc and socat may caused by they used 'connect(2)' and I did not use it. But even this is the case, I still cannot understand why the problem can happen, because as I said, the two messages sent from the client has the same source port. – Woody Wu Jan 27 '19 at 9:18
  • Does it change if you start the server with nc -l -s 192.168.1.20 -p 1234 -u on moon? – Thomas Jan 27 '19 at 13:46
  • @Thomas, many thanks. You just solved the puzzle to me! Does it mean as a general rule, an UDP server program should not use connect(2)? Because even the '-s 192.168.1.20' solve the the problem for this specific client accessing manner, I will fail if another client do 'nc -u 192.168.0.20 xxxx'. – Woody Wu Jan 27 '19 at 15:17

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.