I am trying to send a DNS query message to let's say www.google.com to get A record of DNS. I read this article to find out the structure of DNS query.
I created the buffer message as:
private static final byte[] RequestPacket = {
// Transaction ID: 0x0000
0x00, 0x00,
// Flags: 0x0000 (Standard query)
0x00, 0x00,
// Questions: 1
0x00, 0x01,
// Answer RRs: 0
0x00, 0x00,
// Authority RRs: 0
0x00, 0x00,
// Additional RRs: 0
0x00, 0x00,
// Queries
// Name: www.google.com
0x03, 0x77, 0x77, 0x77, 0x06, 0x67, 0x6F, 0x6F, 0x67, 0x6C, 0x65, 0x03, 0x63,
0x6F, 0x6D, 0x00,
// Type: A Record
0x00, 0x01
};
That's how I am creating send, receive packets and my socket as well:
DatagramPacket sendPacket = new DatagramPacket(RequestPacket , RequestPacket .length, InetAddress.getByName("www.google.com"), 9876);
DatagramPacket recievePacket = new DatagramPacket(mBuffer, mBuffer.length);
DatagramSocket socket = new DatagramSocket();
I am not able to receive any response back(SocketTimeoutException
) when I call socket.receive(recievePacket);
after sending the packet
I think I am messing up with the port of my send packet, but after searching google for a lot of time that's the port I found to query for DNS.
Can somebody tell me what exactly am I doing wrong?
Thanks