Ethereal-dev: [ethereal-dev] New Gryphon patch and answers to old comments.
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 15:50:40 -0500 (EST)
I just found this and thought I'd answer it. On Tue, 7 Dec 1999, Guy Harris wrote: > > You'll want to convert your uses of ntohs(x) to pntohs(&x). > > ...or, in this case, convert it to do > > end_of_frame = pntohs (data + 4) + 8; Done. I also removed the unnecessary castings that were left with the previous patch. > However, the checks for "fd" aren't necessary ("fd" is always non-NULL), > so perhaps it could just be > > end_of_frame = END_OF_FRAME; True in general. In this case, dissect_gryphon() is called recursively with the "fd" argument set to NULL. > In addition, there's a C++-style comment in one line: Removed. 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 14:54:17 1999 +++ packet-gryphon.c Tue Dec 14 15:39:43 1999 @@ -104,7 +104,7 @@ if (fd) end_of_frame = END_OF_FRAME; else { - end_of_frame = pntohs ((unsigned short *)(data + 4)) + 8; + end_of_frame = pntohs (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 = pntohs ((unsigned short *)&data[4]); + msglen = pntohs (&data[4]); header_item = proto_tree_add_text(gryphon_tree, offset, MSG_HDR_SZ, "Header", NULL); @@ -206,7 +206,6 @@ proto_tree_add_text(gryphon_tree, offset, i, "padding", NULL); BUMP (offset, data, i); } -// data = dataend; } } @@ -483,7 +482,7 @@ proto_tree_add_text (pt, *offset, 4, "Command: %s", cmds[i].strptr); BUMP (*offset, *data, 4); - resp = pntohl ((unsigned long *)data[0]); + resp = pntohl (data[0]); for (j = 0; j < SIZEOF(responses); j++) { if (responses[j].value == resp) break; @@ -511,7 +510,7 @@ hdrsize = (*data)[0]; hdrbits = (*data)[1]; - datasize = pntohs ((unsigned short *)((*data)+2)); + datasize = pntohs ((*data)+2); extrasize = (*data)[4]; padding = 3 - (hdrsize + datasize + extrasize + 3) % 4; msgsize = hdrsize + datasize + extrasize + padding + 16; @@ -538,7 +537,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 = pntohl ((unsigned long *)((*data)+8)); + timestamp = pntohl ((*data)+8); hours = timestamp /(100000 * 60 *60); minutes = (timestamp / (100000 * 60)) % 60; seconds = (timestamp / 100000) % 60; @@ -580,7 +579,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 = pntohl ((unsigned long *)(*data)); + timestamp = pntohl ((*data)); hours = timestamp /(100000 * 60 *60); minutes = (timestamp / (100000 * 60)) % 60; seconds = (timestamp / 100000) % 60; @@ -638,8 +637,8 @@ unsigned int timestamp; unsigned char date[45]; - ts.lng[1] = pntohl ((unsigned int *)(*data)); - ts.lng[0] = pntohl ((unsigned int *)((*data)+4)); + ts.lng[1] = pntohl ((*data)); + ts.lng[0] = pntohl ((*data)+4); timestamp = ts.lnglng / 100000LL; strncpy (date, ctime((time_t*)×tamp), sizeof(date)); date[strlen(date)-1] = 0x00; @@ -656,11 +655,11 @@ void cmd_setfilt (int src, const u_char **data, const u_char *dataend, int *offset, int msglen, proto_tree *pt) { - int flag = pntohl ((unsigned int *)((*data)+4)); + int flag = pntohl ((*data)+4); int length, padding; unsigned char mode[30]; - length = *((*data)+4) + *((*data)+5) + pntohs ((unsigned short *)((*data)+6)); + length = *((*data)+4) + *((*data)+5) + pntohs ((*data)+6); if (flag) strcpy (mode, "Pass"); else @@ -687,7 +686,7 @@ unsigned int ioctl; int i; - ioctl = pntohl ((unsigned int *)(*data)); + ioctl = pntohl ((*data)); for (i = 0; i < SIZEOF(ioctls); i++) { if (ioctls[i].value == ioctl) break; @@ -730,7 +729,7 @@ proto_tree_add_text(pt, *offset+1, 6, "reserved", NULL); BUMP (*offset, *data, 7); for (i = 1; i <= blocks; i++) { - length = pntohs ((unsigned short *)((*data)+2)) * 2 + 8; + length = pntohs ((*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 +917,7 @@ proto_tree_add_text(ft, *offset, 20, "Hardware serial number: %s", string); BUMP (*offset, *data, 20); - x = pntohs ((unsigned short *)*data); + x = pntohs ((*data)); for (j = 0; j < SIZEOF(protocol_types); j++) { if (protocol_types[j].value == x) break; @@ -945,13 +944,13 @@ char crit[] = ".... ...1 = Critical scheduler"; char norm[] = ".... ...0 = Normal scheduler"; - x = pntohl ((unsigned int *)*data); + x = pntohl ((*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 = pntohl ((unsigned int *)*data); + x = pntohl ((*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 +958,17 @@ BUMP (*offset, *data, 4); i = 1; while (*data < dataend) { - length = 16 + (*data)[16] + pntohs ((unsigned short *)((*data)+18)) + (*data)[20] + 16; + length = 16 + (*data)[16] + pntohs ((*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 = pntohl ((unsigned int *)*data); + x = pntohl ((*data)); proto_tree_add_text(tree, *offset, 4, "Sleep: %d milliseconds", x); BUMP (*offset, *data, 4); - x = pntohl ((unsigned int *)*data); + x = pntohl ((*data)); proto_tree_add_text(tree, *offset, 4, "Transmit count: %d", x); BUMP (*offset, *data, 4); - x = pntohl ((unsigned int *)*data); + x = pntohl ((*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 +997,7 @@ "Historic peak bus load: %d.%02d%%" }; - timestamp = pntohl ((unsigned long *)(*data)); + timestamp = pntohl ((*data)); hours = timestamp /(100000 * 60 *60); minutes = (timestamp / (100000 * 60)) % 60; seconds = (timestamp / 100000) % 60; @@ -1006,7 +1005,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 = pntohs ((unsigned short *)(*data)); + x = pntohs ((*data)); fract = x % 100; x /= 100; proto_tree_add_text(pt, *offset, 2, fields[i], x, fract); @@ -1029,7 +1028,7 @@ resp_blm_data (src, data, dataend, offset, msglen, pt); for (i = 0; i < SIZEOF(fields); i++){ - x = pntohl ((unsigned int *)(*data)); + x = pntohl ((*data)); proto_tree_add_text(pt, *offset, 4, fields[i], x); BUMP (*offset, *data, 4); } @@ -1096,7 +1095,7 @@ proto_tree_add_text(tree, *offset, 1, ".11. .... Delete this response for a conforming message", NULL); } - actionValue = pntohs ((unsigned short *)((*data)+2)); + actionValue = pntohs ((*data)+2); if (actionValue) { if (action & FR_PERIOD_MSGS){ ptr = "...1 .... The period is in frames"; @@ -1119,14 +1118,14 @@ } BUMP (*offset, *data, 2); for (i = 1; i <= blocks; i++) { - length = pntohs ((unsigned short *)((*data)+2)) * 2 + 8; + length = pntohs ((*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 = pntohs ((unsigned short *)((*data)+4)) + 8; + length = pntohs ((*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 +1188,7 @@ void resp_sched (int src, const u_char **data, const u_char *dataend, int *offset, int msglen, proto_tree *pt) { - unsigned int id = pntohl ((unsigned int *)(*data)); + unsigned int id = pntohl ((*data)); proto_tree_add_text(pt, *offset, 4, "Transmit schedule ID: %d", id); BUMP (*offset, *data, 4); } @@ -1199,7 +1198,7 @@ { u_char string[81]; - proto_tree_add_text(pt, *offset, 4, "Program size: %d bytes", pntohl ((unsigned int *)(*data))); + proto_tree_add_text(pt, *offset, 4, "Program size: %d bytes", pntohl ((*data))); BUMP (*offset, *data, 4); strncpy (string, *data, 32); string[32] = 0; @@ -1236,7 +1235,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", pntohs ((unsigned short *)(*data))); + proto_tree_add_text(pt, *offset, 2, "Block number: %d", pntohs ((*data))); BUMP (*offset, *data, 4); proto_tree_add_text(pt, *offset+2, 1, "Handle: %hd", (*data)[2]); BUMP (*offset, *data, 3); @@ -1279,7 +1278,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", pntohs ((unsigned short *)(*data))); + proto_tree_add_text(pt, *offset, 2, "Number of remaining programs: %d", pntohs ((*data))); BUMP (*offset, *data, 2); for (i = 1; i <= count; i++) { item = proto_tree_add_text(pt, *offset, 112, "Program %d", i); @@ -1366,10 +1365,10 @@ option_value = (*data)[2]; break; case 2: - option_value = pntohs ((unsigned short *)((*data)+2)); + option_value = pntohs ((*data)+2); break; case 4: - option_value = pntohl ((unsigned int *)((*data)+2)); + option_value = pntohl ((*data)+2); break; default: option_value = 0; @@ -1420,8 +1419,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", pntohs ((unsigned short *)(*data))); - length = pntohs ((unsigned short *)((*data)+2)); + proto_tree_add_text(pt, *offset, 2, "Filter field starts at byte %d", pntohs ((*data))); + length = pntohs ((*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 +1451,10 @@ proto_tree_add_text(pt, *offset, 1, "Value: %hd", **data); break; case 2: - proto_tree_add_text(pt, *offset, 2, "Value: %d", pntohs ((unsigned short *)(*data))); + proto_tree_add_text(pt, *offset, 2, "Value: %d", pntohs ((*data))); break; case 4: - proto_tree_add_text(pt, *offset, 4, "Value: %dl", pntohl ((unsigned long *)(*data))); + proto_tree_add_text(pt, *offset, 4, "Value: %dl", pntohl ((*data))); break; default: proto_tree_add_text(pt, *offset, length, "Value", NULL); @@ -1475,8 +1474,8 @@ char *mode, line[50]; int x, y, seconds; - x = pntohl ((unsigned long *)(*data)); - y = pntohl ((unsigned long *)((*data)+4)); + x = pntohl ((*data)); + y = pntohl ((*data)+4); switch (x) { case 0: mode = "Off";
- References:
- Re: [ethereal-dev] New dissector question
- From: Guy Harris
- Re: [ethereal-dev] New dissector question
- Prev by Date: [ethereal-dev] Patch for ISIS support
- Next by Date: [ethereal-dev] Windows Packet Capture routines
- Previous by thread: Re: [ethereal-dev] New dissector question
- Next by thread: Re: [ethereal-dev] New dissector question
- Index(es):