Page 1 of 1

[solved] no DNS response from real router

Posted: Sat Jan 28, 2023 6:30 am
by Klakap
I am currently testing my code on real machine. My router properly responds to DHCP and ARP protocol, however, when I send DNS query, there is no response. So far I checked:
- my driver: there surely is not problem, it is working perfectly
- ARP: router properly responds to ARP request for DNS server IP
- DNS query: I doubt that error is here, because my code works under QEMU and Virtualbox and there is no error shown in Wireshark.
What is quite strange, when I start Virtualbox with network option bridge, router responds to DNS query properly. However when I start my OS on real computer, there is no DNS reply. So I am wondering that maybe there is some overlooked aspect in initalizing communication with real router. Here is how my code works now on real computer:
- > I send DHCP Discover asking for IP 192.168.1.100, router IP and Domain Name Server IP
< - Router send DHCP Offer with IP 192.168.1.100, router IP 192.168.1.1 and Domain Name Server IP 192.168.1.1
- > I send DHCP Request for 192.168.1.100
< - Router send ARP Request for IP 192.168.1.100
- > I send ARP Reply to router
< - Router send DHCP Acknowledge
- > I send DNS query
< - In QEMU, Virtualbox and even Virtualbox bridge Router responds with DNS Reply, however on real hardware it do not
Am I missing something? Any help would be appreciated.

P.S. I am currently rewriting BleskOS to C, so code on GitHub is not my actual code

Re: no DNS response from real router

Posted: Sat Jan 28, 2023 7:04 am
by nullplan
I would guess that there is something wrong with your DNS query that QEMU and VBox are not checking but the router is. Dump the traffic into Wireshark, it is stricter about checking things.

Re: no DNS response from real router

Posted: Sat Jan 28, 2023 7:20 am
by Klakap
Wireshark do not see anything wrong with my DNS query. Screenshot here is from Virtualbox bridge communication, therefore my IP is 192.168.1.101.

Re: no DNS response from real router

Posted: Sat Jan 28, 2023 12:43 pm
by sounds
I can't imagine why, but on the real computer the DNS request might be different. Can you capture the packets sent? Easy options are: (1) run a packet capture on your router if you have a router that can do that (2) use an ethernet hub and a separate box to capture with, as long as the ethernet hub is either a dumb hub that forwards all packets to all ports, or is a switch that has a management UI that lets you set it up to forward all packets from a port to a capture port.

Re: no DNS response from real router

Posted: Mon Jan 30, 2023 8:52 am
by Klakap
sounds wrote:I can't imagine why, but on the real computer the DNS request might be different. Can you capture the packets sent?
Thank you for suggestion. I've solved this problem. It was really sneaky mistake. I used malloc() instead of calloc(). In emulators it do not matter, because they have zeroes in whole free memory, but it is not case on real computer. I was not rewriting all fields, so I was sending malformed packet. When I zeroed packet with calloc(), everything works perfectly.