This is a static, read-only archive of Wireshark Q&A. Older questions and answers from October 2017 and earlier can be found at osqa-ask.wireshark.org.
0

How do I get and display packet data information at a specific byte from the first byte?

asked Oct 31 '17

updated Oct 31 '17

Hello, I am a beginner in Wireshark and dissector building, right now I'm just trying to figure out how to fetch and display packet data. I use the following lines in my dissect function:

guint val;
val = tvb_get_guint8(tvb, 1);
proto_tree_add_uint(masp_tree, hf_masp_data, tvb, 1, 1, val);

Here is an image of the results:

Expected result: 0x00

Actual result: 0x60

Why does fetching the data start from the 43rd byte instead of the very 1st one? How do I resolve this issue?

Thanks

2 Answers

0

answered Nov 02 '17

updated Nov 03 '17

If your traffic is always over Ethernet you can use the pinfo->dl_dst structure and copy it into a local buffer with address_to_bytes(), e.g.

char myBuff[2];
address_to_bytes(pinfo->dl_dst, myBuff, 2);
char myByte = myBuff[1];
0

answered Oct 31 '17

The offset is due to the headers provided by the other parts of the frame, i.e. the Ethernet, IP and UDP headers. Note that by passing the 4th parameter to proto_tree_add_uint() as 1 you're asking for the byte at offset 1 in your tvb, i.e. the second byte in the UDP payload.

Presumably you have registered your dissector with the UDP dissector, hence the preceding items. The byte view shows the whole frame not just your application data.

It's not clear to me why you expect the result to be 0x00, which byte in the byte view are you expecting to read?

Comments

Thanks for the answer, I was expecting the second byte (the one beside 01, in the top left corner). I'm aware that passing the 4th parameter as 1 in proto_tree_add_uint() would get me the byte at offset 1 in the tvb, it's just that I was expecting the tvb to start from 01 (the byte at the top left corner of byte view).

The offset is due to the headers provided by the other parts of the frame, i.e. the Ethernet, IP and UDP headers.

Any idea on how I can set this offset to 0?

User 96912 ( Oct 31 '17 )

The second byte you are referring to is part of the Ethernet payload, and is not part of the tvb corresponding to the UDP payload (the one that is being given to your dissector). The UDP payload starts at offset 0x2a, so the second byte is 0x60 as seen in your capture.

Why do you want to access the top tvb corresponding to the Ethernet frame?

User 54095 ( Oct 31 '17 )

It's for a project. Is there a way to access the top tvb corresponding to the Ethernet frame?

User 96912 ( Nov 01 '17 )

Do you need only the byte or will the Ethernet address do? If the latter, then the packet_info structure passed to your dissector has a member named dl_dst that holds the data link layer destination address.

User 98587 ( Nov 02 '17 )

I need only the byte

User 96912 ( Nov 02 '17 )
cc-by-sa Content on this site is licensed under a Creative Commons Attribution Share Alike 3.0 license.