Mailing List Archive

Printing an array of bytes to the tree?
Is there an intelligent way to print an array of bytes to the tree?
I'd like to have something like:

"array: 0x0102030405060708090A"

Thanks in advance,
Y.
Re: Printing an array of bytes to the tree? [ In reply to ]
On Mon, Aug 12, 2002 at 05:46:12PM +0200, Yaniv Kaul wrote:
> Is there an intelligent way to print an array of bytes to the tree?
> I'd like to have something like:
>
> "array: 0x0102030405060708090A"

If the array of bytes is a named field, just make it a field of type
FT_BYTES.

If it's not a named field, and you're putting it into the protocol tree
with "proto_tree_add_text()", use "tvb_bytes_to_str()".

Doing one of those won't put a leading "0x" in there, and will just put
in a "..." after 16 bytes rather than showing ever single byte (16 is
1/2 the value of the #define MAX_BYTE_STR_LEN in epan/strutil.c -
MAX_BYTE_STR_LEN is the number of characters in the display, and each
byte is shown as 2 hex digits - so it could be increased), but it's the
type of thing you're asking for .
RE: Printing an array of bytes to the tree? [ In reply to ]
Thanks.

tvb_bytes_to_str() is not documented in doc/README.developer.

> -----Original Message-----
> From: Guy Harris [mailto:guy@netapp.com]
> Sent: Mon, August 12, 2002 7:39 PM
> To: Yaniv Kaul
> Cc: Ethereal-Dev@ethereal.com
> Subject: Re: [Ethereal-dev] Printing an array of bytes to the tree?
>
>
> On Mon, Aug 12, 2002 at 05:46:12PM +0200, Yaniv Kaul wrote:
> > Is there an intelligent way to print an array of bytes to the tree?
> > I'd like to have something like:
> >
> > "array: 0x0102030405060708090A"
>
> If the array of bytes is a named field, just make it a field of type
> FT_BYTES.
>
> If it's not a named field, and you're putting it into the protocol tree
> with "proto_tree_add_text()", use "tvb_bytes_to_str()".
>
> Doing one of those won't put a leading "0x" in there, and will just put
> in a "..." after 16 bytes rather than showing ever single byte (16 is
> 1/2 the value of the #define MAX_BYTE_STR_LEN in epan/strutil.c -
> MAX_BYTE_STR_LEN is the number of characters in the display, and each
> byte is shown as 2 hex digits - so it could be increased), but it's the
> type of thing you're asking for .
>
Re: Printing an array of bytes to the tree? [ In reply to ]
I've tried using the following named field:



...

&hf_my_hex_string,

{

"A Hex String",

"myproto.hexstr",

FT_BYTES,

BASE_HEX,

NULL,

0x0,

"",

HFILL

}

...



But printing to the subtree never showed anything when the dissector makes
this call:



if (tree)

{

proto_tree_add_item(myproto_tree, hf_my_hex_string, tvb, offset, 24, FALSE);

}



Is there anything that I'm missing or is it just not possible to print that
many hex characters?



Thanks,
Saad
Re: Printing an array of bytes to the tree? [ In reply to ]
Hi,

Sure it can. Did you register the field?
What code is used to create the subtree?

Thanx,
Jaap

On Fri, 19 May 2006, Saad Nader wrote:

> I've tried using the following named field:
>
>
>
> ...
>
> &hf_my_hex_string,
>
> {
>
> "A Hex String",
>
> "myproto.hexstr",
>
> FT_BYTES,
>
> BASE_HEX,
>
> NULL,
>
> 0x0,
>
> "",
>
> HFILL
>
> }
>
> ...
>
>
>
> But printing to the subtree never showed anything when the dissector makes
> this call:
>
>
>
> if (tree)
>
> {
>
> proto_tree_add_item(myproto_tree, hf_my_hex_string, tvb, offset, 24, FALSE);
>
> }
>
>
>
> Is there anything that I'm missing or is it just not possible to print that
> many hex characters?
>
>
>
> Thanks,
> Saad
>

_______________________________________________
Ethereal-dev mailing list
Ethereal-dev@ethereal.com
http://www.ethereal.com/mailman/listinfo/ethereal-dev