DNS Protocol
I am trying to make my own SMTP server using VB.NET and I have got it to receive emails without a problem, its sending emails that is proving difficult because obviously I need to do MX record and A record lookups using DNS. I have looked at the DNS RFC (http://www.faqs.org/rfcs/rfc1035.html) and under section 4.1.1 it shows the UDP header that must be sent at the start of a DNS query.I tried to copy and paste just that table here but the formatting gets all messed up so just click that RFC link above and do a search (e.g Ctrl + F) on the page for 4.1.1 and it will be the second result you find (as the first will just be in the contents)Those numbers listed across the top of the table represent the bits (so each of those sections is 2 bytes long) but the problem I am having is with figuring out in what order they actually go. I mean normally bits are shown with the most significant bit first but as they have labelled that first bit "0" then I assumed they meant that bit was literally bit 0 but now I am not so sure... The reason I am not sure about this is because I followed that table and created my header as follows:-- I set the 2 byte long ID field to any 2 numbers I wanted-- I wanted to set just the RD bit (bit 7 in that table) on the second row so I set the first byte in that 2 byte pair to 128 as I believed this would just set the very last bit in that byte, which would be bit 7.-- All other fields were just set to 0 apart from the QDCOUNT field being set to 1 (as I'm just asking one question to the DNS server) So I sent this header (with an actual DNS query) to a DNS server and it simply did not respond at all. I changed it so that instead of setting the first byte in that second field to 128 I set it to 1, then when I sent the DNS query I got a response from the server. So I'm wondering if when I set it to 128 what I was actually doing was setting the QR bit (bit 0 according to that table) as that would explain why the server didnt respond - because setting that bit indicates that this is an answer not a question. It seems to make sense that way but it just seems so odd that they would label what is generally considered to be bit 7 as bit 0 and vice versa (so basically the whole of each byte is reversed) I just need to try and confirm this before I go trying to get any further with interpreting the server's response etc so if anyone could shed any light on this that would be great :) Windows XP MCP
September 23rd, 2009 9:55pm

For anyone that is interested, turns out I was correct and the bits are the opposite way around to how I thought they were from looking at that table in the RFC.
Free Windows Admin Tool Kit Click here and download it now
October 6th, 2009 9:11pm

This topic is archived. No further replies will be accepted.

Other recent topics Other recent topics