rendered paste body/* * CS417 A4 template * File: packet-mbp.c * This file cotains a simple template dissector for an application protocol * called MBP(My bogus protocol) */#ifdef HAVE_CONFIG_H# include "config.h"#endif#include <gmodule.h>#include <epan/packet.h>#include <epan/prefs.h>/* forward reference */void proto_register_mbp();void proto_reg_handoff_mbp();void dissect_mbp(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree);static int proto_mbp = -1;static int global_mbp_port = 5678;static dissector_handle_t mbp_handle;/* task1: declare your packet structure and other fields here */#define MBP_START_FLAG 0x01#define MBP_END_FLAG 0x02#define MBP_PRIORITY_FLAG 0x04static int hf_mbp_startflag = -1;static int hf_mbp_endflag = -1;static int hf_mbp_priorityflag = -1;static int hf_mbp_pdu_type = -1;static gint ett_mbp = -1;static int hf_mbp_flags = -1;static int hf_mbp_sequenceno = -1;static int hf_mbp_initialip = -1;static const value_string packettypenames[] = { { 1, "INIT" }, { 2, "Terminate" }, { 3, "Data" }, { 0, NULL }};/* end task1 */voidproto_register_mbp(void){ module_t *mbp_module; if (proto_mbp == -1) { proto_mbp = proto_register_protocol ( "MBP Protocol", /* name */ "MBP", /* short name */ "mbp" /* abbrev */ ); } /* task2: register your packet structure */ static hf_register_info hf[] = { { &hf_mbp_pdu_type, { "MBP PDU Type","mbp.type",FT_UINT8, BASE_DEC, VALS(packettypenames), 0x0,NULL, HFILL } }, { &hf_mbp_flags, { "MBP PDU Flags", "mbp.flags", FT_UINT8, BASE_HEX, NULL, 0x0, "", HFILL } }, { &hf_mbp_startflag, { "MBP PDU Start Flags", "mbp.flags.start", FT_BOOLEAN, 8, NULL, MBP_Start_FLAG, NULL, HFILL} }, { &hf_mbp_endflag, { "MBP PDU End Flags", "mbp.flags.end", FT_BOOLEAN, 8, NULL, MBP_END_FLAG, NULL, HFILL} }, { &hf_mbp_priorityflag, { "MBP PDU Priority Flags", "mbp.flags.priority", FT_BOOLEAN, 8, NULL, MBP_PRIORITY_FLAG, NULL, HFILL} }, { &hf_mbp_sequenceno, { "MBP PDU Sequence Number", "mbp.seqn", FT_UINT16, BASE_DEC, NULL, 0x0, "", HFILL } }, { &hf_mbp_initialip, { "MBP PDU Initial IP", "mbp.initialip", FT_IPv4, BASE_NONE, NULL, 0x0, "", HFILL} }, }; /* Setup protocol subtree array */ static gint *ett[] = { &ett_mbp, }; proto_register_field_array(proto_mbp,hf,array_length(hf)); proto_register_subtree_array(ett,array_length(ett)); /* end task2 */ mbp_module = prefs_register_protocol(proto_mbp, proto_reg_handoff_mbp);} voidproto_reg_handoff_mbp(void){ static int Initialized=FALSE; if (!Initialized) { mbp_handle = create_dissector_handle(dissect_mbp, proto_mbp); dissector_add("udp.port", global_mbp_port, mbp_handle); }} voiddissect_mbp(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree){ if (check_col(pinfo->cinfo, COL_PROTOCOL)) col_set_str(pinfo->cinfo, COL_PROTOCOL, "MBP"); /* Clear out stuff in the info column */ if(check_col(pinfo->cinfo,COL_INFO)){ col_clear(pinfo->cinfo,COL_INFO); } /* task3 parsing code goes here */ if (tree) { /* we are being asked for details */ proto_item *ti = NULL; proto_tree *mbp_tree = NULL; gint offset = 0; ti = proto_tree_add_item(tree, proto_mbp, tvb, 0, -1, FALSE); mbp_tree = proto_item_add_subtree(ti, ett_mbp); proto_tree_add_item(mbp_tree, hf_mbp_pdu_type, tvb, offset, 1, FALSE); offset++; proto_tree_add_item(mbp_tree, hf_mbp_flags, tvb,offset,1,FALSE); proto_tree_add_item(mbp_tree, hf_mbp_startflag, tvb, offset, 1,FALSE); proto_tree offset++; proto_tree_add_item(mbp_tree, hf_mbp_sequenceno,tvb,offset,2,FALSE); offset = offset + 2; proto_tree_add_item(mbp_tree, hf_mbp_initialip, tvb, offset, 4, FALSE); offset = offset + 4; } /* end task3 */}