⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 packet-gryphon.c

📁 ethereal公司开发的aodv路由协议代码
💻 C
📖 第 1 页 / 共 5 页
字号:
{    int     hours, minutes, seconds, fraction;    union {    	unsigned int		lng[2];	guint64			lnglng;    } ts;    unsigned int    timestamp;    unsigned char   date[45];       ts.lng[1] = tvb_get_ntohl(tvb, offset);    ts.lng[0] = tvb_get_ntohl(tvb, offset + 4);    timestamp = ts.lnglng / 100000L;    strncpy (date, ctime((time_t*)&timestamp), sizeof(date));    date[strlen(date)-1] = 0x00;    proto_tree_add_text(pt, tvb, offset, 8, "Date/Time: %s", date);    timestamp = ts.lng[0];    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, 4, "Timestamp: %d:%02d:%02d.%05d", hours, minutes, seconds, fraction);    offset += 8;    return offset;}static intcmd_setfilt(tvbuff_t *tvb, int offset, int src, int msglen, proto_tree *pt){    int     	    flag = tvb_get_ntohl(tvb, offset);    int     	    length, padding;    unsigned char   mode[30];        length =  tvb_get_guint8(tvb, offset+4) + tvb_get_guint8(tvb, offset+5)	+ tvb_get_ntohs(tvb, offset+6);    if (flag)    	strcpy (mode, "Pass");    else    	strcpy (mode, "Block");    if (length == 0)    	strcat (mode, " all");    proto_tree_add_text(pt, tvb, offset, 4, "Pass/Block flag: %s", mode);    proto_tree_add_text(pt, tvb, offset+4, 4, "Length of Pattern & Mask: %d", length);    offset += 8;    if (length) {	proto_tree_add_text(pt, tvb, offset, length * 2, "discarded data");	offset += length * 2;    }    padding = 3 - (length * 2 + 3) % 4;    if (padding) {	proto_tree_add_text(pt, tvb, offset+1, 3, "padding");	offset += padding;    }    return offset;}static intcmd_ioctl(tvbuff_t *tvb, int offset, int src, int msglen, proto_tree *pt){    unsigned int    ioctl, i;    ioctl = tvb_get_ntohl(tvb, offset);    for (i = 0; i < SIZEOF(ioctls); i++) {	if (ioctls[i].value == ioctl)	    break;    }    if (i >= SIZEOF(ioctls))	i = SIZEOF(ioctls) - 1;    proto_tree_add_text(pt, tvb, offset, 4, "IOCTL: %s", ioctls[i].strptr);    offset += 4;    msglen -= 4;    if (msglen > 0) {	proto_tree_add_text(pt, tvb, offset, msglen, "Data");	offset += msglen;    }    return offset;}static intcmd_addfilt(tvbuff_t *tvb, int offset, int src, int msglen, proto_tree *pt){    proto_item	*item;    proto_tree	*tree;    guint8	flags;    int     	blocks, i, length;    char    	*ptr;    char    	pass[] = ".... ...1 = Conforming messages are passed";    char    	block[] = ".... ...0 = Conforming messages are blocked";    char    	active[] = ".... ..1. = The filter is active";    char    	inactive[] = ".... ..0. = The filter is inactive";    item = proto_tree_add_text(pt, tvb, offset, 1, "Flags");    tree = proto_item_add_subtree (item, ett_gryphon_flags);    flags = tvb_get_guint8(tvb, offset);    if (flags & FILTER_PASS_FLAG)	ptr = pass;    else	ptr = block;    proto_tree_add_text(tree, tvb, offset, 1, ptr);    if (flags & FILTER_ACTIVE_FLAG)	ptr = active;    else	ptr = inactive;    proto_tree_add_text(tree, tvb, offset, 1, ptr);    offset += 1;    msglen -= 1;    blocks = tvb_get_guint8(tvb, offset);    proto_tree_add_text(pt, tvb, offset, 1, "Number of filter blocks = %d", blocks);    proto_tree_add_text(pt, tvb, offset+1, 6, "reserved");    offset += 7;    msglen -= 7;    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);    }    return offset;}static intresp_addfilt(tvbuff_t *tvb, int offset, int src, int msglen, proto_tree *pt){    proto_tree_add_text(pt, tvb, offset, 1, "Filter handle: %u",	tvb_get_guint8(tvb, offset));    proto_tree_add_text(pt, tvb, offset+1, 3, "reserved");    offset += 4;    return offset;}static intcmd_modfilt(tvbuff_t *tvb, int offset, int src, int msglen, proto_tree *pt){    guint8	    filter_handle;    unsigned char   action, i;    filter_handle = tvb_get_guint8(tvb, offset);    if (filter_handle)    	proto_tree_add_text(pt, tvb, offset, 1, "Filter handle: %u",	    filter_handle);    else    	proto_tree_add_text(pt, tvb, offset, 1, "Filter 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 filter", filtacts[i].strptr);    proto_tree_add_text(pt, tvb, offset+2, 2, "reserved");    offset += 4;    return offset;}static intresp_filthan(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 filter 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 intdfiltmode(tvbuff_t *tvb, int offset, int src, int msglen, proto_tree *pt){    unsigned int    i;    unsigned char   mode;        mode = tvb_get_guint8(tvb, offset);    for (i = 0; i < SIZEOF(modes); i++) {	if (dmodes[i].value == mode)	    break;    }    if (i >= SIZEOF(dmodes))	i = SIZEOF(dmodes) - 1;    proto_tree_add_text(pt, tvb, offset, 1, "Filter mode: %s", dmodes[i].strptr);    proto_tree_add_text(pt, tvb, offset+1, 3, "reserved");    offset += 4;    return offset;}static intfiltmode(tvbuff_t *tvb, int offset, int src, int msglen, proto_tree *pt){    unsigned int    i;    unsigned char   mode;        mode = tvb_get_guint8(tvb, offset);    for (i = 0; i < SIZEOF(modes); i++) {	if (modes[i].value == mode)	    break;    }    if (i >= SIZEOF(modes))	i = SIZEOF(modes) - 1;    proto_tree_add_text(pt, tvb, offset, 1, "Filter mode: %s", modes[i].strptr);    proto_tree_add_text(pt, tvb, offset+1, 3, "reserved");    offset += 4;    return offset;}static intresp_events(tvbuff_t *tvb, int offset, int src, int msglen, proto_tree *pt){    unsigned int    i;    proto_tree	    *tree;    proto_item	    *item;        i = 1;    while (msglen != 0) {	item = proto_tree_add_text(pt, tvb, offset, 20, "Event %d:", i);	tree = proto_item_add_subtree (item, ett_gryphon_cmd_events_data);	proto_tree_add_text(tree, tvb, offset, 1, "Event ID: %u",	    tvb_get_guint8(tvb, offset));	proto_tree_add_text(tree, tvb, offset+1, 19, "Event name: %.19s",		tvb_get_ptr(tvb, offset+1, 19));	offset += 20;	msglen -= 20;	i++;    }    return offset;}static intcmd_register(tvbuff_t *tvb, int offset, int src, int msglen, proto_tree *pt){    proto_tree_add_text(pt, tvb, offset, 16, "Username: %.16s",	tvb_get_ptr(tvb, offset, 16));    offset += 16;    proto_tree_add_text(pt, tvb, offset, 32, "Password: %.32s",	tvb_get_ptr(tvb, offset, 32));    offset += 32;    return offset;}static intresp_register(tvbuff_t *tvb, int offset, int src, int msglen, proto_tree *pt){    proto_tree_add_text(pt, tvb, offset, 1, "Client ID: %u",	tvb_get_guint8(tvb, offset));    proto_tree_add_text(pt, tvb, offset+1, 1, "Privileges: %u",	tvb_get_guint8(tvb, offset+1));    proto_tree_add_text(pt, tvb, offset+2, 2, "reserved");    offset += 4;    return offset;}static intresp_getspeeds(tvbuff_t *tvb, int offset, int src, int msglen, proto_tree *pt){    int size;    int number;    int index;        proto_tree_add_text(pt, tvb, offset, 4, "Set Speed IOCTL");    proto_tree_add_text(pt, tvb, offset+4, 4, "Get Speed IOCTL");    size = tvb_get_guint8(tvb, offset+8);    proto_tree_add_text(pt, tvb, offset+8, 1, "Speed data size is %d bytes", size);    number = tvb_get_guint8(tvb, offset+9);    proto_tree_add_text(pt, tvb, offset+9, 1, "There are %d preset speeds", number);    offset += 10;    for (index = 0; index < number; index++) {	proto_tree_add_text(pt, tvb, offset, size, "Data for preset %d",	    index+1);	offset += size;    }    return offset;}static intcmd_sort(tvbuff_t *tvb, int offset, int src, int msglen, proto_tree *pt){    char    	*which;        which = tvb_get_guint8(tvb, offset) ?	    "Sort into blocks of up to 16 messages" :	    "Do not sort messages";    proto_tree_add_text(pt, tvb, offset, 1, "Set sorting: %s", which);    offset += 1;    return offset;}static intcmd_optimize(tvbuff_t *tvb, int offset, int src, int msglen, proto_tree *pt){    char    	*which;        which = tvb_get_guint8(tvb, offset) ? 	    "Optimize for latency (Nagle algorithm disabled)" :	    "Optimize for throughput (Nagle algorithm enabled)";    proto_tree_add_text(pt, tvb, offset, 1, "Set optimization: %s", which);    offset += 1;    return offset;}static intresp_config(tvbuff_t *tvb, int offset, int src, int msglen, proto_tree *pt){    proto_item	*ti;    proto_tree	*ft;    int     	devices;    int     	i;    unsigned int j, x;        static const value_string protocol_types[] = {	{GDUMMY * 256 + GDGDMARKONE,	"Dummy device driver"},	{GCAN * 256 + G82527,	    	"CAN, 82527 subtype"},	{GCAN * 256 + GSJA1000,     	"CAN, SJA1000 subtype"},	{GCAN * 256 + G82527SW,     	"CAN, 82527 single wire subtype"},	{GJ1850 * 256 + GHBCCPAIR,  	"J1850, HBCC subtype"},	{GJ1850 * 256 + GDLC,	    	"J1850, GM DLC subtype"},	{GJ1850 * 256 + GCHRYSLER,  	"J1850, Chrysler subtype"},	{GJ1850 * 256 + GDEHC12,    	"J1850, DE HC12 KWP/BDLC subtype"},	{GKWP2000 * 256 + GDEHC12KWP,  	"Keyword protocol 2000"},	{GHONDA * 256 + GDGHC08,    	"Honda UART, DG HC08 subtype"},	{GFORDUBP * 256 + GDGUBP08, 	"Ford UBP, DG HC08 subtype"},	{-1,	    	    	    	"- unknown -"},    };    proto_tree_add_text(pt, tvb, offset, 20, "Device name: %.20s",	tvb_get_ptr(tvb, offset, 20));    offset += 20;    proto_tree_add_text(pt, tvb, offset, 8, "Device version: %.8s",	tvb_get_ptr(tvb, offset, 8));    offset += 8;    proto_tree_add_text(pt, tvb, offset, 20, "Device serial number: %.20s",	tvb_get_ptr(tvb, offset, 20));    offset += 20;    devices = tvb_get_guint8(tvb, offset);    proto_tree_add_text(pt, tvb, offset, 1, "Number of channels: %d", devices);    proto_tree_add_text(pt, tvb, offset+1, 15, "reserved");    offset += 16;    for (i = 1; i <= devices; i++) {	ti = proto_tree_add_text(pt, tvb, offset, 80, "Channel %d:", i);	ft = proto_item_add_subtree(ti, ett_gryphon_cmd_config_device);	proto_tree_add_text(ft, tvb, offset, 20, "Driver name: %.20s",	    tvb_get_ptr(tvb, offset, 20));	offset += 20;	proto_tree_add_text(ft, tvb, offset, 8, "Driver version: %.8s",	    tvb_get_ptr(tvb, offset, 8));	offset += 8;	proto_tree_add_text(ft, tvb, offset, 24, "Device security string: %.24s",	    tvb_get_ptr(tvb, offset, 24));	offset += 24;	proto_tree_add_text(ft, tvb, offset, 20, "Hardware serial number: %.20s",	    tvb_get_ptr(tvb, offset, 20));	offset += 20;    	x = tvb_get_ntohs(tvb, offset);	for (j = 0; j < SIZEOF(protocol_types); j++) {	    if (protocol_types[j].value == x)	    	break;	}	if (j >= SIZEOF(protocol_types))	    j = SIZEOF(protocol_types) -1;	proto_tree_add_text(ft, tvb, offset, 2, "Protocol type & subtype: %s", protocol_types[j].strptr);	offset += 2;	proto_tree_add_text(ft, tvb, offset, 1, "Channel ID: %u",	    tvb_get_guint8(tvb, offset));	proto_tree_add_text(ft, tvb, offset+1, 5, "reserved");	offset += 6;    }

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -