epan/dissectors/, just like all the other packet-*.c files already in there.
Also, please add your dissector file to the corresponding makefiles,
-described in section "1.9 Editing Makefile.common and CMakeLists.txt
+described in section "1.8 Editing Makefile.common and CMakeLists.txt
to add your dissector" below.
Dissectors that use the dissector registration API to register with a lower
To register the distinct dissector functions, consider the following
example, stolen from packet-dns.c:
+ #include "packet-tcp.h"
+
dissector_handle_t dns_udp_handle;
dissector_handle_t dns_tcp_handle;
dissector_handle_t mdns_udp_handle;
- dns_udp_handle = create_dissector_handle(dissect_dns_udp,
+ dns_udp_handle = new_create_dissector_handle(dissect_dns_udp,
proto_dns);
- dns_tcp_handle = create_dissector_handle(dissect_dns_tcp,
+ dns_tcp_handle = new_create_dissector_handle(dissect_dns_tcp,
proto_dns);
- mdns_udp_handle = create_dissector_handle(dissect_mdns_udp,
+ mdns_udp_handle = new_create_dissector_handle(dissect_mdns_udp,
proto_dns);
dissector_add_uint("udp.port", UDP_PORT_DNS, dns_udp_handle);
dissect_dns_common, while dissect_dns_tcp calls tcp_dissect_pdus with a
reference to a callback which will be called with reassembled data:
- static void
- dissect_dns_tcp(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
+ static int
+ dissect_dns_tcp(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree,
+ void *data _U_)
{
tcp_dissect_pdus(tvb, pinfo, tree, dns_desegment, 2,
- get_dns_pdu_len, dissect_dns_tcp_pdu);
+ get_dns_pdu_len, dissect_dns_tcp_pdu, data);
+ return tvb_length(tvb);
}
(The dissect_dns_tcp_pdu function acts similarly to dissect_dns_udp.)
might not be available, so don't refer to any data past that) - the
total length of the PDU, in bytes;
- a routine to dissect the pdu that's passed a tvbuff pointer,
- packet_info pointer, and proto_tree pointer, with the tvbuff
- containing a possibly-reassembled PDU. (The "reported_length"
- of the tvbuff will be the length of the PDU).
+ a new_dissector_t routine to dissect the pdu that's passed a tvbuff
+ pointer, packet_info pointer, proto_tree pointer and a void pointer for
+ user data, with the tvbuff containing a possibly-reassembled PDU. (The
+ "reported_length" of the tvbuff will be the length of the PDU).
+
+ a void pointer to user data that is passed to the dissector routine
+ referenced in the previous parameter.
2.7.2 Modifying the pinfo struct.
#define FRAME_HEADER_LEN 8
-/* The main dissecting routine */
-static void dissect_foo(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
-{
- tcp_dissect_pdus(tvb, pinfo, tree, TRUE, FRAME_HEADER_LEN,
- get_foo_message_len, dissect_foo_message);
-}
-
/* This method dissects fully reassembled messages */
-static void dissect_foo_message(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
+static int dissect_foo_message(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void* data _U_)
{
/* TODO: implement your dissecting code */
+ return tvb_length(tvb);
}
/* determine PDU length of protocol foo */
return (guint)tvb_get_ntohl(tvb, offset+4); /* e.g. length is at offset 4 */
}
+/* The main dissecting routine */
+static int dissect_foo(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void* data)
+{
+ tcp_dissect_pdus(tvb, pinfo, tree, TRUE, FRAME_HEADER_LEN,
+ get_foo_message_len, dissect_foo_message, data);
+ return tvb_length(tvb);
+}
+
...]]>
</programlisting>
</example>
This function gets called whenever a message has been reassembled.
</para>
<para>
- The parameters <parameter>tvb</parameter>, <parameter>pinfo</parameter> and <parameter>tree</parameter>
- are just handed over to <function>tcp_dissect_pdus()</function>.
- The 4th parameter is a flag to indicate if the data should be reassembled or not. This could be set
- according to a dissector preference as well.
- Parameter 5 indicates how much data has at least to be available to be able to determine the length
- of the foo message.
- Parameter 6 is a function pointer to a method that returns this length. It gets called when at least
- the number of bytes given in the previous parameter is available.
- Parameter 7 is a function pointer to your real message dissector.
- </para>
+ The parameters <parameter>tvb</parameter>, <parameter>pinfo</parameter>, <parameter>tree</parameter>
+ and <parameter>data</parameter> are just handed over to <function>tcp_dissect_pdus()</function>.
+ The 4th parameter is a flag to indicate if the data should be reassembled or not. This could be set
+ according to a dissector preference as well.
+ Parameter 5 indicates how much data has at least to be available to be able to determine the length
+ of the foo message.
+ Parameter 6 is a function pointer to a method that returns this length. It gets called when at least
+ the number of bytes given in the previous parameter is available.
+ Parameter 7 is a function pointer to your real message dissector.
+ Parameter 8 is a the data passed in from parent dissector.
+ </para>
</section>
</section>
<section id="ChDissectTap">