4 ms·
Thanks for the article. Would you mind to explain why for the second case in the table (connected socket with bind() and connect()) we need to use recvfrom() in
by khamphatg 5y ago
Thanks for the article.
Would you mind to explain why for the second case in the table (connected socket with bind() and connect()) we need to use recvfrom() instead of recv()?
- majke 5y agoIt's mentioned in the prose. After bind() before connect() there is a race condition, you can receive packets going to unconnected bind() socket, right? bind(0.0.0.0, 1234) ## packet to port 1234 arrives NOW connect(1.1.1.1, 53) If you recv() you will not be able to figure out if the received packet came from 1.1.1.1 or someone else. Therefore in case of bind+connect you must use recvfrom and validate source of the packet, at least for early packets on the socket.
- khamphatg 5y agoAh so it means "filter the source IP/port when receiving early packets on the connected socket" is done by recvfrom()? I was misunderstood that it is done by some fancy iptable/epbf rule :) Thanks for clarification.