packet-gryphon.c
来自「ethereal公司开发的aodv路由协议代码」· C语言 代码 · 共 1,897 行 · 第 1/5 页
C
1,897 行
return offset;}static intcmd_sched(tvbuff_t *tvb, int offset, int src, int msglen, proto_tree *pt){ proto_item *item, *item1; proto_tree *tree, *tree1; int save_offset; unsigned int i, x, length; unsigned char def_chan = tvb_get_guint8(tvb, offset-9); char *ptr; char crit[] = ".... ...1 = Critical scheduler"; char norm[] = ".... ...0 = Normal scheduler"; x = tvb_get_ntohl(tvb, offset); if (x == 0xFFFFFFFF) proto_tree_add_text(pt, tvb, offset, 4, "Number of iterations: infinite"); else proto_tree_add_text(pt, tvb, offset, 4, "Number of iterations: %d", x); offset += 4; msglen -= 4; x = tvb_get_ntohl(tvb, offset); item = proto_tree_add_text(pt, tvb, offset, 4, "Flags"); tree = proto_item_add_subtree (item, ett_gryphon_flags); ptr = x & 1 ? crit : norm; proto_tree_add_text(tree, tvb, offset, 4, ptr, NULL); offset += 4; msglen -= 4; i = 1; while (msglen > 0) { length = 16 + tvb_get_guint8(tvb, offset+16) + tvb_get_ntohs(tvb, offset+18) + tvb_get_guint8(tvb, offset+20) + 16; length += 3 - (length + 3) % 4; item = proto_tree_add_text(pt, tvb, offset, length, "Message %d", i); tree = proto_item_add_subtree (item, ett_gryphon_cmd_sched_data); x = tvb_get_ntohl(tvb, offset); proto_tree_add_text(tree, tvb, offset, 4, "Sleep: %d milliseconds", x); offset += 4; msglen -= 4; x = tvb_get_ntohl(tvb, offset); proto_tree_add_text(tree, tvb, offset, 4, "Transmit count: %d", x); offset += 4; msglen -= 4; x = tvb_get_ntohl(tvb, offset); proto_tree_add_text(tree, tvb, offset, 4, "Transmit period: %d milliseconds", x); offset += 4; msglen -= 4; proto_tree_add_text(tree, tvb, offset, 2, "reserved flags"); x = tvb_get_guint8(tvb, offset+2); if (x == 0) x = def_chan; proto_tree_add_text(tree, tvb, offset+2, 1, "Channel: %d", x); proto_tree_add_text(tree, tvb, offset+3, 1, "reserved"); offset += 4; msglen -= 4; item1 = proto_tree_add_text(tree, tvb, offset, length, "Message"); tree1 = proto_item_add_subtree (item1, ett_gryphon_cmd_sched_cmd); save_offset = offset; offset = decode_data(tvb, offset, msglen, src, tree1); msglen -= offset - save_offset; i++; } return offset;}static intresp_blm_data(tvbuff_t *tvb, int offset, int src, int msglen, proto_tree *pt){ unsigned int i; int hours, minutes, seconds, fraction, x, fract; unsigned long timestamp; char *fields[] = { "Bus load average: %d.%02d%%", "Current bus load: %d.%02d%%", "Peak bus load: %d.%02d%%", "Historic peak bus load: %d.%02d%%" }; timestamp = tvb_get_ntohl(tvb, offset); hours = timestamp /(100000 * 60 *60); minutes = (timestamp / (100000 * 60)) % 60; seconds = (timestamp / 100000) % 60; fraction = timestamp % 100000; proto_tree_add_text(pt, tvb, offset, 4, "Timestamp: %d:%02d:%02d.%05d", hours, minutes, seconds, fraction); offset += 4; for (i = 0; i < SIZEOF(fields); i++){ x = tvb_get_ntohs(tvb, offset); fract = x % 100; x /= 100; proto_tree_add_text(pt, tvb, offset, 2, fields[i], x, fract); offset += 2; } return offset;}static intresp_blm_stat(tvbuff_t *tvb, int offset, int src, int msglen, proto_tree *pt){ unsigned int x, i; char *fields[] = { "Receive frame count: %d", "Transmit frame count: %d", "Receive dropped frame count: %d", "Transmit dropped frame count: %d", "Receive error count: %d", "Transmit error count: %d", }; offset = resp_blm_data(tvb, offset, src, msglen, pt); for (i = 0; i < SIZEOF(fields); i++){ x = tvb_get_ntohl(tvb, offset); proto_tree_add_text(pt, tvb, offset, 4, fields[i], x); offset += 4; } return offset;}static intcmd_addresp(tvbuff_t *tvb, int offset, int src, int msglen, proto_tree *pt){ proto_item *item; proto_tree *tree; int blocks, responses, old_handle, i, length; int action, actionType, actionValue; char *ptr; char active[] = ".... ..1. = The response is active"; char inactive[] = ".... ..0. = The response is inactive"; actionType = 0; item = proto_tree_add_text(pt, tvb, offset, 1, "Flags"); tree = proto_item_add_subtree (item, ett_gryphon_flags); if (tvb_get_guint8(tvb, offset) & FILTER_ACTIVE_FLAG) ptr = active; else ptr = inactive; proto_tree_add_text(tree, tvb, offset, 1, ptr, NULL); offset += 1; blocks = tvb_get_guint8(tvb, offset); proto_tree_add_text(pt, tvb, offset, 1, "Number of filter blocks = %d", blocks); offset += 1; responses = tvb_get_guint8(tvb, offset); proto_tree_add_text(pt, tvb, offset, 1, "Number of response blocks = %d", responses); offset += 1; old_handle = tvb_get_guint8(tvb, offset); proto_tree_add_text(pt, tvb, offset, 1, "Old handle = %d", old_handle); offset += 1; action = tvb_get_guint8(tvb, offset); switch (action & 7) { case FR_RESP_AFTER_EVENT: ptr = "Send response(s) for each conforming message"; break; case FR_RESP_AFTER_PERIOD: ptr = "Send response(s) after the specified period expires following a conforming message"; break; case FR_IGNORE_DURING_PER: ptr = "Send response(s) for a conforming message and ignore\nfurther messages until the specified period expires"; break; default: ptr = "- unknown -"; } item = proto_tree_add_text(pt, tvb, offset, 1, "Action = %s", ptr); tree = proto_item_add_subtree (item, ett_gryphon_flags); if (action & FR_DEACT_AFTER_PER && !(action & FR_DELETE)){ proto_tree_add_text(tree, tvb, offset, 1, "1.0. .... Deactivate this response after the specified period following a conforming message"); } if (action & FR_DEACT_ON_EVENT && !(action & FR_DELETE)){ proto_tree_add_text(tree, tvb, offset, 1, ".10. .... Deactivate this response for a conforming message"); } if (action & FR_DEACT_AFTER_PER && action & FR_DELETE){ proto_tree_add_text(tree, tvb, offset, 1, "1.1. .... Delete this response after the specified period following a conforming message"); } if (action & FR_DEACT_ON_EVENT && action & FR_DELETE){ proto_tree_add_text(tree, tvb, offset, 1, ".11. .... Delete this response for a conforming message"); } actionValue = tvb_get_ntohs(tvb, offset+2); if (actionValue) { if (action & FR_PERIOD_MSGS){ ptr = "...1 .... The period is in frames"; actionType = 1; } else { ptr = "...0 .... The period is in 0.01 seconds"; actionType = 0; } proto_tree_add_text(tree, tvb, offset, 1, ptr, NULL); } offset += 1; proto_tree_add_text(pt, tvb, offset, 1, "reserved"); offset += 1; if (actionValue) { if (actionType == 1) { proto_tree_add_text(tree, tvb, offset, 2, "Period: %d messages", actionValue); } else { proto_tree_add_text(tree, tvb, offset, 2, "Period: %d.%02d seconds", actionValue/100, actionValue%100); } } offset += 2; for (i = 1; i <= blocks; i++) { length = tvb_get_ntohs(tvb, offset+2) * 2 + 8; length += 3 - (length + 3) % 4; item = proto_tree_add_text(pt, tvb, offset, length, "Filter block %d", i); tree = proto_item_add_subtree (item, ett_gryphon_cmd_filter_block); offset = filter_block(tvb, offset, src, msglen, tree); } for (i = 1; i <= responses; i++) { length = tvb_get_ntohs(tvb, offset+4) + 8; length += 3 - (length + 3) % 4; item = proto_tree_add_text(pt, tvb, offset, length, "Response block %d", i); tree = proto_item_add_subtree (item, ett_gryphon_cmd_response_block); dissect_gryphon_message(tvb, offset, tree, TRUE); offset += length; } return offset;}static intresp_addresp(tvbuff_t *tvb, int offset, int src, int msglen, proto_tree *pt){ proto_tree_add_text(pt, tvb, offset, 1, "Response handle: %u", tvb_get_guint8(tvb, offset)); proto_tree_add_text(pt, tvb, offset+1, 3, "reserved"); offset += 4; return offset;}static intcmd_modresp(tvbuff_t *tvb, int offset, int src, int msglen, proto_tree *pt){ unsigned char action; unsigned char dest = tvb_get_guint8(tvb, offset-5); guint8 resp_handle; unsigned int i; resp_handle = tvb_get_guint8(tvb, offset); if (resp_handle) proto_tree_add_text(pt, tvb, offset, 1, "Response handle: %u", resp_handle); else if (dest) proto_tree_add_text(pt, tvb, offset, 1, "Response handles: all on channel %hd", dest); else proto_tree_add_text(pt, tvb, offset, 1, "Response handles: all"); action = tvb_get_guint8(tvb, offset+1); for (i = 0; i < SIZEOF(filtacts); i++) { if (filtacts[i].value == action) break; } if (i >= SIZEOF(filtacts)) i = SIZEOF(filtacts) - 1; proto_tree_add_text(pt, tvb, offset+1, 1, "Action: %s response", filtacts[i].strptr); proto_tree_add_text(pt, tvb, offset+2, 2, "reserved"); offset += 4; return offset;}static intresp_resphan(tvbuff_t *tvb, int offset, int src, int msglen, proto_tree *pt){ int handles = tvb_get_guint8(tvb, offset); int i, padding; proto_tree_add_text(pt, tvb, offset, 1, "Number of response handles: %d", handles); for (i = 1; i <= handles; i++){ proto_tree_add_text(pt, tvb, offset+i, 1, "Handle %d: %u", i, tvb_get_guint8(tvb, offset+i)); } padding = 3 - (handles + 1 + 3) % 4; if (padding) proto_tree_add_text(pt, tvb, offset+1+handles, padding, "padding"); offset += 1+handles+padding; return offset;}static intresp_sched(tvbuff_t *tvb, int offset, int src, int msglen, proto_tree *pt){ unsigned int id = tvb_get_ntohl(tvb, offset); proto_tree_add_text(pt, tvb, offset, 4, "Transmit schedule ID: %u", id); offset += 4; return offset;}static intcmd_desc(tvbuff_t *tvb, int offset, int src, int msglen, proto_tree *pt){ proto_tree_add_text(pt, tvb, offset, 4, "Program size: %u bytes", tvb_get_ntohl(tvb, offset)); offset += 4; proto_tree_add_text(pt, tvb, offset, 32, "Program name: %.32s", tvb_get_ptr(tvb, offset, 32)); offset += 32; proto_tree_add_text(pt, tvb, offset, 80, "Program description: %.80s", tvb_get_ptr(tvb, offset, 80)); offset += 80; return offset;}static intresp_desc(tvbuff_t *tvb, int offset, int src, int msglen, proto_tree *pt){ proto_item *item; proto_tree *tree; char *ptr; char missing[] = ".... ...0 = The program is not present"; char present[] = ".... ...1 = The program is already present"; item = proto_tree_add_text(pt, tvb, offset, 1, "Flags"); tree = proto_item_add_subtree (item, ett_gryphon_flags); if (tvb_get_guint8(tvb, offset) & 1) ptr = present; else ptr = missing; proto_tree_add_text(tree, tvb, offset, 1, ptr); proto_tree_add_text(pt, tvb, offset+1, 1, "Handle: %u", tvb_get_guint8(tvb, offset+1)); proto_tree_add_text(pt, tvb, offset+2, 2, "reserved"); offset += 4; return offset;}static intcmd_upload(tvbuff_t *tvb, int offset, int src, int msglen, proto_tree *pt){ unsigned int length; proto_tree_add_text(pt, tvb, offset, 2, "Block number: %u", tvb_get_ntohs(tvb, offset)); offset += 4; msglen -= 4; proto_tree_add_text(pt, tvb, offset+2, 1, "Handle: %u", tvb_get_guint8(tvb, offset+2)); offset += 3; msglen -= 3; length = msglen; proto_tree_add_text(pt, tvb, offset, length, "Data (%d bytes)", length); offset += length; length = 3 - (length + 3) % 4; if (length) { proto_tree_add_text(pt, tvb, offset, length, "padding"); offset += length; } return offset;}static intcmd_delete(tvbuff_t *tvb, int offset, int src, int msglen, proto_tree *pt){ proto_tree_add_text(pt, tvb, offset, 32, "Program name: %.32s", tvb_get_ptr(tvb, offset, 32)); offset += 32; return offset;}static intcmd_list(tvbuff_t *tvb, int offset, int src, int msglen, proto_tree *pt){ proto_tree_add_text(pt, tvb, offset, 1, "Block number: %u", tvb_get_guint8(tvb, offset)); proto_tree_add_text(pt, tvb, offset+1, 3, "reserved"); offset += 4; return offset;}static intresp_list(tvbuff_t *tvb, int offset, int src, int msglen, proto_tree *pt){ proto_item *item; proto_tree *tree; unsigned int i, count; count = tvb_get_guint8(tvb, offset); proto_tree_add_text(pt, tvb, offset, 1, "Number of programs in this response: %d", count); proto_tree_add_text(pt, tvb, offset+1, 1, "reserved"); offset += 2; proto_tree_add_text(pt, tvb, offset, 2, "Number of remaining programs: %u", tvb_get_ntohs(tvb, offset));
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?