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

Null Terminated String

0

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%


One Answer:

1

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).

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 ♦♦