📄 packet-mgcp.c
字号:
else{ *hf = &hf_mgcp_param_invalid; } if(*hf == &hf_mgcp_param_invalid){ returnvalue = offset; } return returnvalue;}/* * dissect_mgcp_firstline - Dissects the firstline of an MGCP message. * Adds the appropriate headers fields to * tree for the dissection of the first line * of an MGCP message. * * Parameters: * tvb - The tvb containing the first line of an MGCP message. This * tvb is presumed to ONLY contain the first line of the MGCP * message. * pinfo - The packet info for the packet. This is not really used * by this function but is passed through so as to retain the * style of a dissector. * tree - The tree from which to hang the structured information parsed * from the first line of the MGCP message. */static void dissect_mgcp_firstline(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree){ gint tvb_current_offset,tvb_previous_offset,tvb_len,tvb_current_len; gint tokennum, tokenlen; mgcp_type_t mgcp_type = MGCP_OTHERS; proto_item* (*my_proto_tree_add_string)(proto_tree*, int, tvbuff_t*, gint, gint, const char*); tvb_previous_offset = 0; tvb_len = tvb_length(tvb); tvb_current_len = tvb_len; tvb_current_offset = tvb_previous_offset; if(tree){ tokennum = 0; if(global_mgcp_dissect_tree){ my_proto_tree_add_string = proto_tree_add_string; } else{ my_proto_tree_add_string = proto_tree_add_string_hidden; } do { tvb_current_len = tvb_length_remaining(tvb,tvb_previous_offset); tvb_current_offset = tvb_find_guint8(tvb, tvb_previous_offset, tvb_current_len, ' '); if(tvb_current_offset == -1){ tvb_current_offset = tvb_len; tokenlen = tvb_current_len; } else{ tokenlen = tvb_current_offset - tvb_previous_offset; } if(tokennum == 0){ if(is_mgcp_verb(tvb,tvb_previous_offset,tvb_current_len)){ mgcp_type = MGCP_REQUEST; my_proto_tree_add_string(tree,hf_mgcp_req_verb, tvb, tvb_previous_offset, tokenlen, tvb_format_text(tvb,tvb_previous_offset ,tokenlen)); } else if (is_mgcp_rspcode(tvb,tvb_previous_offset,tvb_current_len)){ mgcp_type = MGCP_RESPONSE; my_proto_tree_add_string(tree,hf_mgcp_rsp_rspcode, tvb, tvb_previous_offset, tokenlen, tvb_format_text(tvb,tvb_previous_offset ,tokenlen)); } else { break; } } if(tokennum == 1){ my_proto_tree_add_string(tree,hf_mgcp_transid, tvb, tvb_previous_offset, tokenlen, tvb_format_text(tvb,tvb_previous_offset, tokenlen)); } if(tokennum == 2){ if(mgcp_type == MGCP_REQUEST){ my_proto_tree_add_string(tree,hf_mgcp_req_endpoint, tvb, tvb_previous_offset, tokenlen, tvb_format_text(tvb, tvb_previous_offset, tokenlen)); } else if(mgcp_type == MGCP_RESPONSE){ if(tvb_current_offset < tvb_len){ tokenlen = tvb_find_line_end(tvb, tvb_previous_offset, -1,&tvb_current_offset); } else{ tokenlen = tvb_current_len; } my_proto_tree_add_string(tree, hf_mgcp_rsp_rspstring, tvb, tvb_previous_offset, tokenlen, tvb_format_text(tvb, tvb_previous_offset, tokenlen)); break; } } if( (tokennum == 3 && mgcp_type == MGCP_REQUEST) ){ if(tvb_current_offset < tvb_len ){ tokenlen = tvb_find_line_end(tvb, tvb_previous_offset, -1,&tvb_current_offset); } else{ tokenlen = tvb_current_len; } my_proto_tree_add_string(tree,hf_mgcp_version, tvb, tvb_previous_offset, tokenlen, tvb_format_text(tvb,tvb_previous_offset, tokenlen)); break; } if(tvb_current_offset < tvb_len){ tvb_previous_offset = tvb_skip_wsp(tvb, tvb_current_offset, tvb_current_len); } tokennum++; } while( tvb_current_offset < tvb_len && tvb_previous_offset < tvb_len && tokennum <= 3); switch (mgcp_type){ case MGCP_RESPONSE: proto_tree_add_boolean_hidden(tree, hf_mgcp_rsp, tvb, 0, 0, TRUE); break; case MGCP_REQUEST: proto_tree_add_boolean_hidden(tree, hf_mgcp_req, tvb, 0, 0, TRUE); break; default: break; } }}/* * dissect_mgcp_params - Dissects the parameters of an MGCP message. * Adds the appropriate headers fields to * tree for the dissection of the parameters * of an MGCP message. * * Parameters: * tvb - The tvb containing the parameters of an MGCP message. This * tvb is presumed to ONLY contain the part of the MGCP * message which contains the MGCP parameters. * pinfo - The packet info for the packet. This is not really used * by this function but is passed through so as to retain the * style of a dissector. * tree - The tree from which to hang the structured information parsed * from the parameters of the MGCP message. */static void dissect_mgcp_params(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree){ int linelen, tokenlen, *my_param; gint tvb_lineend,tvb_current_len, tvb_linebegin,tvb_len; gint tvb_tokenbegin; proto_tree *mgcp_param_ti, *mgcp_param_tree; proto_item* (*my_proto_tree_add_string)(proto_tree*, int, tvbuff_t*, gint, gint, const char*); tvb_len = tvb_length(tvb); tvb_linebegin = 0; tvb_current_len = tvb_length_remaining(tvb,tvb_linebegin); tvb_lineend = tvb_linebegin; if(tree){ if(global_mgcp_dissect_tree){ my_proto_tree_add_string = proto_tree_add_string; mgcp_param_ti = proto_tree_add_item(tree, proto_mgcp, tvb, tvb_linebegin, tvb_len, FALSE); proto_item_set_text(mgcp_param_ti, "Parameters"); mgcp_param_tree = proto_item_add_subtree(mgcp_param_ti, ett_mgcp_param); } else{ my_proto_tree_add_string = proto_tree_add_string_hidden; mgcp_param_tree = tree; mgcp_param_ti = NULL; } /* Parse the parameters */ while(tvb_lineend < tvb_len){ linelen = tvb_find_line_end(tvb, tvb_linebegin, -1,&tvb_lineend); tvb_tokenbegin = tvb_parse_param(tvb, tvb_linebegin, linelen, &my_param); if( my_param != NULL ){ tokenlen = tvb_find_line_end(tvb,tvb_tokenbegin,-1,&tvb_lineend); my_proto_tree_add_string(mgcp_param_tree,*my_param, tvb, tvb_linebegin, linelen, tvb_format_text(tvb,tvb_tokenbegin, tokenlen)); } tvb_linebegin = tvb_lineend; } }} /* * tvb_skip_wsp - Returns the position in tvb of the first non-whitespace * character following offset or offset + maxlength -1 whichever * is smaller. * * Parameters: * tvb - The tvbuff in which we are skipping whitespace. * offset - The offset in tvb from which we begin trying to skip whitespace. * maxlength - The maximum distance from offset that we may try to skip * whitespace. * * Returns: The position in tvb of the first non-whitespace * character following offset or offset + maxlength -1 whichever * is smaller. */static gint tvb_skip_wsp(tvbuff_t* tvb, gint offset, gint maxlength){ gint counter = offset; gint end = offset + maxlength,tvb_len; guint8 tempchar; tvb_len = tvb_length(tvb); end = offset + maxlength; if(end >= tvb_len){ end = tvb_len; } for(counter = offset; counter < end && ((tempchar = tvb_get_guint8(tvb,counter)) == ' ' || tempchar == '\t');counter++); return (counter);}/* * tvb_find_null_line - Returns the length from offset to the first null * line found (a null line is a line that begins * with a CR or LF. The offset to the first character * after the null line is written into the gint pointed * to by next_offset. * * Parameters: * tvb - The tvbuff in which we are looking for a null line. * offset - The offset in tvb at which we will begin looking for * a null line. * len - The maximum distance from offset in tvb that we will look for * a null line. If it is -1 we will look to the end of the buffer. * * next_offset - The location to write the offset of first character * FOLLOWING the null line. * * Returns: The length from offset to the first character BEFORE * the null line.. */static gint tvb_find_null_line(tvbuff_t* tvb, gint offset, gint len, gint* next_offset){ gint tvb_lineend,tvb_current_len,tvb_linebegin,maxoffset; guint tempchar; tvb_linebegin = offset; tvb_lineend = tvb_linebegin; /* Simple setup to allow for the traditional -1 search to the end * of the tvbuff */ if(len != -1){ tvb_current_len = len; } else{ tvb_current_len = tvb_length_remaining(tvb,offset); } maxoffset = (tvb_current_len - 1) + offset; /* * Loop around until we either find a line begining with a carriage return * or newline character or until we hit the end of the tvbuff. */ do { tvb_linebegin = tvb_lineend; tvb_current_len = tvb_length_remaining(tvb,tvb_linebegin); tvb_find_line_end(tvb, tvb_linebegin, tvb_current_len, &tvb_lineend); tempchar = tvb_get_guint8(tvb,tvb_linebegin); } while( tempchar != '\r' && tempchar != '\n' && tvb_lineend <= maxoffset); *next_offset = tvb_lineend; if( tvb_lineend <= maxoffset ) { tvb_current_len = tvb_linebegin - offset; } else { tvb_current_len = tvb_length_remaining(tvb,offset); } return (tvb_current_len);}/* * tvb_find_dot_line - Returns the length from offset to the first line * containing only a dot (.) character. A line * containing only a dot is used to indicate a * separation between multiple MGCP messages * piggybacked in the same UDP packet. * * Parameters: * tvb - The tvbuff in which we are looking for a dot line. * offset - The offset in tvb at which we will begin looking for * a dot line. * len - The maximum distance from offset in tvb that we will look for * a dot line. If it is -1 we will look to the end of the buffer. * * next_offset - The location to write the offset of first character * FOLLOWING the dot line. * * Returns: The length from offset to the first character BEFORE * the dot line or -1 if the character at offset is a . * followed by a newline or a carriage return. */static gint tvb_find_dot_line(tvbuff_t* tvb, gint offset, gint len, gint* next_offset){ gint tvb_current_offset, tvb_current_len, maxoffset,tvb_len; guint8 tempchar; tvb_current_offset = offset; tvb_current_len = len; tvb_len = tvb_length(tvb); if(len == -1){ maxoffset = ( tvb_len - 1 ); } else { maxoffset = (len - 1 ) + offset; } tvb_current_offset = offset -1; do { tvb_current_offset = tvb_find_guint8(tvb, tvb_current_offset+1, tvb_current_len, '.'); tvb_current_len = maxoffset - tvb_current_offset + 1; /* * if we didn't find a . then break out of the loop */ if(tvb_current_offset == -1){ break; } /* do we have and characters following the . ? */ if( tvb_current_offset < maxoffset ) { tempchar = tvb_get_guint8(tvb,tvb_current_offset+1); /* * are the characters that follow the dot a newline or carriage return ? */ if(tempchar == '\r' || tempchar == '\n'){ /* * do we have any charaters that proceed the . ? */ if( tvb_current_offset == 0 ){ break; } else { tempchar = tvb_get_guint8(tvb,tvb_current_offset-1); /* * are the characters that follow the dot a newline or a carriage * return ? */ if(tempchar == '\r' || tempchar == '\n'){ break; } } } } else if ( tvb_current_offset == maxoffset ) { if( tvb_current_offset == 0 ){ break; } else { tempchar = tvb_get_guint8(tvb,tvb_current_offset-1); if(tempchar == '\r' || tempchar == '\n'){ break; } } } } while (tvb_current_offset < maxoffset); /* * so now we either have the tvb_current_offset of a . in a dot line * or a tvb_current_offset of -1 */ if(tvb_current_offset == -1){ tvb_current_offset = maxoffset +1; *next_offset = maxoffset + 1; } else { tvb_find_line_end(tvb,tvb_current_offset,tvb_current_len,next_offset); } if( tvb_current_offset == offset ){ tvb_current_len = -1; } else { tvb_current_len = tvb_current_offset - offset; } return tvb_current_len; }/* Start the functions we need for the plugin stuff */#ifndef __ETHEREAL_STATIC__G_MODULE_EXPORT voidplugin_reg_handoff(void){ proto_reg_handoff_mgcp();}G_MODULE_EXPORT voidplugin_init(plugin_address_table_t *pat){ /* initialise the table of pointers needed in Win32 DLLs */ plugin_address_table_init(pat); /* register the new protocol, protocol fields, and subtrees */ if (proto_mgcp == -1) { /* execute protocol initialization only once */ proto_register_mgcp(); }}#endif/* End the functions we need for plugin stuff */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -