Ethereal-dev: [Ethereal-dev] Patches for JXTA Protocol Dissector
Note: This archive is from the project's previous web site, ethereal.com. This list is no longer active.
From: Mike Duigou <mike@xxxxxxxxxx>
Date: Mon, 03 Jan 2005 14:15:06 -0800
I've developed a rudimentary dissector for JXTA (www.jxta.org). It still
needs significant refinement, but it already provides a lot of useful
info. It is ready enough though for submission and hopefully review and
improvements by others.
I've generated the diffs versus svn revision 12945 (most current at time of writing).
Two diffs are included: the jxta dissector and a second file with a bunch of changes unrelated to the jxta dissector.
The JXTA dissector is currently a single file and does not depend upon any external JXTA header files.
The second patch file contains minor grammatical changes for README.developer and a patch to tvbuff to generate better doxygen output.
Enjoy! Mike
Index: AUTHORS =================================================================== --- AUTHORS (revision 12945) +++ AUTHORS (working copy) @@ -2267,6 +2267,9 @@ Correctly handle time stamps in some Windows Sniffer files } +Mike Duigou <bondolo [AT] jxta.org> { + Dissector for JXTA protocol +} And assorted fixes and enhancements by the people listed above and by: Index: epan/dissectors/Makefile.common =================================================================== --- epan/dissectors/Makefile.common (revision 12945) +++ epan/dissectors/Makefile.common (working copy) @@ -315,6 +315,7 @@ packet-isup.c \ packet-iua.c \ packet-jabber.c \ + packet-jxta.c \ packet-kadm5.c \ packet-kerberos.c \ packet-kerberos4.c \ Index: epan/dissectors/packet-jxta.c =================================================================== --- epan/dissectors/packet-jxta.c (revision 0) +++ epan/dissectors/packet-jxta.c (revision 0) @@ -0,0 +1,548 @@ +/* packet-JXTA.c + * Routines for JXTA packet dissection + * Copyright 2004, Mike Duigou <bondolo@xxxxxxxx> + * Heavily based on packet-jabber.c, which in turn is heavily based on + * on packet-acap.c, which in turn is heavily based on + * packet-imap.c, Copyright 1999, Richard Sharpe <rsharpe@xxxxxxxxxx> + * + * $Id: packet-jxta.c 11410 2004-07-18 18:06:47Z gram $ + * + * Ethereal - Network traffic analyzer + * By Gerald Combs <gerald@xxxxxxxxxxxx> + * Copyright 1998 Gerald Combs + * + * Copied from packet-pop.c, packet-jabber.c, packet-udp.c + * + * JXTA specification from http://spec.jxta.org + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + */ + +#ifdef HAVE_CONFIG_H +# include "config.h" +#endif + +#include <stdio.h> + +#include <string.h> +#include <glib.h> +#include <epan/packet.h> +#include <epan/strutil.h> +#include <epan/prefs.h> +#include "packet-tcp.h" + +static int proto_jxta = -1; + +static int hf_jxta_udp = -1; +static int hf_jxta_udpsig = -1; +static int hf_jxta_welcome = -1; +static int hf_jxta_framing = -1; +static int hf_jxta_framing_header_name_length = -1; +static int hf_jxta_framing_header_name = -1; +static int hf_jxta_framing_header_value_length = -1; +static int hf_jxta_framing_header_value = -1; +static int hf_jxta_message = -1; +static int hf_jxta_message_sig = -1; +static int hf_jxta_message_version = -1; +static int hf_jxta_message_namespaces_count = -1; +static int hf_jxta_message_namespace_len = -1; +static int hf_jxta_message_namespace_name = -1; +static int hf_jxta_message_element_count = -1; +static int hf_jxta_element = -1; +static int hf_jxta_element_sig = -1; +static int hf_jxta_element_namespaceid = -1; +static int hf_jxta_element_flags = -1; +static int hf_jxta_element_name_len = -1; +static int hf_jxta_element_name = -1; +static int hf_jxta_element_type_len = -1; +static int hf_jxta_element_type = -1; +static int hf_jxta_element_encoding_len = -1; +static int hf_jxta_element_encoding = -1; +static int hf_jxta_element_data_length = -1; +static int hf_jxta_element_content_len = -1; +static int hf_jxta_element_content = -1; +static int hf_jxta_element_signature = -1; + +static gint ett_jxta_welcome = -1; +static gint ett_jxta_udp = -1; +static gint ett_jxta_framing = -1; +static gint ett_jxta_msg = -1; +static gint ett_jxta_elem = -1; + +static dissector_handle_t udpm_jxta_handle; +static dissector_handle_t tcp_jxta_handle; +static dissector_handle_t http_jxta_handle; + +/** our header fields */ +static hf_register_info hf[] = { + { &hf_jxta_udp, + { "JXTA UDP Message", "jxta.udp", FT_NONE, BASE_NONE, NULL, 0x0, + "JXTA UDP Message", HFILL } + }, + { &hf_jxta_udpsig, + { "Signature", "jxta.udpsig", FT_STRING, BASE_NONE, NULL, 0x0, + "JXTA UDP Signature", HFILL } + }, + { &hf_jxta_welcome, + { "Welcome Message", "jxta.welcome", FT_NONE, BASE_NONE, NULL, 0x0, + "JXTA Connection Welcome Message", HFILL } + }, + { &hf_jxta_framing, + { "JXTA Message Framing", "jxta.framing", FT_NONE, BASE_NONE, NULL, 0x0, + "JXTA Message Framing Header", HFILL } + }, + { &hf_jxta_framing_header_name_length, + { "Name Length", "jxta.framing.header.namelen", FT_UINT8, BASE_DEC, NULL, 0x0, + "JXTA Message Framing Header Name Length", HFILL } + }, + { &hf_jxta_framing_header_name, + { "Name", "jxta.framing.header.name", FT_STRING, FT_NONE, NULL, 0x0, + "JXTA Message Framing Header Name", HFILL } + }, + { &hf_jxta_framing_header_value_length, + { "Value Length", "jxta.framing.header.valuelen", FT_UINT16, BASE_DEC, NULL, 0x0, + "JXTA Message Framing Header Value Length", HFILL } + }, + { &hf_jxta_framing_header_value, + { "Value", "jxta.framing.header.value", FT_BYTES, BASE_HEX, NULL, 0x0, + "JXTA Message Framing Header Value", HFILL } + }, + { &hf_jxta_message, + { "JXTA Message", "jxta.message", FT_NONE, BASE_NONE, NULL, 0x0, + "JXTA Message", HFILL } + }, + { &hf_jxta_message_sig, + { "Signature", "jxta.message.signature", FT_STRING, BASE_NONE, NULL, 0x0, + "JXTA Message Signature", HFILL } + }, + { &hf_jxta_message_version, + { "Version", "jxta.message.version", FT_UINT8, BASE_DEC, NULL, 0x0, + "JXTA Message Version", HFILL } + }, + { &hf_jxta_message_namespaces_count, + { "Namespace Count", "jxta.message.namespaces", FT_UINT16, BASE_DEC, NULL, 0x0, + "JXTA Message Namespaces", HFILL } + }, + { &hf_jxta_message_namespace_len, + { "Namespace Name Length", "jxta.message.namespace.len", FT_UINT16, BASE_DEC, NULL, 0x0, + "JXTA Message Namespace Name Length", HFILL } + }, + { &hf_jxta_message_namespace_name, + { "Namespace Name", "jxta.message.namespace.name", FT_STRING, BASE_NONE, NULL, 0x0, + "JXTA Message Namespace Name", HFILL } + }, + { &hf_jxta_message_element_count, + { "Element Count", "jxta.message.elements", FT_UINT16, BASE_DEC, NULL, 0x0, + "JXTA Message Element Count", HFILL } + }, + { &hf_jxta_element, + { "JXTA Message Element", "jxta.message.element", FT_NONE, BASE_NONE, NULL, 0x0, + "JXTA Message Element", HFILL } + }, + { &hf_jxta_element_sig, + { "Signature", "jxta.message.element.signature", FT_STRING, BASE_NONE, NULL, 0x0, + "JXTA Message Element Signature", HFILL } + }, + { &hf_jxta_element_namespaceid, + { "Namespace ID", "jxta.message.element.namespaceid", FT_UINT8, BASE_DEC, NULL, 0x0, + "JXTA Message Element Namespace ID", HFILL } + }, + + /* TODO 20050104 bondolo This should be a bitfield */ + + { &hf_jxta_element_flags, + { "Flags", "jxta.message.element.flags", FT_UINT8, BASE_HEX, NULL, 0x0, + "JXTA Message Element Flags", HFILL } + }, + { &hf_jxta_element_name_len, + { "Element Name Length", "jxta.message.element.name.length", FT_UINT16, BASE_DEC, NULL, 0x0, + "JXTA Message Element Name Length", HFILL } + }, + { &hf_jxta_element_name, + { "Element Name", "jxta.message.element.name", FT_STRING, BASE_NONE, NULL, 0x0, + "JXTA Message Element Name", HFILL } + }, + { &hf_jxta_element_type_len, + { "Element Type Length", "jxta.message.element.type.length", FT_UINT16, BASE_DEC, NULL, 0x0, + "JXTA Message Element Name Length", HFILL } + }, + { &hf_jxta_element_type, + { "Element Type", "jxta.message.element.type", FT_STRING, BASE_NONE, NULL, 0x0, + "JXTA Message Element Name", HFILL } + }, + { &hf_jxta_element_encoding_len, + { "Element Type Length", "jxta.message.element.encoding.length", FT_UINT16, BASE_DEC, NULL, 0x0, + "JXTA Message Element Encoding Length", HFILL } + }, + { &hf_jxta_element_encoding, + { "Element Type", "jxta.message.element.encoding", FT_STRING, BASE_NONE, NULL, 0x0, + "JXTA Message Element Encoding", HFILL } + }, + { &hf_jxta_element_content_len, + { "Element Content Length", "jxta.message.element.content.length", FT_UINT32, BASE_DEC, NULL, 0x0, + "JXTA Message Element Content Length", HFILL } + }, + { &hf_jxta_element_content, + { "Element Content", "jxta.message.element.content", FT_BYTES, BASE_HEX, NULL, 0x0, + "JXTA Message Element Content", HFILL } + }, + { &hf_jxta_element_signature, + { "Element Signature", "jxta.message.element.signature", FT_NONE, BASE_NONE, NULL, 0x0, + "JXTA Message Element Signature", HFILL } + } +}; + +/** setup protocol subtree array */ +static gint * const ett[] = { + &ett_jxta_welcome, + &ett_jxta_udp, + &ett_jxta_framing, + &ett_jxta_msg, + &ett_jxta_elem +}; + +static int gUDP_MULTICAST_PORT_JXTA = 1234; +static int gHTTP_PORT_JXTA = 9700; +static int gTCP_PORT_JXTA = 9701; + +static int regUDP_MULTICAST_PORT_JXTA = -1; +static int regHTTP_PORT_JXTA = -1; +static int regTCP_PORT_JXTA = -1; + + +static void dissect_jxta_framing(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree); + +static void dissect_jxta_message(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree); + +void proto_reg_handoff_jxta(void); + +/** + Dissect a tvbuff containing a JXTA UDP header, JXTA Message framing and a JXTA Message +**/ +static void dissect_jxta_udp(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree) { + proto_tree *jxta_tree = NULL; + proto_item *ti; + + if (check_col(pinfo->cinfo, COL_PROTOCOL)) { + col_set_str(pinfo->cinfo, COL_PROTOCOL, "JXTA"); + } + + if (check_col(pinfo->cinfo, COL_INFO)) { + /* + * bondolo For now just say its a message. eventually put in dest addr. + */ + col_add_fstr(pinfo->cinfo, COL_INFO, "%s", "UDP Message"); + } + + guint32 udpsignature = tvb_get_ntohl( tvb, 0 ); + + gboolean goodsig = 0 == (udpsignature ^ 0x4A585441U); + + if (tree) { + ti = proto_tree_add_item(tree, hf_jxta_udp, tvb, 0, -1, FALSE); + jxta_tree = proto_item_add_subtree(ti, ett_jxta_udp); + + ti = proto_tree_add_item( jxta_tree, hf_jxta_udpsig, tvb, 0, 4, FALSE ); + + if( goodsig ) { + PROTO_ITEM_SET_HIDDEN( ti ); + } + } + + if( goodsig ) { + tvbuff_t* jxta_framed_message_tvb = tvb_new_subset( tvb, 4, tvb_length(tvb) - 4, tvb_length(tvb) - 4 ); + + dissect_jxta_framing( jxta_framed_message_tvb, pinfo, tree ); + } +} + +static void dissect_jxta_tcp_pdu(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree) { + dissect_jxta_message( tvb, pinfo, tree ); +} + +static void dissect_jxta_tcp(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree) { + tcp_dissect_pdus(tvb, pinfo, tree, TRUE, 0, NULL, dissect_jxta_tcp_pdu); +} + +/** + Dissect a tvbuff containing a JXTA Message framing and a JXTA Message +**/ +static void dissect_jxta_framing(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree) { + proto_tree *jxta_tree; + proto_item *ti; + guint offset = 0; + + if (tree) { + ti = proto_tree_add_item(tree, hf_jxta_framing, tvb, 0, -1, FALSE); + jxta_tree = proto_item_add_subtree(ti, ett_jxta_framing); + } + + /* parse framing headers */ + do { + guint8 headernamelen = tvb_get_guint8( tvb, offset ); + + if(tree) { + ti = proto_tree_add_item( jxta_tree, hf_jxta_framing_header_name_length, tvb, offset, 1, FALSE ); + PROTO_ITEM_SET_HIDDEN( ti ); + } + + if( tree && (headernamelen > 0) ) { + /* + * Put header name into protocol tree. + */ + ti = proto_tree_add_string(jxta_tree, hf_jxta_framing_header_name, tvb, offset+1, headernamelen, + tvb_format_text(tvb, offset+1, headernamelen)); + } + + offset += 1 + headernamelen; + + if( headernamelen > 0 ) { + guint16 headervaluelen = tvb_get_ntohs( tvb, offset ); + + if( tree ) { + ti = proto_tree_add_item(jxta_tree, hf_jxta_framing_header_value_length, tvb, offset, 2, FALSE ); + PROTO_ITEM_SET_HIDDEN( ti ); + + /** TODO bondolo Add specific handling for known header types */ + + /* + * Put header value into protocol tree. + */ + ti = proto_tree_add_item(jxta_tree, hf_jxta_framing_header_value, tvb, offset+2, headervaluelen, FALSE ); + } + + offset += 2 + headervaluelen; + } + + if( 0 == headernamelen ) { + break; + } + } while( TRUE ); + + tvbuff_t* jxta_message_tvb = tvb_new_subset( tvb, offset, tvb_length(tvb) - offset, tvb_length(tvb) - offset ); + + /* Call it a new layer and pass the tree as we got it */ + dissect_jxta_message( jxta_message_tvb, pinfo, tree ); +} + +/** + Dissect a tvbuff containing a JXTA Message +**/ +static void dissect_jxta_message(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree) { + proto_tree *jxta_tree = NULL; + proto_item *ti; + + if (check_col(pinfo->cinfo, COL_PROTOCOL)) { + col_set_str(pinfo->cinfo, COL_PROTOCOL, "JXTA"); + } + + if (check_col(pinfo->cinfo, COL_INFO)) { + /* + * TODO bondolo For now just say its a message. eventually put in dest addr. + */ + col_add_fstr(pinfo->cinfo, COL_INFO, "%s", "Message"); + } + + if (tree) { + ti = proto_tree_add_item(tree, hf_jxta_message, tvb, 0, -1, FALSE); + jxta_tree = proto_item_add_subtree(ti, ett_jxta_udp); + } + + guint32 msgsignature = tvb_get_ntohl( tvb, 0 ); + + gboolean goodsig = 0 == (msgsignature ^ 0x6A786D67U); + + if( tree ) { + ti = proto_tree_add_item( jxta_tree, hf_jxta_message_sig, tvb, 0, sizeof(guint32), FALSE ); + + if( goodsig ) { + guint8 messageVersion; + PROTO_ITEM_SET_HIDDEN( ti ); + + messageVersion = tvb_get_guint8( tvb, sizeof(guint32) ); + ti = proto_tree_add_item( jxta_tree, hf_jxta_message_version, tvb, sizeof(guint32), 1, FALSE ); + + if( 0 == messageVersion ) { + int eachNamespace; + guint16 numberOfElements; + unsigned int offset = 7; + guint16 messageNamespaceCount = tvb_get_ntohs( tvb, 5 ); + + /* parse namespaces */ + /* TODO 20050103 bondolo Should record the namespaces and number them. */ + for( eachNamespace = 0; eachNamespace < messageNamespaceCount; eachNamespace++ ) { + guint8 namespaceLen = tvb_get_guint8( tvb, offset ); + + ti = proto_tree_add_item(jxta_tree, hf_jxta_message_namespace_len, tvb, offset++, namespaceLen, FALSE ); + PROTO_ITEM_SET_HIDDEN( ti ); + + ti = proto_tree_add_string(jxta_tree, hf_jxta_message_namespace_name, tvb, offset, namespaceLen, + tvb_format_text(tvb, offset, namespaceLen)); + + offset += namespaceLen; + } + + /* parse elements */ + numberOfElements = tvb_get_ntohs( tvb, offset ); + ti = proto_tree_add_item(jxta_tree, hf_jxta_message_element_count, tvb, offset, sizeof(guint16), FALSE ); + offset += sizeof(guint16); + + while( offset < tvb_length(tvb) ) { + proto_tree *jxta_elem_tree = NULL; + proto_item *elem_ti; + + elem_ti = proto_tree_add_item(jxta_tree, hf_jxta_element, tvb, 0, -1, FALSE); + jxta_elem_tree = proto_item_add_subtree(elem_ti, ett_jxta_elem); + + /* gross hack for parsing of signature element */ + element_parse : + { + guint32 elemsignature = tvb_get_ntohl( tvb, offset ); + gboolean goodsig = 0 == (elemsignature ^ 0x6A78656CU); + + ti = proto_tree_add_item( jxta_tree, hf_jxta_element_sig, tvb, offset, 4, FALSE ); + offset += 4; + if( goodsig ) { + guint8 namespaceID; + guint8 flags; + guint16 nameLen; + guint32 elemContentLength; + PROTO_ITEM_SET_HIDDEN( ti ); + + namespaceID = tvb_get_guint8( tvb, offset ); + ti = proto_tree_add_item( jxta_elem_tree, hf_jxta_element_namespaceid, tvb, offset, sizeof(guint8), FALSE ); + offset += sizeof(guint8); + + flags = tvb_get_guint8( tvb, offset ); + ti = proto_tree_add_item( jxta_elem_tree, hf_jxta_element_flags, tvb, offset, sizeof(guint8), FALSE ); + offset += sizeof(guint8); + + nameLen = tvb_get_ntohs( tvb, offset ); + ti = proto_tree_add_item( jxta_elem_tree, hf_jxta_element_name_len, tvb, offset, sizeof(guint16), FALSE ); + offset += sizeof(guint16); + PROTO_ITEM_SET_HIDDEN( ti ); + + ti = proto_tree_add_string(jxta_elem_tree, hf_jxta_element_name, tvb, offset, nameLen, + tvb_format_text(tvb, offset, nameLen)); + + offset += nameLen; + + /* process type */ + if( (flags & 0x01) != 0 ) { + guint16 typeLen = tvb_get_ntohs( tvb, offset ); + ti = proto_tree_add_item( jxta_elem_tree, hf_jxta_element_type_len, tvb, offset, sizeof(guint16), FALSE ); + offset += sizeof(guint16); + PROTO_ITEM_SET_HIDDEN( ti ); + + ti = proto_tree_add_string(jxta_elem_tree, hf_jxta_element_type, tvb, offset, typeLen, + tvb_format_text(tvb, offset, typeLen)); + + offset += typeLen; + } + + /* process encoding */ + if( (flags & 0x02) != 0 ) { + guint16 encodingLen = tvb_get_ntohs( tvb, offset ); + ti = proto_tree_add_item( jxta_elem_tree, hf_jxta_element_encoding_len, tvb, offset, sizeof(guint16), FALSE ); + offset += sizeof(guint16); + PROTO_ITEM_SET_HIDDEN( ti ); + + ti = proto_tree_add_string(jxta_elem_tree, hf_jxta_element_encoding, tvb, offset, encodingLen, + tvb_format_text(tvb, offset, encodingLen)); + + offset += encodingLen; + } + + /* content */ + elemContentLength = tvb_get_ntohl( tvb, offset ); + ti = proto_tree_add_item( jxta_elem_tree, hf_jxta_element_content_len, tvb, offset, sizeof(guint32), FALSE ); + offset += sizeof(guint32); + + ti = proto_tree_add_item( jxta_elem_tree, hf_jxta_element_content, tvb, offset, elemContentLength, FALSE ); + offset += elemContentLength; + + /* XXX Evil Hack Warning : handle parsing of signature element. Would be better with recursion.*/ + if( (flags & 0x04) != 0 ) { + goto element_parse; + } + } + + proto_item_set_end( elem_ti, tvb, offset - 1 ); + } + } + } + } + } +} + +void proto_register_jxta(void) +{ + module_t *jxta_module; + + proto_jxta = proto_register_protocol("JXTA P2P", "JXTA", "jxta"); + + /* Register header fields */ + proto_register_field_array(proto_jxta, hf, array_length(hf)); + + /* Register JXTA Sub-tree */ + proto_register_subtree_array(ett, array_length(ett)); + + /* Register preferences */ + jxta_module = prefs_register_protocol(proto_jxta, proto_reg_handoff_jxta); + + prefs_register_uint_preference(jxta_module, "tcp.port", "JXTA TCP Port", + "Set the port for JXTA TCP messages", + 10, &gTCP_PORT_JXTA); + + prefs_register_uint_preference(jxta_module, "http.port", "JXTA HTTP Port", + "Set the port for JXTA HTTP messages", + 10, &gHTTP_PORT_JXTA); + + prefs_register_uint_preference(jxta_module, "udp.port", "JXTA UDP Multicast Port", + "Set the port for JXTA UDP Multicast messages", + 10, &gUDP_MULTICAST_PORT_JXTA); +} + +void proto_reg_handoff_jxta(void) { + static gboolean jxta_prefs_initialized = FALSE; + + if (!jxta_prefs_initialized) { + udpm_jxta_handle = create_dissector_handle(dissect_jxta_udp, proto_jxta); + tcp_jxta_handle = create_dissector_handle(dissect_jxta_tcp, proto_jxta); + http_jxta_handle = create_dissector_handle(dissect_jxta_message, proto_jxta); + + jxta_prefs_initialized = TRUE; + } else { + dissector_delete("udp.port", regUDP_MULTICAST_PORT_JXTA, udpm_jxta_handle); + + dissector_delete("tcp.port", regTCP_PORT_JXTA, tcp_jxta_handle); + + dissector_delete("http.port", regHTTP_PORT_JXTA, http_jxta_handle); + } + + /* remember what ports we registered on for later removal */ + regUDP_MULTICAST_PORT_JXTA = gUDP_MULTICAST_PORT_JXTA; + regTCP_PORT_JXTA = gTCP_PORT_JXTA; + regHTTP_PORT_JXTA = gHTTP_PORT_JXTA; + + /* register as a sub-dissector of UDP tagged on port field */ + dissector_add("udp.port", regUDP_MULTICAST_PORT_JXTA, udpm_jxta_handle); + + /* register as a sub-dissector of TCP tagged on port field*/ + dissector_add("tcp.port", regTCP_PORT_JXTA, tcp_jxta_handle); + + /* register as a sub-dissector of HTTP tagged on port field */ + dissector_add("http.port", regHTTP_PORT_JXTA, http_jxta_handle); +}
Index: doc/README.developer =================================================================== --- doc/README.developer (revision 12945) +++ doc/README.developer (working copy) @@ -2398,7 +2398,7 @@ 2.5 Per packet information -Information can be stored for each data packet that is process by the dissector. +Information can be stored for each data packet that is processed by the dissector. The information is added with the p_add_proto_data function and retreived with the p_get_proto_data function. The data pointers passed into the p_add_proto_data are not managed by the proto_data routines. If you use malloc or any other dynamic @@ -2523,7 +2523,7 @@ followed by additional data. The second one is more generic but requires more code and is less efficient. -For the first method, you register two different dissection methods, on +For the first method, you register two different dissection methods, one for the TCP case, and one for the other cases. It is a good idea to have a dissect_PROTO_common function which will parse the generic content that you can find in all PDUs which is called from Index: epan/tvbuff.h =================================================================== --- epan/tvbuff.h (revision 12945) +++ epan/tvbuff.h (working copy) @@ -38,7 +38,18 @@ #include <glib.h> #include "exceptions.h" -/* The different types of tvbuff's */ +/** @file + * "testy, virtual(-izable) buffer". They are testy in that they get mad when + * an attempt is made to access data beyond the bounds of their array. In that + * case, they throw an exception. + * + * They are virtualizable in that new tvbuff's can be made from other tvbuffs, + * while only the original tvbuff may have data. That is, the new tvbuff has + * virtual data. + */ + + +/** The different types of tvbuff's */ typedef enum { TVBUFF_REAL_DATA, TVBUFF_SUBSET, @@ -110,7 +121,7 @@ -/* TVBUFF_REAL_DATA contains a guint8* that points to real data. +/** TVBUFF_REAL_DATA contains a guint8* that points to real data. * The data is allocated and contiguous. * * TVBUFF_SUBSET has a backing tvbuff. The TVBUFF_SUBSET is a "window" @@ -129,21 +140,21 @@ */ -/* "class" initialization. Called once during execution of program +/** "class" initialization. Called once during execution of program * so that tvbuff.c can initialize its data. */ extern void tvbuff_init(void); -/* "class" cleanup. Called once during execution of program +/** "class" cleanup. Called once during execution of program * so that tvbuff.c can clean up its data. */ extern void tvbuff_cleanup(void); -/* Returns a pointer to a newly initialized tvbuff. Note that +/** Returns a pointer to a newly initialized tvbuff. Note that * tvbuff's of types TVBUFF_SUBSET and TVBUFF_COMPOSITE * require further initialization via the appropriate functions */ extern tvbuff_t* tvb_new(tvbuff_type); -/* Marks a tvbuff for freeing. The guint8* data of a TVBUFF_REAL_DATA +/** Marks a tvbuff for freeing. The guint8* data of a TVBUFF_REAL_DATA * is *never* freed by the tvbuff routines. The tvbuff itself is actually freed * once its usage count drops to 0. * @@ -164,27 +175,27 @@ */ extern void tvb_free(tvbuff_t*); -/* Free the tvbuff_t and all tvbuff's created from it. */ +/** Free the tvbuff_t and all tvbuff's created from it. */ extern void tvb_free_chain(tvbuff_t*); -/* Both return the new usage count, after the increment or decrement */ +/** Both return the new usage count, after the increment or decrement */ extern guint tvb_increment_usage_count(tvbuff_t*, guint count); -/* If a decrement causes the usage count to drop to 0, a the tvbuff +/** If a decrement causes the usage count to drop to 0, a the tvbuff * is immediately freed. Be sure you know exactly what you're doing * if you decide to use this function, as another tvbuff could * still have a pointer to the just-freed tvbuff, causing corrupted data * or a segfault in the future */ extern guint tvb_decrement_usage_count(tvbuff_t*, guint count); -/* Set a callback function to call when a tvbuff is actually freed +/** Set a callback function to call when a tvbuff is actually freed * (once the usage count drops to 0). One argument is passed to * that callback --- a void* that points to the real data. * Obviously, this only applies to a TVBUFF_REAL_DATA tvbuff. */ extern void tvb_set_free_cb(tvbuff_t*, tvbuff_free_cb_t); -/* Attach a TVBUFF_REAL_DATA tvbuff to a parent tvbuff. This connection +/** Attach a TVBUFF_REAL_DATA tvbuff to a parent tvbuff. This connection * is used during a tvb_free_chain()... the "child" TVBUFF_REAL_DATA acts * as if is part of the chain-of-creation of the parent tvbuff, although it * isn't. This is useful if you need to take the data from some tvbuff, @@ -195,16 +206,16 @@ * the tvbuff routines knowledgable of this fact. */ extern void tvb_set_child_real_data_tvbuff(tvbuff_t* parent, tvbuff_t* child); -/* Sets parameters for TVBUFF_REAL_DATA. Can throw ReportedBoundsError. */ +/**Sets parameters for TVBUFF_REAL_DATA. Can throw ReportedBoundsError. */ extern void tvb_set_real_data(tvbuff_t*, const guint8* data, guint length, gint reported_length); -/* Combination of tvb_new() and tvb_set_real_data(). Can throw ReportedBoundsError. */ +/** Combination of tvb_new() and tvb_set_real_data(). Can throw ReportedBoundsError. */ extern tvbuff_t* tvb_new_real_data(const guint8* data, guint length, gint reported_length); -/* Define the subset of the backing buffer to use. +/** Define the subset of the backing buffer to use. * * 'backing_offset' can be negative, to indicate bytes from * the end of the backing buffer. @@ -220,27 +231,27 @@ extern void tvb_set_subset(tvbuff_t* tvb, tvbuff_t* backing, gint backing_offset, gint backing_length, gint reported_length); -/* Combination of tvb_new() and tvb_set_subset() +/** Combination of tvb_new() and tvb_set_subset() * Can throw ReportedBoundsError. */ extern tvbuff_t* tvb_new_subset(tvbuff_t* backing, gint backing_offset, gint backing_length, gint reported_length); -/* Both tvb_composite_append and tvb_composite_prepend can throw +/** Both tvb_composite_append and tvb_composite_prepend can throw * BoundsError if member_offset/member_length goes beyond bounds of * the 'member' tvbuff. */ -/* Append to the list of tvbuffs that make up this composite tvbuff */ +/** Append to the list of tvbuffs that make up this composite tvbuff */ extern void tvb_composite_append(tvbuff_t* tvb, tvbuff_t* member); -/* Prepend to the list of tvbuffs that make up this composite tvbuff */ +/** Prepend to the list of tvbuffs that make up this composite tvbuff */ extern void tvb_composite_prepend(tvbuff_t* tvb, tvbuff_t* member); -/* Helper function that calls tvb_new(TVBUFF_COMPOSITE). +/** Helper function that calls tvb_new(TVBUFF_COMPOSITE). * Provided only to maintain symmetry with other constructors */ extern tvbuff_t* tvb_new_composite(void); -/* Mark a composite tvbuff as initialized. No further appends or prepends +/** Mark a composite tvbuff as initialized. No further appends or prepends * occur, data access can finally happen after this finalization. */ extern void tvb_composite_finalize(tvbuff_t* tvb); @@ -248,19 +259,19 @@ /* Get total length of buffer */ extern guint tvb_length(tvbuff_t*); -/* Computes bytes to end of buffer, from offset (which can be negative, +/** Computes bytes to end of buffer, from offset (which can be negative, * to indicate bytes from end of buffer). Function returns -1 to * indicate that offset is out of bounds. No exception is thrown. */ extern gint tvb_length_remaining(tvbuff_t*, gint offset); -/* Same as above, but throws an exception if the offset is out of bounds. */ +/** Same as above, but throws an exception if the offset is out of bounds. */ extern guint tvb_ensure_length_remaining(tvbuff_t*, gint offset); /* Checks (w/o throwing exception) that the bytes referred to by * 'offset'/'length' actually exist in the buffer */ extern gboolean tvb_bytes_exist(tvbuff_t*, gint offset, gint length); -/* Checks that the bytes referred to by 'offset'/'length' actually exist +/** Checks that the bytes referred to by 'offset'/'length' actually exist * in the buffer, and throws an exception if they aren't. */ extern void tvb_ensure_bytes_exist(tvbuff_t *tvb, gint offset, gint length); @@ -270,13 +281,13 @@ /* Get reported length of buffer */ extern guint tvb_reported_length(tvbuff_t*); -/* Computes bytes of reported packet data to end of buffer, from offset +/** Computes bytes of reported packet data to end of buffer, from offset * (which can be negative, to indicate bytes from end of buffer). Function * returns -1 to indicate that offset is out of bounds. No exception is * thrown. */ extern gint tvb_reported_length_remaining(tvbuff_t *tvb, gint offset); -/* Set the reported length of a tvbuff to a given value; used for protocols +/** Set the reported length of a tvbuff to a given value; used for protocols whose headers contain an explicit length and where the calling dissector's payload may include padding as well as the packet for this protocol. @@ -309,7 +320,7 @@ extern gfloat tvb_get_letohieee_float(tvbuff_t*, gint offset); extern gdouble tvb_get_letohieee_double(tvbuff_t*, gint offset); -/* Returns target for convenience. Does not suffer from possible +/** Returns target for convenience. Does not suffer from possible * expense of tvb_get_ptr(), since this routine is smart enough * to copy data in chunks if the request range actually exists in * different TVBUFF_REAL_DATA tvbuffs. This function assumes that the @@ -317,11 +328,11 @@ * target memory. */ extern guint8* tvb_memcpy(tvbuff_t*, guint8* target, gint offset, gint length); -/* It is the user's responsibility to g_free() the memory allocated by +/** It is the user's responsibility to g_free() the memory allocated by * tvb_memdup(). Calls tvb_memcpy() */ extern guint8* tvb_memdup(tvbuff_t*, gint offset, gint length); -/* WARNING! This function is possibly expensive, temporarily allocating +/** WARNING! This function is possibly expensive, temporarily allocating * another copy of the packet data. Furthermore, it's dangerous because once * this pointer is given to the user, there's no guarantee that the user will * honor the 'length' and not overstep the boundaries of the buffer. @@ -341,7 +352,7 @@ * tvbuff_free_cb_t() is called, if any. */ extern const guint8* tvb_get_ptr(tvbuff_t*, gint offset, gint length); -/* Find first occurence of any of the needles in tvbuff, starting at offset. +/** Find first occurence of any of the needles in tvbuff, starting at offset. * Searches at most maxlength number of bytes; if maxlength is -1, searches * to end of tvbuff. * Returns the offset of the found needle, or -1 if not found. @@ -351,7 +362,7 @@ extern gint tvb_find_guint8(tvbuff_t*, gint offset, gint maxlength, guint8 needle); -/* Find first occurence of any of the needles in tvbuff, starting at offset. +/** Find first occurence of any of the needles in tvbuff, starting at offset. * Searches at most maxlength number of bytes. Returns the offset of the * found needle, or -1 if not found. Will not throw an exception, even if * maxlength exceeds boundary of tvbuff; in that case, -1 will be returned if @@ -359,38 +370,38 @@ extern gint tvb_pbrk_guint8(tvbuff_t *, gint offset, gint maxlength, guint8 *needles); -/* Find size of stringz (NUL-terminated string) by looking for terminating +/** Find size of stringz (NUL-terminated string) by looking for terminating * NUL. The size of the string includes the terminating NUL. * * If the NUL isn't found, it throws the appropriate exception. */ extern guint tvb_strsize(tvbuff_t *tvb, gint offset); -/* Find length of string by looking for end of string ('\0'), up to +/** Find length of string by looking for end of string ('\0'), up to * 'maxlength' characters'; if 'maxlength' is -1, searches to end * of tvbuff. * Returns -1 if 'maxlength' reached before finding EOS. */ extern gint tvb_strnlen(tvbuff_t*, gint offset, guint maxlength); -/* Convert a string from Unicode to ASCII. At the moment we fake it by +/** Convert a string from Unicode to ASCII. At the moment we fake it by * assuming all characters are ASCII )-: The caller must free the * result returned. The len parameter is the number of guint16's to * convert from Unicode. */ extern char *tvb_fake_unicode(tvbuff_t *tvb, int offset, int len, gboolean little_endian); -/* +/** * Format the data in the tvb from offset for size ... */ extern gchar * tvb_format_text(tvbuff_t *tvb, gint offset, gint size); -/* +/** * Like "tvb_format_text()", but for null-padded strings; don't show * the null padding characters as "\000". */ extern gchar *tvb_format_stringzpad(tvbuff_t *tvb, gint offset, gint size); -/* +/** * Given a tvbuff, an offset, and a length, allocate a buffer big enough * to hold a non-null-terminated string of that length at that offset, * plus a trailing '\0', copy the string into it, and return a pointer @@ -400,7 +411,7 @@ */ extern guint8 *tvb_get_string(tvbuff_t *tvb, gint offset, gint length); -/* +/** * Given a tvbuff and an offset, with the offset assumed to refer to * a null-terminated string, find the length of that string (and throw * an exception if the tvbuff ends before we find the null), allocate @@ -410,7 +421,7 @@ */ extern guint8 *tvb_get_stringz(tvbuff_t *tvb, gint offset, gint *lengthp); -/* Looks for a stringz (NUL-terminated string) in tvbuff and copies +/** Looks for a stringz (NUL-terminated string) in tvbuff and copies * no more than bufsize number of bytes, including terminating NUL, to buffer. * Returns length of string (not including terminating NUL), or -1 if the string was * truncated in the buffer due to not having reached the terminating NUL. @@ -426,7 +437,7 @@ extern gint tvb_get_nstringz(tvbuff_t *tvb, gint offset, guint bufsize, guint8* buffer); -/* Like tvb_get_nstringz(), but never returns -1. The string is guaranteed to +/** Like tvb_get_nstringz(), but never returns -1. The string is guaranteed to * have a terminating NUL. If the string was truncated when copied into buffer, * a NUL is placed at the end of buffer to terminate it. * @@ -435,7 +446,7 @@ extern gint tvb_get_nstringz0(tvbuff_t *tvb, gint offset, guint bufsize, guint8* buffer); -/* +/** * Given a tvbuff, an offset into the tvbuff, and a length that starts * at that offset (which may be -1 for "all the way to the end of the * tvbuff"), find the end of the (putative) line that starts at the @@ -457,7 +468,7 @@ extern gint tvb_find_line_end(tvbuff_t *tvb, gint offset, int len, gint *next_offset, gboolean desegment); -/* +/** * Given a tvbuff, an offset into the tvbuff, and a length that starts * at that offset (which may be -1 for "all the way to the end of the * tvbuff"), find the end of the (putative) line that starts at the @@ -478,28 +489,28 @@ extern gint tvb_find_line_end_unquoted(tvbuff_t *tvb, gint offset, int len, gint *next_offset); -/* +/** * Call strncmp after checking if enough chars left, returning 0 if * it returns 0 (meaning "equal") and -1 otherwise, otherwise return -1. */ extern gint tvb_strneql(tvbuff_t *tvb, gint offset, const gchar *str, gint size); -/* +/** * Call strncasecmp after checking if enough chars left, returning 0 if * it returns 0 (meaning "equal") and -1 otherwise, otherwise return -1. */ extern gint tvb_strncaseeql(tvbuff_t *tvb, gint offset, const gchar *str, gint size); -/* +/** * Call memcmp after checking if enough chars left, returning 0 if * it returns 0 (meaning "equal") and -1 otherwise, otherwise return -1. */ extern gint tvb_memeql(tvbuff_t *tvb, gint offset, const guint8 *str, gint size); -/* +/** * Format a bunch of data from a tvbuff as bytes, returning a pointer * to the string with the formatted data, with "punct" as a byte * separator. @@ -516,14 +527,14 @@ #define TVB_GET_DS_TVB(tvb) \ (tvb->ds_tvb) -/* Locate a sub-tvbuff within another tvbuff, starting at position +/** Locate a sub-tvbuff within another tvbuff, starting at position * 'haystack_offset'. Returns the index of the beginning of 'needle' within * 'haystack', or -1 if 'needle' is not found. The index is relative * to the start of 'haystack', not 'haystack_offset'. */ extern gint tvb_find_tvb(tvbuff_t *haystack_tvb, tvbuff_t *needle_tvb, gint haystack_offset); -/* +/** * Uncompresses a zlib compressed packet inside a tvbuff at offset with * length comprlen. Returns an uncompressed tvbuffer if uncompression * succeeded or NULL if uncompression failed.
- Follow-Ups:
- Re: [Ethereal-dev] Patches for JXTA Protocol Dissector
- From: Guy Harris
- Re: [Ethereal-dev] Patches for JXTA Protocol Dissector
- Prev by Date: [Ethereal-dev] ethereal crash
- Next by Date: [Ethereal-dev] buildbot failure in Windows 2000 (IA32)
- Previous by thread: Re: [Ethereal-dev] Ethereal crash
- Next by thread: Re: [Ethereal-dev] Patches for JXTA Protocol Dissector
- Index(es):