This is our old Q&A Site. Please post any new questions and answers at ask.wireshark.org.

Is there an available function that finds bytes till null character? ('0')

Thanks, Dhanashree

asked 18 Apr '11, 12:44

dsprabhu4's gravatar image

dsprabhu4
117710
accept rate: 0%


Each of tvb_get_stringz, tvb_get_ephemeral_stringz, and tvb_get_seasonal_stringz extract a NULL terminated string from the TVB and return it as a guint8 *.

I would recommend that you check for the presence of the terminating NULL before calling any of these functions, however, as it is not guaranteed to be in the captured packet (erroneous transmission, fuzz-test, fragmentation, etc). You could use tvb_find_guint8 to do this; a returned length of -1 means that the NULL was not found before the end of the packet or maxlength (an argument to the call).

permanent link

answered 18 Apr '11, 13:00

multipleinterfaces's gravatar image

multipleinte...
1.3k152340
accept rate: 12%

I am using following function and then checking if it is -1 or not. / check for null character / null_offset = tvb_find_guint8(tvb, offset + 1, -1,0);

Thank You. It really helped me.

(18 Apr '11, 14:17) dsprabhu4
2

Note that if the terminating NUL is not found, tvb_get_stringz(), tvb_get_ephemeral_stringz(), and tvb_get_seasonal_stringz() will throw an exception, so that the packet will be reported as either cut short by the snapshot length (if it hits the captured length before finding a NUL or hitting the end of the packet) or malformed (if it hits the end of the packet before finding a NUL and the captured length and packet length are the same). In most cases, this is what you'd want - no need for the tvb_find_guint8().

(18 Apr '11, 18:29) Guy Harris ♦♦

Thanks to all. I was able to do what i wanted to do.

(19 Apr '11, 06:13) dsprabhu4

(please use the "accept" button (the checkmark next to an answer) to accept an answer, this will make sure the question is removed from the "Unanswered Questions" list)

(19 Apr '11, 08:01) SYN-bit ♦♦
Your answer
toggle preview

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Markdown Basics

  • *italic* or _italic_
  • **bold** or __bold__
  • link:[text](http://url.com/ "title")
  • image?![alt text](/path/img.jpg "title")
  • numbered list: 1. Foo 2. Bar
  • to add a line break simply add two spaces to where you would like the new line to be.
  • basic HTML tags are also supported

Question tags:

×11
×6
×3

question asked: 18 Apr '11, 12:44

question was seen: 2,512 times

last updated: 19 Apr '11, 08:01

p​o​w​e​r​e​d by O​S​Q​A