netdns2 icon indicating copy to clipboard operation
netdns2 copied to clipboard

Prevent TCP segmentation

Open daeppen opened this issue 1 year ago • 0 comments

Issue

When using TCP (\Net_DNS2_Resolver::$use_tcp = true), then certain DNS systems may refuse to answer the DNS query due to (I assume) unintentional TCP segmentation.

Cause

When writing data to the TCP socket (using PHP's fwrite()), PHP immediately sends the data using the TCP flags PSH and ACK. As a result, the TCP receiver might try to process the first TCP segment (which does only contain the length of the DNS-query, but not the actual query itself). The latter will obviously fail and the receiver will instantly close the connection using a TCP RST packet, resulting in refusing to accept the actual DNS-query which is sent in the second TCP segment.

Solution

fwrite() must only be called once, containing both the length of the DNS query along with the actual query.

daeppen avatar Apr 02 '24 18:04 daeppen