|
From: Brian W. <bwe...@xb...> - 2011-09-01 22:37:30
|
On Sep 1, 2011, at 2:57 PM, Periya.Data wrote:
> Hi,
> I have a bytebuffer of size 2048 bytes. Its initial bytes have some custom data (upto 70th byte). From 71st byte, the DNS messages are there. I think I know the length of the DNS message (I am not yet sure about this).
>
> How do I get one message at a time from the bytebuffer?
>
> I am doing something like this:
>
> byte[] dns_msg_buf= new byte[1024];
> bb.get(dns_msg_buf, 71, caplen); // bb is a byte buffer with custom data and dns msgs. Caplen is the len.
> Message dns_msg = new Message(dns_msg_buf);
> System.out.println("Message size: " + dns_msg.numBytes());
>
> dns_msg.numBytes => seems to be returning the size of the header only = which is 12 bytes. Is there a way to find the total length of the message = hdr + 4 message sections?
Message.numBytes() does return the size of the entire message; the provided "dig" helper program calls Message.toString(), which calls Message.numBytes(), and returns the full message size correctly.
The code looks correct, so I suspect that there's a problem with the data you're parsing. The Message(byte []) constructor doesn't verify that the entire byte array was consumed by the parsing, so it probably wasn't.
Brian
|