[Dnsmasq-discuss] dnsmasq query via tcp return always in 2 packets ?

Simon Kelley simon at thekelleys.org.uk
Mon Apr 22 09:39:49 BST 2013

On 20/04/13 12:59, Jim Bos wrote:
> I got errors trying to use tcl library to query via tcp to dnsmasq
> ( http://tcllib.sourceforge.net/doc/tcllib_dns.html )
> looking with wireshark what was happening I noticed that dnsmasq when
> queried via tcp always seems to reply with 2 tcp packets. The DNS
> payload for tcp starts with a length field consisting of 2 bytes.
> dnsmasq always appears to send the first byte (typically a zero for
> replies with less then 255 bytes) followed by 2nd length field byte and
> the rest of the message in subsequent package.
> That's obviously not an error for a tcp stream (and I haven't verified
> that's the reason for the errors in the library) but does seem
> sub-optimal and not something other nameservers do.
> (verified by doing   dig +tcp google.com @ )
> I can supply a wireshark dump but this is very easy to reproduce,
> is there a reason dnsmasq is doing this ?

The reason its doing it, I guess, is that the code does, roughly,

unsigned char c1 = size >> 8, c2 = size;

write (..., &c1, 1);
write (..., &c2, 1);
write (..., packet_buff, size);

The reason that code is written like that is ease of getting the 
byte-order right in the transmitted length.

As you say, the TCP stream is correct, if sub-optimal, and I suppose 
that possibility didn't occur to me when I wrote the code. It's easy to 
change and will be done henceforth.



> Thanks,
> Jim
> _______________________________________________
> Dnsmasq-discuss mailing list
> Dnsmasq-discuss at lists.thekelleys.org.uk
> http://lists.thekelleys.org.uk/mailman/listinfo/dnsmasq-discuss

More information about the Dnsmasq-discuss mailing list