Ethereal-dev: Re: [ethereal-dev] Vines coded expanded
Note: This archive is from the project's previous web site, ethereal.com. This list is no longer active.
From: guy@xxxxxxxxxx (Guy Harris)
Date: Thu, 3 Dec 1998 22:25:12 -0800 (PST)
> I finally got it to work by *yuk* replacing the call to > "gtk_tree_item_new_with_label()" in "add_item_to_tree()" with a modified > version of the code to "gtk_tree_item_new_with_label()" that sets the > style on the newly-created label widget, but I'm still not sure that's > how I'm *supposed* to be doing that - and it means that I've > cut-and-pasted code, so if the tree item widget changes in a future GTK+ > release, that change doesn't get propagated.... There appears to be a better way - in "add_item_to_tree()", right after it calls "gtk_tree_item_new_with_label()", call "gtk_container_foreach()" with a routine to set the widget style on the subwidget to which it's handed a pointer. Here's a patch that does all that. The new bitfield-decoding routines are "decode_boolean_bitfield()", "decode_enumerated_bitfield()", and "decode_numeric_bitfield()", in "util.c", declared in "util.h". I'm not particularly committed to their names, their calling sequences, or their locations, as long as any changed versions manage not to oblige their callers to do significantly more work. The change includes, as samples, stuff to decode the "type of service" byte, and the "flags" part of the "flags/fragment offset" byte, in the IP header, and the "flags" part of the "data offset/flags" byte in the TCP header. It also changes the PostScript header, as per Gilbert's comment. The display doesn't look quite as nice to me, offhand, in a fixed-width font, but so it goes.... One might also make aesthetic arguments against the implementation, at the GTK level; I'm not a GTK wizard, so I don't know if there's a better way, either from the coding standpoint or from the "where should styles, fonts, etc. come from" standpoint (i.e., if written differently, it might let you better configure the fonts in the "gtkrc" file). I'm assuming here that styles are reference-counted, so that you don't have to create a new one for every single tree item. Here's the patch: Index: ethereal.c =================================================================== RCS file: /usr/local/cvsroot/ethereal/ethereal.c,v retrieving revision 1.14 diff -c -r1.14 ethereal.c *** ethereal.c 1998/11/18 03:17:16 1.14 --- ethereal.c 1998/12/04 06:10:41 *************** *** 79,84 **** --- 79,86 ---- ts_type timestamp_type = RELATIVE; + GtkStyle *item_style; + #define E_DFILTER_TE_KEY "display_filter_te" /* About Ethereal window */ *************** *** 576,581 **** --- 578,587 ---- gtk_signal_connect(GTK_OBJECT(tree_view), "selection_changed", GTK_SIGNAL_FUNC(tree_view_cb), NULL); gtk_widget_show(tree_view); + + item_style = gtk_style_new(); + gdk_font_unref(item_style->font); + item_style->font = m_r_font; /* Byte view */ bv_table = gtk_table_new (2, 2, FALSE); Index: ethereal.h =================================================================== RCS file: /usr/local/cvsroot/ethereal/ethereal.h,v retrieving revision 1.8 diff -c -r1.8 ethereal.h *** ethereal.h 1998/11/17 04:28:45 1.8 --- ethereal.h 1998/12/04 06:10:41 *************** *** 123,128 **** --- 123,130 ---- extern ts_type timestamp_type; + extern GtkStyle *item_style; + void about_ethereal( GtkWidget *, gpointer); void file_sel_ok_cb(GtkWidget *, GtkFileSelection *); void blank_packetinfo(); Index: packet-ip.c =================================================================== RCS file: /usr/local/cvsroot/ethereal/packet-ip.c,v retrieving revision 1.12 diff -c -r1.12 packet-ip.c *** packet-ip.c 1998/11/17 04:28:54 1.12 --- packet-ip.c 1998/12/04 06:10:41 *************** *** 43,48 **** --- 43,49 ---- #include "packet.h" #include "etypes.h" #include "resolv.h" + #include "util.h" extern packet_info pi; *************** *** 391,397 **** {IP_PROTO_UDP, "UDP" }, {IP_PROTO_OSPF, "OSPF"}, {0, NULL } }; ! /* To do: check for runts, errs, etc. */ /* Avoids alignment problems on many architectures. */ --- 392,407 ---- {IP_PROTO_UDP, "UDP" }, {IP_PROTO_OSPF, "OSPF"}, {0, NULL } }; ! static const value_string precedence_vals[] = { ! { IPTOS_PREC_ROUTINE, "routine" }, ! { IPTOS_PREC_PRIORITY, "priority" }, ! { IPTOS_PREC_IMMEDIATE, "immediate" }, ! { IPTOS_PREC_FLASH, "flash" }, ! { IPTOS_PREC_FLASHOVERRIDE, "flash override" }, ! { IPTOS_PREC_CRITIC_ECP, "CRITIC/ECP" }, ! { IPTOS_PREC_INTERNETCONTROL, "internetwork control" }, ! { IPTOS_PREC_NETCONTROL, "network control" }, ! { 0, NULL } }; /* To do: check for runts, errs, etc. */ /* Avoids alignment problems on many architectures. */ *************** *** 458,469 **** add_subtree(ti, ip_tree, ETT_IP); add_item_to_tree(ip_tree, offset, 1, "Version: %d", iph.ip_v); add_item_to_tree(ip_tree, offset, 1, "Header length: %d bytes", hlen); ! add_item_to_tree(ip_tree, offset + 1, 1, "Type of service: 0x%02x (%s)", iph.ip_tos, tos_str); add_item_to_tree(ip_tree, offset + 2, 2, "Total length: %d", iph.ip_len); add_item_to_tree(ip_tree, offset + 4, 2, "Identification: 0x%04x", iph.ip_id); ! /* To do: add flags */ add_item_to_tree(ip_tree, offset + 6, 2, "Fragment offset: %d", iph.ip_off & IP_OFFSET); add_item_to_tree(ip_tree, offset + 8, 1, "Time to live: %d", --- 468,506 ---- add_subtree(ti, ip_tree, ETT_IP); add_item_to_tree(ip_tree, offset, 1, "Version: %d", iph.ip_v); add_item_to_tree(ip_tree, offset, 1, "Header length: %d bytes", hlen); ! tf = add_item_to_tree(ip_tree, offset + 1, 1, "Type of service: 0x%02x (%s)", iph.ip_tos, tos_str); + field_tree = gtk_tree_new(); + add_subtree(tf, field_tree, ETT_IP_TOS); + add_item_to_tree(field_tree, offset + 1, 1, "%s", + decode_enumerated_bitfield(iph.ip_tos, IPTOS_PREC_MASK, + sizeof (iph.ip_tos)*8, precedence_vals, + "%s precedence")); + add_item_to_tree(field_tree, offset + 1, 1, "%s", + decode_boolean_bitfield(iph.ip_tos, IPTOS_LOWDELAY, + sizeof (iph.ip_tos)*8, "low delay", "normal delay")); + add_item_to_tree(field_tree, offset + 1, 1, "%s", + decode_boolean_bitfield(iph.ip_tos, IPTOS_THROUGHPUT, + sizeof (iph.ip_tos)*8, "high throughput", "normal throughput")); + add_item_to_tree(field_tree, offset + 1, 1, "%s", + decode_boolean_bitfield(iph.ip_tos, IPTOS_RELIABILITY, + sizeof (iph.ip_tos)*8, "high reliability", "normal reliability")); + add_item_to_tree(field_tree, offset + 1, 1, "%s", + decode_boolean_bitfield(iph.ip_tos, IPTOS_LOWCOST, + sizeof (iph.ip_tos)*8, "low cost", "normal cost")); add_item_to_tree(ip_tree, offset + 2, 2, "Total length: %d", iph.ip_len); add_item_to_tree(ip_tree, offset + 4, 2, "Identification: 0x%04x", iph.ip_id); ! tf = add_item_to_tree(ip_tree, offset + 6, 2, "Flags: 0x%x", ! (iph.ip_off & (IP_DF|IP_MF)) >> 12); ! field_tree = gtk_tree_new(); ! add_subtree(tf, field_tree, ETT_IP_OFF); ! add_item_to_tree(field_tree, offset + 6, 2, "%s", ! decode_boolean_bitfield(iph.ip_off >> 8, IP_DF >> 8, 8, "don't fragment", ! "may fragment")); ! add_item_to_tree(field_tree, offset + 6, 2, "%s", ! decode_boolean_bitfield(iph.ip_off >> 8, IP_MF >> 8, 8, "more fragments", ! "last fragment")); add_item_to_tree(ip_tree, offset + 6, 2, "Fragment offset: %d", iph.ip_off & IP_OFFSET); add_item_to_tree(ip_tree, offset + 8, 1, "Time to live: %d", Index: packet-tcp.c =================================================================== RCS file: /usr/local/cvsroot/ethereal/packet-tcp.c,v retrieving revision 1.9 diff -c -r1.9 packet-tcp.c *** packet-tcp.c 1998/11/18 03:01:37 1.9 --- packet-tcp.c 1998/12/04 06:10:41 *************** *** 43,48 **** --- 43,49 ---- #include "packet.h" #include "resolv.h" #include "follow.h" + #include "util.h" extern FILE* data_out_file; extern packet_info pi; *************** *** 280,286 **** add_item_to_tree(tcp_tree, offset + 8, 4, "Acknowledgement number: %u", th.th_ack); add_item_to_tree(tcp_tree, offset + 12, 1, "Header length: %d bytes", hlen); ! add_item_to_tree(tcp_tree, offset + 13, 1, "Flags: %s", flags); add_item_to_tree(tcp_tree, offset + 14, 2, "Window size: %d", th.th_win); add_item_to_tree(tcp_tree, offset + 16, 2, "Checksum: 0x%04x", th.th_sum); if (th.th_flags & TH_URG) --- 281,307 ---- add_item_to_tree(tcp_tree, offset + 8, 4, "Acknowledgement number: %u", th.th_ack); add_item_to_tree(tcp_tree, offset + 12, 1, "Header length: %d bytes", hlen); ! tf = add_item_to_tree(tcp_tree, offset + 13, 1, "Flags: 0x%x", th.th_flags); ! field_tree = gtk_tree_new(); ! add_subtree(tf, field_tree, ETT_TCP_FLAGS); ! add_item_to_tree(field_tree, offset + 13, 1, "%s", ! decode_boolean_bitfield(th.th_flags, TH_URG, sizeof (th.th_flags)*8, ! "Urgent pointer", "No urgent pointer")); ! add_item_to_tree(field_tree, offset + 13, 1, "%s", ! decode_boolean_bitfield(th.th_flags, TH_ACK, sizeof (th.th_flags)*8, ! "Acknowledgment", "No acknowledgment")); ! add_item_to_tree(field_tree, offset + 13, 1, "%s", ! decode_boolean_bitfield(th.th_flags, TH_PUSH, sizeof (th.th_flags)*8, ! "Push", "No push")); ! add_item_to_tree(field_tree, offset + 13, 1, "%s", ! decode_boolean_bitfield(th.th_flags, TH_RST, sizeof (th.th_flags)*8, ! "Reset", "No reset")); ! add_item_to_tree(field_tree, offset + 13, 1, "%s", ! decode_boolean_bitfield(th.th_flags, TH_SYN, sizeof (th.th_flags)*8, ! "Syn", "No Syn")); ! add_item_to_tree(field_tree, offset + 13, 1, "%s", ! decode_boolean_bitfield(th.th_flags, TH_FIN, sizeof (th.th_flags)*8, ! "Fin", "No Fin")); add_item_to_tree(tcp_tree, offset + 14, 2, "Window size: %d", th.th_win); add_item_to_tree(tcp_tree, offset + 16, 2, "Checksum: 0x%04x", th.th_sum); if (th.th_flags & TH_URG) Index: packet.c =================================================================== RCS file: /usr/local/cvsroot/ethereal/packet.c,v retrieving revision 1.13 diff -c -r1.13 packet.c *** packet.c 1998/12/04 05:59:13 1.13 --- packet.c 1998/12/04 06:10:42 *************** *** 149,154 **** --- 149,160 ---- } } + static void + set_item_style(GtkWidget *widget, gpointer dummy) + { + gtk_widget_set_style(widget, item_style); + } + GtkWidget * add_item_to_tree(GtkWidget *tree, gint start, gint len, gchar *format, ...) { *************** *** 159,164 **** --- 165,171 ---- va_start(ap, format); vsnprintf(label_str, 256, format, ap); ti = gtk_tree_item_new_with_label(label_str); + gtk_container_foreach(GTK_CONTAINER(ti), set_item_style, NULL); gtk_object_set_data(GTK_OBJECT(ti), E_TREEINFO_START_KEY, (gpointer) start); gtk_object_set_data(GTK_OBJECT(ti), E_TREEINFO_LEN_KEY, (gpointer) len); gtk_tree_append(GTK_TREE(tree), ti); Index: packet.h =================================================================== RCS file: /usr/local/cvsroot/ethereal/packet.h,v retrieving revision 1.27 diff -c -r1.27 packet.h *** packet.h 1998/12/04 05:59:14 1.27 --- packet.h 1998/12/04 06:10:42 *************** *** 391,400 **** --- 391,403 ---- ETT_IP_OPTION_SEC, ETT_IP_OPTION_ROUTE, ETT_IP_OPTION_TIMESTAMP, + ETT_IP_TOS, + ETT_IP_OFF, ETT_UDP, ETT_TCP, ETT_TCP_OPTIONS, ETT_TCP_OPTION_SACK, + ETT_TCP_FLAGS, ETT_ICMP, ETT_IGMP, ETT_IPX, Index: print.ps =================================================================== RCS file: /usr/local/cvsroot/ethereal/print.ps,v retrieving revision 1.2 diff -c -r1.2 print.ps *** print.ps 1998/09/17 03:29:28 1.2 --- print.ps 1998/12/04 06:10:42 *************** *** 110,116 **** /vpos tmargin def % Set the font to 10 point ! /Helvetica findfont 10 scalefont setfont % ---- ethereal preamble end ---- % % Display our output lines. --- 110,116 ---- /vpos tmargin def % Set the font to 10 point ! /Courier findfont 10 scalefont setfont % ---- ethereal preamble end ---- % % Display our output lines. Index: util.c =================================================================== RCS file: /usr/local/cvsroot/ethereal/util.c,v retrieving revision 1.7 diff -c -r1.7 util.c *** util.c 1998/10/28 21:22:33 1.7 --- util.c 1998/12/04 06:10:42 *************** *** 43,48 **** --- 43,49 ---- # include "snprintf.h" #endif + #include "packet.h" #include "util.h" #include "image/icon-excl.xpm" *************** *** 163,166 **** --- 164,247 ---- if (btn_mask) *btn_mask = ESD_BTN_CANCEL; gtk_widget_destroy(GTK_WIDGET(win)); + } + + /* Generate, into "buf", a string showing the bits of a bitfield. + Return a pointer to the character after that string. */ + static char * + decode_bitfield_value(char *buf, guint32 val, guint32 mask, int width) + { + int i; + guint32 bit; + char *p; + + i = 0; + p = buf; + bit = 1 << (width - 1); + for (;;) { + if (mask & bit) { + /* This bit is part of the field. Show its value. */ + if (val & bit) + *p++ = '1'; + else + *p++ = '0'; + } else { + /* This bit is not part of the field. */ + *p++ = '.'; + } + bit >>= 1; + i++; + if (i >= width) + break; + if (i % 4 == 0) + *p++ = ' '; + } + strcpy(p, " = "); + p += 3; + return p; + } + + /* Generate a string describing a Boolean bitfield (a one-bit field that + says something is either true of false). */ + const char * + decode_boolean_bitfield(guint32 val, guint32 mask, int width, + const char *truedesc, const char *falsedesc) + { + static char buf[1025]; + char *p; + + p = decode_bitfield_value(buf, val, mask, width); + if (val & mask) + strcpy(p, truedesc); + else + strcpy(p, falsedesc); + return buf; + } + + /* Generate a string describing an enumerated bitfield (an N-bit field + with various specific values having particular names). */ + const char * + decode_enumerated_bitfield(guint32 val, guint32 mask, int width, + const value_string *tab, const char *fmt) + { + static char buf[1025]; + char *p; + + p = decode_bitfield_value(buf, val, mask, width); + sprintf(p, fmt, val_to_str(val & mask, tab, "Unknown")); + return buf; + } + + /* Generate a string describing a numeric bitfield (an N-bit field whose + value is just a number). */ + const char * + decode_numeric_bitfield(guint32 val, guint32 mask, int width, + const char *fmt) + { + static char buf[1025]; + char *p; + + p = decode_bitfield_value(buf, val, mask, width); + sprintf(p, fmt, val & mask); + return buf; } Index: util.h =================================================================== RCS file: /usr/local/cvsroot/ethereal/util.h,v retrieving revision 1.5 diff -c -r1.5 util.h *** util.h 1998/10/16 01:18:35 1.5 --- util.h 1998/12/04 06:10:42 *************** *** 48,53 **** --- 48,62 ---- void simple_dialog_cancel_cb(GtkWidget *, gpointer); + const char *decode_boolean_bitfield(guint32 val, guint32 mask, int width, + const char *truedesc, const char *falsedesc); + + const char *decode_enumerated_bitfield(guint32 val, guint32 mask, int width, + const value_string *tab, const char *fmt); + + const char *decode_numeric_bitfield(guint32 val, guint32 mask, int width, + const char *fmt); + #ifdef __cplusplus } #endif /* __cplusplus */
- Follow-Ups:
- Re: [ethereal-dev] Vines coded expanded
- From: Guy Harris
- Re: [ethereal-dev] Vines coded expanded
- References:
- Re: [ethereal-dev] Vines coded expanded
- From: Guy Harris
- Re: [ethereal-dev] Vines coded expanded
- Prev by Date: [ethereal-dev] Fixes to DNS and NBNS printing checked in
- Next by Date: Re: [ethereal-dev] Vines coded expanded
- Previous by thread: Re: [ethereal-dev] Vines coded expanded
- Next by thread: Re: [ethereal-dev] Vines coded expanded
- Index(es):