📄 packet-mgcp.c
字号:
{ &hf_mgcp_param_connectionid, {"ConnectionIdentifier (I)", "mgcp.param.connectionid", FT_STRING, BASE_DEC, NULL, 0x0, "Connection Identifier", HFILL }}, { &hf_mgcp_param_secondconnectionid, { "SecondConnectionID (I2)", "mgcp.param.secondconnectionid", FT_STRING, BASE_DEC, NULL, 0x0, "Second Connection Identifier", HFILL }}, { &hf_mgcp_param_notifiedentity, { "NotifiedEntity (N)", "mgcp.param.notifiedentity", FT_STRING, BASE_DEC, NULL, 0x0, "Notified Entity", HFILL }}, { &hf_mgcp_param_requestid, { "RequestIdentifier (X)", "mgcp.param.requestid", FT_STRING, BASE_DEC, NULL, 0x0, "Request Identifier", HFILL }}, { &hf_mgcp_param_localconnoptions, { "LocalConnectionOptions (L)", "mgcp.param.localconnectionoptions", FT_STRING, BASE_DEC, NULL, 0x0, "Local Connection Options", HFILL }}, { &hf_mgcp_param_connectionmode, { "ConnectionMode (M)", "mgcp.param.connectionmode", FT_STRING, BASE_DEC, NULL, 0x0, "Connection Mode", HFILL }}, { &hf_mgcp_param_reqevents, { "RequestedEvents (R)", "mgcp.param.reqevents", FT_STRING, BASE_DEC, NULL, 0x0, "Requested Events", HFILL }}, { &hf_mgcp_param_signalreq, { "SignalRequests (S)", "mgcp.param.signalreq", FT_STRING, BASE_DEC, NULL, 0x0, "Signal Request", HFILL }}, { &hf_mgcp_param_restartmethod, { "RestartMethod (RM)", "mgcp.param.restartmethod", FT_STRING, BASE_DEC, NULL, 0x0, "Restart Method", HFILL }}, { &hf_mgcp_param_restartdelay, { "RestartDelay (RD)", "mgcp.param.restartdelay", FT_STRING, BASE_DEC, NULL, 0x0, "Restart Delay", HFILL }}, { &hf_mgcp_param_digitmap, { "DigitMap (D)", "mgcp.param.digitmap", FT_STRING, BASE_DEC, NULL, 0x0, "Digit Map", HFILL }}, { &hf_mgcp_param_observedevent, { "ObservedEvents (O)", "mgcp.param.observedevents", FT_STRING, BASE_DEC, NULL, 0x0, "Observed Events", HFILL }}, { &hf_mgcp_param_connectionparam, { "ConnectionParameters (P)", "mgcp.param.connectionparam", FT_STRING, BASE_DEC, NULL, 0x0, "Connection Parameters", HFILL }}, { &hf_mgcp_param_reasoncode, { "ReasonCode (E)", "mgcp.param.reasoncode", FT_STRING, BASE_DEC, NULL, 0x0, "Reason Code", HFILL }}, { &hf_mgcp_param_eventstates, { "EventStates (ES)", "mgcp.param.eventstates", FT_STRING, BASE_DEC, NULL, 0x0, "Event States", HFILL }}, { &hf_mgcp_param_specificendpoint, { "SpecificEndpointID (Z)", "mgcp.param.specificendpointid", FT_STRING, BASE_DEC, NULL, 0x0, "Specific Endpoint ID", HFILL }}, { &hf_mgcp_param_secondendpointid, { "SecondEndpointID (Z2)", "mgcp.param.secondendpointid", FT_STRING, BASE_DEC, NULL, 0x0, "Second Endpoing ID", HFILL }}, { &hf_mgcp_param_reqinfo, { "RequestedInfo (F)", "mgcp.param.reqinfo", FT_STRING, BASE_DEC, NULL, 0x0,"Requested Info", HFILL }}, { &hf_mgcp_param_quarantinehandling, { "QuarantineHandling (Q)", "mgcp.param.quarantinehandling", FT_STRING, BASE_DEC, NULL, 0x0, "Quarantine Handling", HFILL }}, { &hf_mgcp_param_detectedevents, { "DetectedEvents (T)", "mgcp.param.detectedevents", FT_STRING, BASE_DEC, NULL, 0x0, "Detected Events", HFILL }}, { &hf_mgcp_param_capabilities, { "Capabilities (A)", "mgcp.param.capabilities", FT_STRING, BASE_DEC, NULL, 0x0, "Capabilities", HFILL }}, { &hf_mgcp_param_extention, { "Extention Parameter (X-*)", "mgcp.param.extention", FT_STRING, BASE_DEC, NULL, 0x0, "Extension Parameter", HFILL }}, { &hf_mgcp_param_invalid, { "Invalid Parameter", "mgcp.param.invalid", FT_STRING, BASE_DEC, NULL, 0x0, "Invalid Parameter", HFILL }}, { &hf_mgcp_messagecount, { "MGCP Message Count", "mgcp.messagecount", FT_UINT32, BASE_DEC, NULL, 0x0, "Number of MGCP message in a packet", HFILL }}, /* Add more fields here */ }; static gint *ett[] = { &ett_mgcp, &ett_mgcp_param, }; module_t *mgcp_module; proto_mgcp = proto_register_protocol("Media Gateway Control Protocol", "MGCP", "mgcp"); proto_register_field_array(proto_mgcp, hf, array_length(hf)); proto_register_subtree_array(ett, array_length(ett)); /* Register our configuration options for , particularly our ports */ mgcp_module = prefs_register_protocol(proto_mgcp, proto_reg_handoff_mgcp); prefs_register_uint_preference(mgcp_module, "tcp.gateway_port", "MGCP Gateway TCP Port", "Set the UDP port for gateway messages " "(if other than the default of 2427)", 10, &global_mgcp_gateway_tcp_port); prefs_register_uint_preference(mgcp_module, "udp.gateway_port", "MGCP Gateway UDP Port", "Set the TCP port for gateway messages " "(if other than the default of 2427)", 10, &global_mgcp_gateway_udp_port); prefs_register_uint_preference(mgcp_module, "tcp.callagent_port", "MGCP Callagent TCP Port", "Set the TCP port for callagent messages " "(if other than the default of 2727)", 10, &global_mgcp_callagent_tcp_port); prefs_register_uint_preference(mgcp_module, "udp.callagent_port", "MGCP Callagent UDP Port", "Set the UDP port for callagent messages " "(if other than the default of 2727)", 10, &global_mgcp_callagent_udp_port); prefs_register_bool_preference(mgcp_module, "display_raw_text", "Display raw text for MGCP message", "Specifies that the raw text of the " "MGCP message should be displayed " "instead of (or in addition to) the " "dissection tree", &global_mgcp_raw_text); prefs_register_bool_preference(mgcp_module, "display_dissect_tree", "Display tree dissection for MGCP message", "Specifies that the dissection tree of the " "MGCP message should be displayed " "instead of (or in addition to) the " "raw text", &global_mgcp_dissect_tree); prefs_register_bool_preference(mgcp_module, "display_mgcp_message_count", "Display the number of MGCP messages", "Display the number of MGCP messages " "found in a packet in the protocol column.", &global_mgcp_message_count);}/* The registration hand-off routine */voidproto_reg_handoff_mgcp(void){ static int mgcp_prefs_initialized = FALSE; static dissector_handle_t mgcp_handle; /* * Get a handle for the SDP dissector. */ sdp_handle = find_dissector("sdp"); if (!mgcp_prefs_initialized) { mgcp_handle = create_dissector_handle(dissect_mgcp, proto_mgcp); mgcp_prefs_initialized = TRUE; } else { dissector_delete("tcp.port", gateway_tcp_port, mgcp_handle); dissector_delete("udp.port", gateway_udp_port, mgcp_handle); dissector_delete("tcp.port", callagent_tcp_port, mgcp_handle); dissector_delete("udp.port", callagent_udp_port, mgcp_handle); } /* Set our port number for future use */ gateway_tcp_port = global_mgcp_gateway_tcp_port; gateway_udp_port = global_mgcp_gateway_udp_port; callagent_tcp_port = global_mgcp_callagent_tcp_port; callagent_udp_port = global_mgcp_callagent_udp_port; dissector_add("tcp.port", global_mgcp_gateway_tcp_port, mgcp_handle); dissector_add("udp.port", global_mgcp_gateway_udp_port, mgcp_handle); dissector_add("tcp.port", global_mgcp_callagent_tcp_port, mgcp_handle); dissector_add("udp.port", global_mgcp_callagent_udp_port, mgcp_handle);}/* * is_mgcp_verb - A function for determining whether there is a * MGCP verb at offset in tvb * * Parameter: * tvb - The tvbuff in which we are looking for an MGCP verb * offset - The offset in tvb at which we are looking for a MGCP verb * maxlength - The maximum distance from offset we may look for the * characters that make up a MGCP verb. * * Return: TRUE if there is an MGCP verb at offset in tvb, otherwise FALSE */static gboolean is_mgcp_verb(tvbuff_t *tvb, gint offset, gint maxlength){ int returnvalue = FALSE; guint8 word[5]; if(( maxlength >= 4) && tvb_get_nstringz0(tvb,offset,4,word)){ if (strncasecmp(word, "EPCF", 4) == 0 || strncasecmp(word, "CRCX", 4) == 0 || strncasecmp(word, "MDCX", 4) == 0 || strncasecmp(word, "DLCX", 4) == 0 || strncasecmp(word, "RQNT", 4) == 0 || strncasecmp(word, "NTFY", 4) == 0 || strncasecmp(word, "AUEP", 4) == 0 || strncasecmp(word, "AUCX", 4) == 0 || strncasecmp(word, "RSIP", 4) == 0 || (word[0] == 'X' && is_rfc2234_alpha(word[1]) && is_rfc2234_alpha(word[2]) && is_rfc2234_alpha(word[3])) ){ returnvalue = TRUE; } } if( returnvalue && maxlength >= 5 && (word[0] = tvb_get_guint8(tvb,4)) != ' ' && word[0] != '\t'){ returnvalue = FALSE; } return returnvalue;}/* * is_mgcp_rspcode - A function for determining whether something which * looks roughly like a MGCP response code is at * offset in tvb * * Parameters: * tvb - The tvbuff in which we are looking for an MGCP response code * offset - The offset in tvb at which we are looking for a MGCP response code * maxlength - The maximum distance from offset we may look for the * characters that make up a MGCP response code. * * Return: TRUE if there is an MGCP response code at offset in tvb, * otherwise FALSE */static gboolean is_mgcp_rspcode(tvbuff_t *tvb, gint offset, gint maxlength){ int returnvalue = FALSE; guint8 word[4]; if(maxlength >= 3){ tvb_get_nstringz0(tvb,offset,3,word); if( isdigit(word[0]) && isdigit(word[1]) && isdigit(word[2])){ returnvalue = TRUE; } } if( returnvalue && maxlength >= 4 && (word[0] = tvb_get_guint8(tvb,3)) != ' ' && word[0] != '\t'){ returnvalue = FALSE; } return returnvalue;}/* * is_rfc2234_alpha - Indicates whether the character c is an alphabetical * character. This function is used instead of * isalpha because isalpha may deviate from the rfc2234 * definition of ALPHA in some locales. * * Parameter: * c - The character being checked for being an alphabetical character. * * Return: TRUE if c is an upper or lower case alphabetical character, * FALSE otherwise. */static gboolean is_rfc2234_alpha(guint8 c){ int returnvalue = FALSE; if(( c <= 'Z' && c >= 'A' ) || (c <= 'z' && c >= 'a')){ returnvalue = TRUE; } return returnvalue;} /* * tvb_parse_param - Parse the MGCP param into a type and a value. * * Parameters: * tvb - The tvbuff containing the MGCP param we are to parse. * offset - The offset in tvb at which we will begin looking for a * MGCP parameter to parse. * len - The maximum distance from offset in tvb that we can look for * an MGCP parameter to parse. * hf - The place to write a pointer to the integer representing the * header field associated with the MGCP parameter parsed. * * Returns: The offset in tvb where the value of the MGCP parameter * begins. */static gint tvb_parse_param(tvbuff_t* tvb, gint offset, gint len, int** hf){ gint returnvalue, tvb_current_offset,counter; guint8 tempchar; tvb_current_offset = offset; returnvalue = -1; *hf = NULL; if(len > 0){ tempchar = tvb_get_guint8(tvb,tvb_current_offset); switch(tempchar){ case 'K': *hf = &hf_mgcp_param_rspack; break; case 'B': *hf = &hf_mgcp_param_bearerinfo; break; case 'C': *hf = &hf_mgcp_param_callid; break; case 'I': tvb_current_offset++; if(len > (tvb_current_offset - offset) && (tempchar = tvb_get_guint8(tvb,tvb_current_offset)) == ':'){ *hf = &hf_mgcp_param_connectionid; tvb_current_offset--; } else if ( tempchar == '2'){ *hf = &hf_mgcp_param_secondconnectionid; } break; case 'N': *hf = &hf_mgcp_param_notifiedentity; break; case 'X': tvb_current_offset++; if(len > (tvb_current_offset - offset) && (tempchar = tvb_get_guint8(tvb,tvb_current_offset)) == ':'){ *hf = &hf_mgcp_param_requestid; } else if(len > (tvb_current_offset - offset) && ( (tempchar = tvb_get_guint8(tvb,tvb_current_offset)) == '-' || tempchar == '+')){ tvb_current_offset++; for(counter = 1;(counter <= 6) && (len > (counter + tvb_current_offset - offset)) && ( is_rfc2234_alpha(tempchar = tvb_get_guint8(tvb, tvb_current_offset+counter)) || isdigit(tempchar));counter++); if(tempchar == ':'){ tvb_current_offset += counter; *hf = &hf_mgcp_param_extention; } } tvb_current_offset--; break; case 'L': *hf = &hf_mgcp_param_localconnoptions; break; case 'M': *hf = &hf_mgcp_param_connectionmode; break; case 'R': tvb_current_offset++; if(len > (tvb_current_offset - offset) && (tempchar = tvb_get_guint8(tvb,tvb_current_offset)) == ':'){ *hf = &hf_mgcp_param_reqevents; tvb_current_offset--; } else if ( tempchar == 'M'){ *hf = &hf_mgcp_param_restartmethod; } else if ( tempchar == 'D'){ *hf = &hf_mgcp_param_restartdelay; } break; case 'S': *hf = &hf_mgcp_param_signalreq; break; case 'D': *hf = &hf_mgcp_param_digitmap; break; case 'O': *hf = &hf_mgcp_param_observedevent; break; case 'P': *hf = &hf_mgcp_param_connectionparam; break; case 'E': tvb_current_offset++; if(len > (tvb_current_offset - offset) && (tempchar = tvb_get_guint8(tvb,tvb_current_offset)) == ':'){ *hf = &hf_mgcp_param_reasoncode; tvb_current_offset--; } else if ( tempchar == 'S'){ *hf = &hf_mgcp_param_eventstates; } break; case 'Z': tvb_current_offset++; if(len > (tvb_current_offset - offset) && (tempchar = tvb_get_guint8(tvb,tvb_current_offset)) == ':'){ *hf = &hf_mgcp_param_specificendpoint; tvb_current_offset--; } else if ( tempchar == '2'){ *hf = &hf_mgcp_param_secondendpointid; } break; case 'F': *hf = &hf_mgcp_param_reqinfo; break; case 'Q': *hf = &hf_mgcp_param_quarantinehandling; break; case 'T': *hf = &hf_mgcp_param_detectedevents; break; case 'A': *hf = &hf_mgcp_param_capabilities; break; default: *hf = &hf_mgcp_param_invalid; break; } tvb_current_offset++; if(*hf != NULL && len > (tvb_current_offset - offset) && (tempchar = tvb_get_guint8(tvb,tvb_current_offset)) == ':'){ tvb_current_offset++; tvb_current_offset = tvb_skip_wsp(tvb,tvb_current_offset, (len - tvb_current_offset + offset)); returnvalue = tvb_current_offset; } else { *hf = &hf_mgcp_param_invalid; } }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -