ANNOUNCEMENT: Live Wireshark University & Allegro Packets online APAC Wireshark Training Session
July 17th, 2024 | 10:00am-11:55am SGT (UTC+8) | Online

Ethereal-dev: [Ethereal-dev] [PATCH] Hostlist/Conversation list assign wrong addresses to rows

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

From: Ian Schorr <ethereal@xxxxxxxxxxxxx>
Date: Thu, 05 Aug 2004 00:09:23 -0400
Unfortunately my latest patch had a bug, drawing addresses to the wrong rows in the clist. This corrects the problem (and removes the duplicated code that Ulf was nice enough to isolate).

Ian
Index: hostlist_table.c
===================================================================
--- hostlist_table.c	(revision 11602)
+++ hostlist_table.c	(working copy)
@@ -461,7 +461,10 @@
     char *port;
     address_type  at;
     guint32 pt;
+    int rownum;
 
+    rownum=gtk_clist_find_row_from_data(hl->table, (gpointer)hostlist_idx);
+
     at = hl->hosts[hostlist_idx].address.type;
     if(!hl->resolve_names) at = AT_NONE;
     switch(at) {
@@ -474,7 +477,7 @@
     default:
         entry=address_to_str(&hl->hosts[hostlist_idx].address);
     }
-    gtk_clist_set_text(hl->table, hostlist_idx, 0, entry);
+    gtk_clist_set_text(hl->table, rownum, 0, entry);
 
     pt = hl->hosts[hostlist_idx].port_type;
     if(!hl->resolve_names) pt = PT_NONE;
@@ -489,7 +492,7 @@
         port=hostlist_port_to_str(hl->hosts[hostlist_idx].port_type, hl->hosts[hostlist_idx].port);
         entry=port?port:"";
     }
-    gtk_clist_set_text(hl->table, hostlist_idx, 1, entry);
+    gtk_clist_set_text(hl->table, rownum, 1, entry);
 }
 
 /* Refresh the address fields of all entries in the list */
@@ -497,51 +500,9 @@
 draw_hostlist_table_addresses(hostlist_table *hl)
 {
     guint32 i;
-    int j;
 
-
     for(i=0;i<hl->num_hosts;i++){
-#if 0
-        char *entry;
-        char *port;
-        address_type  at;
-        guint32 pt;
-#endif
-
-        j=gtk_clist_find_row_from_data(hl->table, (gpointer)i);
-
-        draw_hostlist_table_address(hl, j);
-
-#if 0
-        at = hl->hosts[i].address.type;
-        if(!hl->resolve_names) at = AT_NONE;
-        switch(at) {
-        case(AT_IPv4):
-            entry=get_hostname((*(guint *)hl->hosts[i].address.data));
-            break;
-        case(AT_ETHER):
-            entry=get_ether_name(hl->hosts[i].address.data);
-            break;
-        default:
-            entry=address_to_str(&hl->hosts[i].address);
-        }
-        gtk_clist_set_text(hl->table, j, 0, entry);
-
-        pt = hl->hosts[i].port_type;
-        if(!hl->resolve_names) pt = PT_NONE;
-        switch(pt) {
-        case(PT_TCP):
-            entry=get_tcp_port(hl->hosts[i].port);
-            break;
-        case(PT_UDP):
-            entry=get_udp_port(hl->hosts[i].port);
-            break;
-        default:
-            port=hostlist_port_to_str(hl->hosts[i].port_type, hl->hosts[i].port);
-            entry=port?port:"";
-        }
-        gtk_clist_set_text(hl->table, j, 1, entry);
-#endif
+        draw_hostlist_table_address(hl, i);
     }
 }
 
Index: conversations_table.c
===================================================================
--- conversations_table.c	(revision 11602)
+++ conversations_table.c	(working copy)
@@ -948,7 +948,10 @@
     char *port;
     address_type  at;
     guint32 pt;
+    int rownum;
 
+    rownum=gtk_clist_find_row_from_data(ct->table, (gpointer)conversation_idx);
+
     at = ct->conversations[conversation_idx].src_address.type;
     if(!ct->resolve_names) at = AT_NONE;
     switch(at) {
@@ -961,7 +964,7 @@
     default:
         entry=address_to_str(&ct->conversations[conversation_idx].src_address);
     }
-    gtk_clist_set_text(ct->table, conversation_idx, 0, entry);
+    gtk_clist_set_text(ct->table, rownum, 0, entry);
 
     pt = ct->conversations[conversation_idx].port_type;
     if(!ct->resolve_names) pt = PT_NONE;
@@ -976,7 +979,7 @@
         port=ct_port_to_str(ct->conversations[conversation_idx].port_type, ct->conversations[conversation_idx].src_port);
         entry=port?port:"";
     }
-    gtk_clist_set_text(ct->table, conversation_idx, 1, entry);
+    gtk_clist_set_text(ct->table, rownum, 1, entry);
 
     at = ct->conversations[conversation_idx].dst_address.type;
     if(!ct->resolve_names) at = AT_NONE;
@@ -990,7 +993,7 @@
     default:
         entry=address_to_str(&ct->conversations[conversation_idx].dst_address);
     }
-    gtk_clist_set_text(ct->table, conversation_idx, 2, entry);
+    gtk_clist_set_text(ct->table, rownum, 2, entry);
 
     switch(pt) {
     case(PT_TCP):
@@ -1003,7 +1006,7 @@
         port=ct_port_to_str(ct->conversations[conversation_idx].port_type, ct->conversations[conversation_idx].dst_port);
         entry=port?port:"";
     }
-    gtk_clist_set_text(ct->table, conversation_idx, 3, entry);
+    gtk_clist_set_text(ct->table, rownum, 3, entry);
 }
 
 /* Refresh the address fields of all entries in the list */
@@ -1011,77 +1014,9 @@
 draw_ct_table_addresses(conversations_table *ct)
 {
     guint32 i;
-    int j;
 
-
     for(i=0;i<ct->num_conversations;i++){
-#if 0
-        char *entry;
-        char *port;
-        address_type  at;
-        guint32 pt;
-#endif
-
-        j=gtk_clist_find_row_from_data(ct->table, (gpointer)i);
-
-        draw_ct_table_address(ct, j);
-#if 0
-        at = ct->conversations[i].src_address.type;
-        if(!ct->resolve_names) at = AT_NONE;
-        switch(at) {
-        case(AT_IPv4):
-            entry=get_hostname((*(guint *)ct->conversations[i].src_address.data));
-            break;
-        case(AT_ETHER):
-            entry=get_ether_name(ct->conversations[i].src_address.data);
-            break;
-        default:
-            entry=address_to_str(&ct->conversations[i].src_address);
-        }
-        gtk_clist_set_text(ct->table, j, 0, entry);
-
-        pt = ct->conversations[i].port_type;
-        if(!ct->resolve_names) pt = PT_NONE;
-        switch(pt) {
-        case(PT_TCP):
-            entry=get_tcp_port(ct->conversations[i].src_port);
-            break;
-        case(PT_UDP):
-            entry=get_udp_port(ct->conversations[i].src_port);
-            break;
-        default:
-            port=ct_port_to_str(ct->conversations[i].port_type, ct->conversations[i].src_port);
-            entry=port?port:"";
-        }
-        gtk_clist_set_text(ct->table, j, 1, entry);
-
-        at = ct->conversations[i].dst_address.type;
-        if(!ct->resolve_names) at = AT_NONE;
-        switch(at) {
-        case(AT_IPv4):
-            entry=get_hostname((*(guint *)ct->conversations[i].dst_address.data));
-            break;
-        case(AT_ETHER):
-            entry=get_ether_name(ct->conversations[i].dst_address.data);
-            break;
-        default:
-            entry=address_to_str(&ct->conversations[i].dst_address);
-        }
-        gtk_clist_set_text(ct->table, j, 2, entry);
-
-        switch(pt) {
-        case(PT_TCP):
-            entry=get_tcp_port(ct->conversations[i].dst_port);
-            break;
-        case(PT_UDP):
-            entry=get_udp_port(ct->conversations[i].dst_port);
-            break;
-        default:
-            port=ct_port_to_str(ct->conversations[i].port_type, ct->conversations[i].dst_port);
-            entry=port?port:"";
-        }
-        gtk_clist_set_text(ct->table, j, 3, entry);
-#endif
+        draw_ct_table_address(ct, i);
     }
 }