|
From: Periya.Data <per...@gm...> - 2011-09-01 22:23:23
|
Also, I get a null pointer exception error when I try to getName.
// DNS Questions
Name qname;
int qtype;
int qclass;
Record question = dns_msg.getQuestion();
qname = question.getName(); ===> error at this line.
I am not what that means. A valid record is not found? Is there a nice way
to check if a valid record has been returned? Maybe I am screwing up with
the starting of a valid DNS message from the bytebuffer.
Suggestions are welcome.
Thanks,
PD.
On Thu, Sep 1, 2011 at 3:05 PM, Brian Wellington <bwe...@xb...> wrote:
>
> 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
|