I've to access 4 bytes of data from tvb (tvbuff_t *) passed in dissect-protocolname() function. I used 2 functions:
Both shows the different result in second display pane of wireshark. I'm not changing the offset too. Thanks. asked 09 Jun '15, 01:42 Sammee Sharma edited 09 Jun '15, 01:49 |
One Answer:
Note that, in that statement,
However, in that statement,
And it's the offset in bytes from the beginning of the tvbuff in that call as well. So, if you want to use
However:
Yes -
(No, the name doesn't have "be", for "big-endian", or "32" in it, but, well, BSD, UN*X history, Unless you're dealing with values not aligned on byte boundaries, i.e. bit-packed values, you don't need to use the answered 09 Jun '15, 02:17 Guy Harris ♦♦ edited 09 Jun '15, 09:58 |
Thanks, @GuyHarris , it worked. The offset in first function is in bits. so it should be converted to bytes in order to access the same value. just one correction i want to make in your answer is that the offset should be multiplied by 8 not 32. Thanks for the quick answer.
And one more thing, i didn't get the function
data = tvb_get_ntohl(tvb, offset);
Can you explain a bit about this function like how it will be used to access the 4 bytes.
Thanks.
The ntohl is an abbreviation for "network to host long", i.e. convert a long from the network representation (which is always big-endian) to host representation. There are similar functions for converting from host to network representations and for many different data types. See
epan/tvbuff.h
for the full list....which means that
tvb_get_ntohl()
is all you need to fetch a 32-bit big-endian quantity that's aligned on a byte boundary; there's no advantage to usingtvb_get_bits32()
unless you're dealing with data that's not aligned on byte boundaries.Example fixed.