Ethereal-dev: [ethereal-dev] Gryphon dissector patch

Note: This archive is from the project's previous web site, ethereal.com. This list is no longer active.

From: Steve Limkemann <stevelim@xxxxxxxxxx>
Date: Tue, 14 Dec 1999 13:13:31 -0500 (EST)
Gilbert,

  Sorry for the delay in getting back with a patch to my code.  My brother
died last Wednesday morning of lung cancer and I took some time off.

  The patch to my original code follows my signature.  (I haven't used or
created very many patches.  If it's incorrect or not in the preferred
format, let me know and I'll redo it.)  It should take care of all of the
outstanding issues with the dissector.  Since I am no longer subscribed to
the list, please pass along anything that requires changes to the code.

			Steve

 ______________________  _______________________________________________
/  Steve Limkemann     \/  A microsecond here and a microsecond there,  \
|  Westland, Michigan  ||    and before you know it, you're talking     |
|  USA, North America  ||                real-time.                     |
|  Earth, Solar System ||                                               |
|  Milky Way           ||      Smoking: Not just an addiction,          |
|    MGX467 271 48185  ||               but a way of death.             |
\ _____________________/\ ______________________________________________/


--- packet-gryphon.c.orig	Tue Dec 14 12:11:50 1999
+++ packet-gryphon.c	Tue Dec 14 12:38:20 1999
@@ -104,7 +104,7 @@
     if (fd)
     	end_of_frame = END_OF_FRAME;
     else {
-    	end_of_frame =  ntohs (*(unsigned short *)(data + 4)) + 8;
+    	end_of_frame =  pntohs ((unsigned short *)(data + 4)) + 8;
 	end_of_frame += 3 - (end_of_frame + 3) % 4;
     }
     dataend = data + end_of_frame;
@@ -133,7 +133,7 @@
 	    src = data[0];
 	    dest = data[2];
 	    frmtyp = data[6];
-	    msglen = ntohs (*(unsigned short *)&data[4]);
+	    msglen = pntohs ((unsigned short *)&data[4]);
 
     	    header_item = proto_tree_add_text(gryphon_tree, offset,
 	    	    MSG_HDR_SZ, "Header", NULL);
@@ -483,7 +483,7 @@
     proto_tree_add_text (pt, *offset, 4, "Command: %s", cmds[i].strptr);
     BUMP (*offset, *data, 4);
     
-    resp = ntohl (*(unsigned long *)data[0]);
+    resp = pntohl ((unsigned long *)data[0]);
     for (j = 0; j < SIZEOF(responses); j++) {
     	if (responses[j].value == resp)
 	    break;
@@ -511,7 +511,7 @@
 
 	hdrsize = (*data)[0];
 	hdrbits = (*data)[1];
-	datasize = ntohs (*(unsigned short *)((*data)+2));
+	datasize = pntohs ((unsigned short *)((*data)+2));
 	extrasize = (*data)[4];
 	padding = 3 - (hdrsize + datasize + extrasize + 3) % 4;
 	msgsize = hdrsize + datasize + extrasize + padding + 16;
@@ -538,7 +538,7 @@
 	}
     	proto_tree_add_text(tree, *offset+6, 1, "Priority: %d", (*data)[6]);
     	proto_tree_add_text(tree, *offset+7, 1, "Error status: %hd", (*data)[7]);
-	timestamp = ntohl (*(unsigned long *)((*data)+8));
+	timestamp = pntohl ((unsigned long *)((*data)+8));
 	hours = timestamp /(100000 * 60 *60);
 	minutes = (timestamp / (100000 * 60)) % 60;
 	seconds = (timestamp / 100000) % 60;
@@ -580,7 +580,7 @@
     proto_tree_add_text(pt, *offset+1, 1, "Event context: %hd", *((*data)+1));
     proto_tree_add_text(pt, *offset+2, 2, "reserved", NULL);
     BUMP (*offset, *data, 4);
-    timestamp = ntohl (*(unsigned long *)(*data));
+    timestamp = pntohl ((unsigned long *)(*data));
     hours = timestamp /(100000 * 60 *60);
     minutes = (timestamp / (100000 * 60)) % 60;
     seconds = (timestamp / 100000) % 60;
@@ -638,8 +638,8 @@
     unsigned int    timestamp;
     unsigned char   date[45];
     
-    ts.lng[1] = ntohl (*(unsigned int *)(*data));
-    ts.lng[0] = ntohl (*(unsigned int *)((*data)+4));
+    ts.lng[1] = pntohl ((unsigned int *)(*data));
+    ts.lng[0] = pntohl ((unsigned int *)((*data)+4));
     timestamp = ts.lnglng / 100000LL;
     strncpy (date, ctime((time_t*)&timestamp), sizeof(date));
     date[strlen(date)-1] = 0x00;
@@ -656,11 +656,11 @@
 void
 cmd_setfilt (int src, const u_char **data, const u_char *dataend, int *offset, int msglen, proto_tree *pt)
 {
-    int     	    flag = ntohl (*(unsigned int *)((*data)+4));
+    int     	    flag = pntohl ((unsigned int *)((*data)+4));
     int     	    length, padding;
     unsigned char   mode[30];
     
-    length =  *((*data)+4) + *((*data)+5) + ntohs (*(unsigned short *)((*data)+6));
+    length =  *((*data)+4) + *((*data)+5) + pntohs ((unsigned short *)((*data)+6));
     if (flag)
     	strcpy (mode, "Pass");
     else
@@ -687,7 +687,7 @@
     unsigned int    ioctl;
     int     	    i;
 
-    ioctl = ntohl (*(unsigned int *)(*data));
+    ioctl = pntohl ((unsigned int *)(*data));
     for (i = 0; i < SIZEOF(ioctls); i++) {
     	if (ioctls[i].value == ioctl)
 	    break;
@@ -730,7 +730,7 @@
     proto_tree_add_text(pt, *offset+1, 6, "reserved", NULL);
     BUMP (*offset, *data, 7);
     for (i = 1; i <= blocks; i++) {
-	length = ntohs (*(unsigned short *)((*data)+2)) * 2 + 8;
+	length = pntohs ((unsigned short *)((*data)+2)) * 2 + 8;
 	length += 3 - (length + 3) % 4;
 	item = proto_tree_add_text(pt, *offset, length, "Filter block %d", i);
 	tree = proto_item_add_subtree (item, ett_gryphon_cmd_filter_block);
@@ -918,7 +918,7 @@
 	proto_tree_add_text(ft, *offset, 20, "Hardware serial number: %s", string);
 	BUMP (*offset, *data, 20);
 
-    	x = ntohs (*(unsigned short *)*data);
+    	x = pntohs ((unsigned short *)*data);
 	for (j = 0; j < SIZEOF(protocol_types); j++) {
 	    if (protocol_types[j].value == x)
 	    	break;
@@ -945,13 +945,13 @@
     char    	    crit[] = ".... ...1 = Critical scheduler";
     char    	    norm[] = ".... ...0 = Normal scheduler";
     
-    x = ntohl (*(unsigned int *)*data);
+    x = pntohl ((unsigned int *)*data);
     if (x == 0xFFFFFFFF)
     	proto_tree_add_text(pt, *offset, 4, "Number of iterations: infinite", NULL);
     else
     	proto_tree_add_text(pt, *offset, 4, "Number of iterations: %d", x);
     BUMP (*offset, *data, 4);
-    x = ntohl (*(unsigned int *)*data);
+    x = pntohl ((unsigned int *)*data);
     item = proto_tree_add_text(pt, *offset, 4, "Flags", NULL);
     tree = proto_item_add_subtree (item, ett_gryphon_flags);
     ptr = x & 1 ? crit : norm;
@@ -959,17 +959,17 @@
     BUMP (*offset, *data, 4);
     i = 1;
     while (*data < dataend) {
-    	length = 16 + (*data)[16] + ntohs (*(unsigned short *)((*data)+18)) + (*data)[20] + 16;
+    	length = 16 + (*data)[16] + pntohs ((unsigned short *)((*data)+18)) + (*data)[20] + 16;
 	length += 3 - (length + 3) % 4;
 	item = proto_tree_add_text(pt, *offset, length, "Message %d", i);
 	tree = proto_item_add_subtree (item, ett_gryphon_cmd_sched_data);
-	x = ntohl (*(unsigned int *)*data);
+	x = pntohl ((unsigned int *)*data);
 	proto_tree_add_text(tree, *offset, 4, "Sleep: %d milliseconds", x);
 	BUMP (*offset, *data, 4);
-	x = ntohl (*(unsigned int *)*data);
+	x = pntohl ((unsigned int *)*data);
 	proto_tree_add_text(tree, *offset, 4, "Transmit count: %d", x);
 	BUMP (*offset, *data, 4);
-	x = ntohl (*(unsigned int *)*data);
+	x = pntohl ((unsigned int *)*data);
 	proto_tree_add_text(tree, *offset, 4, "Transmit period: %d milliseconds", x);
 	BUMP (*offset, *data, 4);
 	proto_tree_add_text(tree, *offset, 2, "reserved flags", NULL);
@@ -998,7 +998,7 @@
     	"Historic peak bus load: %d.%02d%%"
     };
 
-    timestamp = ntohl (*(unsigned long *)(*data));
+    timestamp = pntohl ((unsigned long *)(*data));
     hours = timestamp /(100000 * 60 *60);
     minutes = (timestamp / (100000 * 60)) % 60;
     seconds = (timestamp / 100000) % 60;
@@ -1006,7 +1006,7 @@
     proto_tree_add_text(pt, *offset, 4, "Timestamp: %d:%02d:%02d.%05d", hours, minutes, seconds, fraction);
     BUMP (*offset, *data, 4);
     for (i = 0; i < SIZEOF(fields); i++){
-    	x = ntohs (*(unsigned short *)(*data));
+    	x = pntohs ((unsigned short *)(*data));
 	fract = x % 100;
 	x /= 100;
 	proto_tree_add_text(pt, *offset, 2, fields[i], x, fract);
@@ -1029,7 +1029,7 @@
 
     resp_blm_data (src, data, dataend, offset, msglen, pt);
     for (i = 0; i < SIZEOF(fields); i++){
-    	x = ntohl (*(unsigned int *)(*data));
+    	x = pntohl ((unsigned int *)(*data));
 	proto_tree_add_text(pt, *offset, 4, fields[i], x);
 	BUMP (*offset, *data, 4);
     }
@@ -1096,7 +1096,7 @@
     	proto_tree_add_text(tree, *offset, 1,
 	    	".11. .... Delete this response for a conforming message", NULL);
     }
-    actionValue = ntohs (*(unsigned short *)((*data)+2));
+    actionValue = pntohs ((unsigned short *)((*data)+2));
     if (actionValue) {
 	if (action & FR_PERIOD_MSGS){
     	    ptr = "...1 .... The period is in frames";
@@ -1119,14 +1119,14 @@
     }
     BUMP (*offset, *data, 2);
     for (i = 1; i <= blocks; i++) {
-	length = ntohs (*(unsigned short *)((*data)+2)) * 2 + 8;
+	length = pntohs ((unsigned short *)((*data)+2)) * 2 + 8;
 	length += 3 - (length + 3) % 4;
 	item = proto_tree_add_text(pt, *offset, length, "Filter block %d", i);
 	tree = proto_item_add_subtree (item, ett_gryphon_cmd_filter_block);
 	filter_block (src, data, dataend, offset, msglen, tree);
     }
     for (i = 1; i <= responses; i++) {
-	length = ntohs (*(unsigned short *)((*data)+4)) + 8;
+	length = pntohs ((unsigned short *)((*data)+4)) + 8;
 	length += 3 - (length + 3) % 4;
 	item = proto_tree_add_text(pt, *offset, length, "Response block %d", i);
 	tree = proto_item_add_subtree (item, ett_gryphon_cmd_response_block);
@@ -1189,7 +1189,7 @@
 void
 resp_sched (int src, const u_char **data, const u_char *dataend, int *offset, int msglen, proto_tree *pt)
 {
-    unsigned int    id = ntohl (*(unsigned int *)(*data));
+    unsigned int    id = pntohl ((unsigned int *)(*data));
     proto_tree_add_text(pt, *offset, 4, "Transmit schedule ID: %d", id);
     BUMP (*offset, *data, 4);
 }
@@ -1199,7 +1199,7 @@
 {
     u_char  string[81];
     
-    proto_tree_add_text(pt, *offset, 4, "Program size: %d bytes", ntohl (*(unsigned int *)(*data)));
+    proto_tree_add_text(pt, *offset, 4, "Program size: %d bytes", pntohl ((unsigned int *)(*data)));
     BUMP (*offset, *data, 4);
     strncpy (string, *data, 32);
     string[32] = 0;
@@ -1236,7 +1236,7 @@
 cmd_upload (int src, const u_char **data, const u_char *dataend, int *offset, int msglen, proto_tree *pt) {
     unsigned int    length;
     
-    proto_tree_add_text(pt, *offset, 2, "Block number: %d", ntohs (*(unsigned short *)(*data)));
+    proto_tree_add_text(pt, *offset, 2, "Block number: %d", pntohs ((unsigned short *)(*data)));
     BUMP (*offset, *data, 4);
     proto_tree_add_text(pt, *offset+2, 1, "Handle: %hd", (*data)[2]);
     BUMP (*offset, *data, 3);
@@ -1279,7 +1279,7 @@
     proto_tree_add_text(pt, *offset, 1, "Number of programs in this response: %d", count);
     proto_tree_add_text(pt, *offset+1, 1, "reserved", NULL);
     BUMP (*offset, *data, 2);
-    proto_tree_add_text(pt, *offset, 2, "Number of remaining programs: %d", ntohs (*(unsigned short *)(*data)));
+    proto_tree_add_text(pt, *offset, 2, "Number of remaining programs: %d", pntohs ((unsigned short *)(*data)));
     BUMP (*offset, *data, 2);
     for (i = 1; i <= count; i++) {
 	item = proto_tree_add_text(pt, *offset, 112, "Program %d", i);
@@ -1366,10 +1366,10 @@
 	    option_value = (*data)[2];
 	    break;
 	case 2:
-	    option_value = ntohs (*(unsigned short *)((*data)+2));
+	    option_value = pntohs ((unsigned short *)((*data)+2));
 	    break;
 	case 4:
-	    option_value = ntohl (*(unsigned int *)((*data)+2));
+	    option_value = pntohl ((unsigned int *)((*data)+2));
 	    break;
 	default:
 	    option_value = 0;
@@ -1420,8 +1420,8 @@
 filter_block (int src, const u_char **data, const u_char *dataend, int *offset, int msglen, proto_tree *pt) {
     int     length, type, i, operator, padding;
     
-    proto_tree_add_text(pt, *offset, 2, "Filter field starts at byte %d", ntohs (*(unsigned short *)(*data)));
-    length = ntohs (*(unsigned short *)((*data)+2));
+    proto_tree_add_text(pt, *offset, 2, "Filter field starts at byte %d", pntohs ((unsigned short *)(*data)));
+    length = pntohs ((unsigned short *)((*data)+2));
     proto_tree_add_text(pt, *offset+2, 2, "Filter field is %d bytes long", length);
     type = *((*data)+4);
     for (i = 0; i < SIZEOF(filter_data_types); i++) {
@@ -1452,10 +1452,10 @@
     	    proto_tree_add_text(pt, *offset, 1, "Value: %hd", **data);
 	    break;
 	case 2:
-   	    proto_tree_add_text(pt, *offset, 2, "Value: %d", ntohs (*(unsigned short *)(*data)));
+   	    proto_tree_add_text(pt, *offset, 2, "Value: %d", pntohs ((unsigned short *)(*data)));
 	    break;
 	case 4:
-   	    proto_tree_add_text(pt, *offset, 4, "Value: %dl", ntohl (*(unsigned long *)(*data)));
+   	    proto_tree_add_text(pt, *offset, 4, "Value: %dl", pntohl ((unsigned long *)(*data)));
 	    break;
 	default:
    	    proto_tree_add_text(pt, *offset, length, "Value", NULL);
@@ -1475,8 +1475,8 @@
     char    *mode, line[50];
     int     x, y, seconds;
     
-    x = ntohl (*(unsigned long *)(*data));
-    y = ntohl (*(unsigned long *)((*data)+4));
+    x = pntohl ((unsigned long *)(*data));
+    y = pntohl ((unsigned long *)((*data)+4));
     switch (x) {
     case 0:
     	mode = "Off";
@@ -1507,22 +1507,22 @@
 {
     static hf_register_info hf[] = {
 	{ &hf_gryph_src,
-	{ "Source",           "g.src", FT_UINT8, BASE_DEC, NULL, 0x0,
+	{ "Source",           "gryph.src", FT_UINT8, BASE_DEC, NULL, 0x0,
 	    	"" }},
 	{ &hf_gryph_srcchan,
-	{ "Source channel",   "g.srcchan", FT_UINT8, BASE_DEC, NULL, 0x0,
+	{ "Source channel",   "gryph.srcchan", FT_UINT8, BASE_DEC, NULL, 0x0,
 	    	"" }},
 	{ &hf_gryph_dest,
-	{ "Destination",      "g.dest", FT_UINT8, BASE_DEC, NULL, 0x0,
+	{ "Destination",      "gryph.dest", FT_UINT8, BASE_DEC, NULL, 0x0,
 	    	"" }},
 	{ &hf_gryph_destchan,
-	{ "Destination channel", "g.dstchan", FT_UINT8, BASE_DEC, NULL, 0x0,
+	{ "Destination channel", "gryph.dstchan", FT_UINT8, BASE_DEC, NULL, 0x0,
 	    	"" }},
 	{ &hf_gryph_type,
-	{ "Frame type",       "g.type", FT_UINT8, BASE_DEC, NULL, 0x0,
+	{ "Frame type",       "gryph.type", FT_UINT8, BASE_DEC, NULL, 0x0,
 	    	"" }},
 	{ &hf_gryph_cmd,
-	{ "Command",          "g.cmd.cmd", FT_UINT8, BASE_DEC, NULL, 0x0,
+	{ "Command",          "gryph.cmd.cmd", FT_UINT8, BASE_DEC, NULL, 0x0,
 	    	"" }},
     };