Ethereal-dev: [Ethereal-dev] Precisions needed on how to integrate the call to the sub-dissec
Title: [Ethereal-dev] Precisions needed on how to integrate the call to the sub-dissector into the parent dissector
Hi List,
I'm currently writing a dissector for a proprietary protocol (let's call it myproto) that runs on top of TCP and use a field value to discriminate between two sub-dissectors to call : either TCAP or MAP.
The integration to TCP is OK.
My problem is that I don't know how to integrate those calls to the sub-dissectors in my code.
I know that a similar question has been asked beginning of november, but I read the answers and I am still confused about the way to implement it.
Could somebody complete those code snippets below ?
Thanks in advance,
Yann.
static void
dissect_myproto_common(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
{
guint offset = 0;
guint packet_length = 0;
guint msgtype = 0;
proto_tree *myproto_tree = NULL;
proto_tree *header_tree = NULL;
proto_item *ti = NULL;
tvbuff_t *next_tvb = NULL;;
int reported_length = 0;
int available_length = 0;
int data_offset = 0;
int field = 0;
if (check_col(pinfo->cinfo, COL_INFO))
col_clear(pinfo->cinfo, COL_INFO);
packet_length = tvb_get_letohs(tvb, 1);
if (tree) {
/* Tree building code snipped */
}
if (data_offset > 0) { /* offset to the first byte of the sub-protocol ; should be non-zero */
available_length = tvb_length(tvb) - data_offset;
reported_length = tvb_get_letohs(tvb, data_offset - 2); /* the length of the data is given just before the start */
next_tvb = tvb_new_subset(tvb, offset, MIN(available_length, reported_length), reported_length);
switch (field) {
case TCAP:
/* What should I do here ??? */
break;
case MAP:
/* What should I do here ??? */
break;
default:
break;
}
}
}
void
proto_register_myproto(void)
{
static hf_register_info hf[] = {
{ &hf_myproto_header, {"Header", "myproto.header", FT_UINT8, BASE_DEC, NULL, 0x0, "Sub-dissector Field", HFILL }},
};
static gint *ett[] = {
&ett_myproto,
};
module_t *myproto_module;
/* Registering the MYPROTO protocol */
proto_myproto = proto_register_protocol("MYPROTO Protocol", "MYPROTO", "myproto");
proto_register_field_array(proto_myproto, hf, array_length(hf));
proto_register_subtree_array(ett, array_length(ett));
/* Registering the MYPROTO protocol preferences */
myproto_module = prefs_register_protocol(proto_myproto, NULL);
/* Registering the default ports to use over TCP */
prefs_register_uint_preference(myproto_module, "tcp_port", "MYPROTO port", "MYPROTO port (default 3000)", 10, &tcp_port_myproto);
/* Registering the desegmentation preference*/
prefs_register_bool_preference(myproto_module, "desegment_myproto_messages", "Desegment all MYPROTO messages spanning multiple TCP segments", "Whether the MYPROTO dissector should desegment all messages spanning multiple TCP segments", &myproto_desegment);
/* What should I do here ??? */
}
void
proto_reg_handoff_myproto(void)
{
dissector_handle_t myproto_tcp_handle;
myproto_tcp_handle = create_dissector_handle(dissect_myproto_tcp, proto_myproto);
dissector_add("tcp.port", tcp_port_myproto, myproto_tcp_handle);
/* What should I do here ??? */
}