diff options
author | Jaap Keuter <jaap.keuter@xs4all.nl> | 2016-05-31 22:51:06 +0200 |
---|---|---|
committer | Anders Broman <a.broman58@gmail.com> | 2016-06-02 19:27:08 +0000 |
commit | f9f8e21a4b88d2c6efe0181bced998095bc3b440 (patch) | |
tree | bf5a713f8b5f5235c8de63117a857e810e96f1eb /docbook/wsdg_src | |
parent | d53229dbc169143f301625ff44e1ca14ba3ab286 (diff) | |
download | wireshark-f9f8e21a4b88d2c6efe0181bced998095bc3b440.tar.gz |
Remove 'if (tree)' checks from code samples.
Showing 'if (tree)' constructions in code samples and then having to
explain these are no longer nessasery, or even wrong in many cases,
indicates that these shouldn't be in the code samples in the first
place.
Change-Id: I1a0ccc84ad24ff998548fa913bc00c0336bf1123
Reviewed-on: https://code.wireshark.org/review/15659
Reviewed-by: Anders Broman <a.broman58@gmail.com>
Diffstat (limited to 'docbook/wsdg_src')
-rw-r--r-- | docbook/wsdg_src/WSDG_chapter_dissection.asciidoc | 68 |
1 files changed, 22 insertions, 46 deletions
diff --git a/docbook/wsdg_src/WSDG_chapter_dissection.asciidoc b/docbook/wsdg_src/WSDG_chapter_dissection.asciidoc index ccfcb45aa7..9c4c6e61ca 100644 --- a/docbook/wsdg_src/WSDG_chapter_dissection.asciidoc +++ b/docbook/wsdg_src/WSDG_chapter_dissection.asciidoc @@ -201,13 +201,7 @@ The simplest thing to do to start with is to just label the payload. This will allow us to set up some of the parts we will need. The first thing we will do is to build a subtree to decode our results into. -This helps to keep things looking nice in the detailed display. Now the -dissector is called in two different cases. In one case it is called to get a -summary of the packet, in the other case it is called to look into details of -the packet. These two cases can be distinguished by the tree pointer. If the -tree pointer is NULL, then we are being asked for a summary. If it is non NULL, -we can pick apart the protocol for display. So with that in mind, let's enhance -our dissector. +This helps to keep things looking nice in the detailed display. .Plugin Packet Dissection. ==== @@ -220,10 +214,7 @@ dissect_foo(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree) /* Clear out stuff in the info column */ col_clear(pinfo->cinfo,COL_INFO); - if (tree) { /* we are being asked for details */ - proto_item *ti = NULL; - ti = proto_tree_add_item(tree, proto_foo, tvb, 0, -1, ENC_NA); - } + proto_item *ti = proto_tree_add_item(tree, proto_foo, tvb, 0, -1, ENC_NA); } ---- ==== @@ -299,14 +290,9 @@ Now we can enhance the protocol display with some detail. .Dissector starting to dissect the packets. ==== ---- - if (tree) { /* we are being asked for details */ - proto_item *ti = NULL; - proto_tree *foo_tree = NULL; - - ti = proto_tree_add_item(tree, proto_foo, tvb, 0, -1, ENC_NA); - foo_tree = proto_item_add_subtree(ti, ett_foo); - proto_tree_add_item(foo_tree, hf_foo_pdu_type, tvb, 0, 1, ENC_BIG_ENDIAN); - } + proto_item *ti = proto_tree_add_item(tree, proto_foo, tvb, 0, -1, ENC_NA); + proto_tree *foo_tree = proto_item_add_subtree(ti, ett_foo); + proto_tree_add_item(foo_tree, hf_foo_pdu_type, tvb, 0, 1, ENC_BIG_ENDIAN); ---- ==== @@ -367,22 +353,16 @@ dissect_foo(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree) gint offset = 0; ... - - if (tree) { /* we are being asked for details */ - proto_item *ti = NULL; - proto_tree *foo_tree = NULL; - - ti = proto_tree_add_item(tree, proto_foo, tvb, 0, -1, ENC_NA); - foo_tree = proto_item_add_subtree(ti, ett_foo); - proto_tree_add_item(foo_tree, hf_foo_pdu_type, tvb, offset, 1, ENC_BIG_ENDIAN); - offset += 1; - proto_tree_add_item(foo_tree, hf_foo_flags, tvb, offset, 1, ENC_BIG_ENDIAN); - offset += 1; - proto_tree_add_item(foo_tree, hf_foo_sequenceno, tvb, offset, 2, ENC_BIG_ENDIAN); - offset += 2; - proto_tree_add_item(foo_tree, hf_foo_initialip, tvb, offset, 4, ENC_BIG_ENDIAN); - offset += 4; - } + proto_item *ti = proto_tree_add_item(tree, proto_foo, tvb, 0, -1, ENC_NA); + proto_tree *foo_tree = proto_item_add_subtree(ti, ett_foo); + proto_tree_add_item(foo_tree, hf_foo_pdu_type, tvb, offset, 1, ENC_BIG_ENDIAN); + offset += 1; + proto_tree_add_item(foo_tree, hf_foo_flags, tvb, offset, 1, ENC_BIG_ENDIAN); + offset += 1; + proto_tree_add_item(foo_tree, hf_foo_sequenceno, tvb, offset, 2, ENC_BIG_ENDIAN); + offset += 2; + proto_tree_add_item(foo_tree, hf_foo_initialip, tvb, offset, 4, ENC_BIG_ENDIAN); + offset += 4; ... } @@ -546,18 +526,14 @@ dissect_foo(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree) col_add_fstr(pinfo->cinfo, COL_INFO, "Type %s", val_to_str(packet_type, packettypenames, "Unknown (0x%02x)")); - if (tree) { /* we are being asked for details */ - proto_item *ti = NULL; - proto_tree *foo_tree = NULL; - gint offset = 0; + gint offset = 0; - ti = proto_tree_add_item(tree, proto_foo, tvb, 0, -1, ENC_NA); - proto_item_append_text(ti, ", Type %s", - val_to_str(packet_type, packettypenames, "Unknown (0x%02x)")); - foo_tree = proto_item_add_subtree(ti, ett_foo); - proto_tree_add_item(foo_tree, hf_foo_pdu_type, tvb, offset, 1, ENC_BIG_ENDIAN); - offset += 1; - } + proto_item *ti = proto_tree_add_item(tree, proto_foo, tvb, 0, -1, ENC_NA); + proto_item_append_text(ti, ", Type %s", + val_to_str(packet_type, packettypenames, "Unknown (0x%02x)")); + proto_tree *foo_tree = proto_item_add_subtree(ti, ett_foo); + proto_tree_add_item(foo_tree, hf_foo_pdu_type, tvb, offset, 1, ENC_BIG_ENDIAN); + offset += 1; } ---- ==== |