Add a "get_addr_name()" routine that takes an "address *" and attempts
authorguy <guy@f5534014-38df-0310-8fa8-9805f1628bb7>
Thu, 30 Dec 2004 02:10:24 +0000 (02:10 +0000)
committerguy <guy@f5534014-38df-0310-8fa8-9805f1628bb7>
Thu, 30 Dec 2004 02:10:24 +0000 (02:10 +0000)
to resolve it to a name.

Fix up some const-pointer-to-non-const-pointer, and
function-pointer-to-void-*, conversions.

Fix some comments.

git-svn-id: http://anonsvn.wireshark.org/wireshark/trunk@12863 f5534014-38df-0310-8fa8-9805f1628bb7

epan/addr_resolv.c
epan/addr_resolv.h
epan/column-utils.c
epan/dissectors/packet-aoe.c
epan/prefs.c
epan/tap.c
epan/tap.h
gtk/conversations_table.c
gtk/hostlist_table.c
util.c

index f31b72cbc1ed9e245ecf0d358d6d083831980a6d..1b4503859d6b29bf251668d680ea3509c0ffd4d3 100644 (file)
@@ -1869,6 +1869,32 @@ extern gchar *get_sctp_port(guint port)
 
 } /* get_sctp_port */
 
+const gchar *get_addr_name(address *addr)
+{
+  guint32 ipv4_addr;
+  struct e_in6_addr ipv6_addr;
+
+  switch (addr->type) {
+
+  case AT_ETHER:
+    return get_ether_name(addr->data);
+
+  case AT_IPv4:
+    memcpy(&ipv4_addr, addr->data, sizeof ipv4_addr);
+    return get_hostname(ipv4_addr);
+
+  case AT_IPv6:
+    memcpy(&ipv6_addr.s6_addr, addr->data, sizeof ipv6_addr.s6_addr);
+    return get_hostname6(&ipv6_addr);
+
+  case AT_STRINGZ:
+    return addr->data;
+
+  default:
+    return NULL;
+  }
+}
+
 extern gchar *get_ether_name(const guint8 *addr)
 {
   if (!(g_resolv_flags & RESOLV_MAC))
index 05b6877e28738f833df6e65345c505773ad5b4b5..8c37ab3272ca7065434a60e2e1c967cd037452cb 100644 (file)
@@ -60,15 +60,33 @@ extern gchar *g_pipxnets_path;
 /* Set the flags controlling what names to resolve */
 extern void resolv_set_flags(guint32 flags);
 
-/* get_tcp_port returns the UDP port name or "%u" if not found */
+/*
+ * get_udp_port() returns the port name corresponding to that UDP port,
+ * or the port number as a string if not found.
+ */
 extern gchar *get_udp_port(guint port);
 
-/* get_tcp_port returns the TCP port name or "%u" if not found */
+/*
+ * get_tcp_port() returns the port name corresponding to that TCP port,
+ * or the port number as a string if not found.
+ */
 extern gchar *get_tcp_port(guint port);
 
-/* get_sctp_port returns the SCTP port name or "%u" if not found */
+/*
+ * get_sctp_port() returns the port name corresponding to that SCTP port,
+ * or the port number as a string if not found.
+ */
 extern gchar *get_sctp_port(guint port);
 
+/*
+ * For address types that support name resolution, and for AT_STRINGZ,
+ * "get_addr_name()" returns the name corresponding to the address,
+ * or a string for the address if not found.
+ *
+ * For other address types, it returns a null pointer.
+ */
+const gchar *get_addr_name(address *addr);
+
 /*
  * Asynchronous host name lookup initialization, processing, and cleanup
  */
index ecf245c6dc3110ee0a4dd81b76c8b80455b25297..8851fce7f18d0a24e5917a8ae94842a4b8bedd06 100644 (file)
@@ -574,7 +574,7 @@ static void
 col_set_addr(packet_info *pinfo, int col, address *addr, gboolean is_res,
             gboolean is_src)
 {
-  guint32 ipv4_addr;
+  const char *addr_string;
   struct e_in6_addr ipv6_addr;
 
   pinfo->cinfo->col_expr[col][0] = '\0';
@@ -582,37 +582,12 @@ col_set_addr(packet_info *pinfo, int col, address *addr, gboolean is_res,
   if (addr->type == AT_NONE)
     return;    /* no address, nothing to do */
   if (is_res) {
-    switch (addr->type) {
-
-    case AT_ETHER:
-      strncpy(pinfo->cinfo->col_buf[col], get_ether_name(addr->data), COL_MAX_LEN);
-      pinfo->cinfo->col_buf[col][COL_MAX_LEN - 1] = '\0';
-      break;
-
-    case AT_IPv4:
-      memcpy(&ipv4_addr, addr->data, sizeof ipv4_addr);
-      strncpy(pinfo->cinfo->col_buf[col], get_hostname(ipv4_addr), COL_MAX_LEN);
+    addr_string = get_addr_name(addr);
+    if (addr_string != NULL) {
+      strncpy(pinfo->cinfo->col_buf[col], addr_string, COL_MAX_LEN);
       pinfo->cinfo->col_buf[col][COL_MAX_LEN - 1] = '\0';
-      break;
-
-    case AT_IPv6:
-      memcpy(&ipv6_addr.s6_addr, addr->data, sizeof ipv6_addr.s6_addr);
-      strncpy(pinfo->cinfo->col_buf[col], get_hostname6(&ipv6_addr), COL_MAX_LEN);
-      pinfo->cinfo->col_buf[col][COL_MAX_LEN - 1] = '\0';
-      break;
-
-    case AT_STRINGZ:
-      /* XXX - should be done in "address_to_str_buf()", but that routine
-         doesn't know COL_MAX_LEN; it should be changed to take the
-         maximum length as an argument. */
-      strncpy(pinfo->cinfo->col_buf[col], addr->data, COL_MAX_LEN);
-      pinfo->cinfo->col_buf[col][COL_MAX_LEN - 1] = '\0';
-      break;
-
-    default:
+    } else
       address_to_str_buf(addr, pinfo->cinfo->col_buf[col]);
-      break;
-    }
   } else {
     switch (addr->type) {
 
index 4fdb9e4d3a65e8979a94a52d2c27f2ca0834ff9f..0a6196a9daebcc47ec3ad3aa6e66037fcb30618c 100644 (file)
@@ -202,7 +202,7 @@ ata_cmd_equal_matched(gconstpointer k1, gconstpointer k2)
 static guint
 ata_cmd_hash_unmatched(gconstpointer k)
 {
-  ata_info_t *key = (ata_info_t *)k;
+  const ata_info_t *key = (ata_info_t *)k;
 
   return key->tag;
 }
@@ -210,8 +210,8 @@ ata_cmd_hash_unmatched(gconstpointer k)
 static gint
 ata_cmd_equal_unmatched(gconstpointer k1, gconstpointer k2)
 {
-  ata_info_t *key1 = (ata_info_t *)k1;
-  ata_info_t *key2 = (ata_info_t *)k2;
+  const ata_info_t *key1 = (ata_info_t *)k1;
+  const ata_info_t *key2 = (ata_info_t *)k2;
 
   return (key1->tag==key2->tag)&&(key1->conversation==key2->conversation);
 }
index 9a41a77afd7ad82dbbfb8ed38de66abf9147b947..35f9533420f1788d5f53a437cec9cd9bbdfed837 100644 (file)
@@ -38,6 +38,7 @@
 #include <glib.h>
 
 #include <epan/filesystem.h>
+#include <epan/address.h>
 #include <epan/addr_resolv.h>
 #include <epan/packet.h>
 #include <epan/prefs.h>
index e73ab58a6f0464b15d7ad5e8de2c3eefbe71061d..60ee22e19550ffe00f58e5e648d0a2a78a65391c 100644 (file)
@@ -61,7 +61,7 @@ typedef struct _tap_packet_t {
        struct _tap_packet_t *next;
        int tap_id;
        packet_info *pinfo;
-       void *tap_specific_data;
+       const void *tap_specific_data;
 } tap_packet_t;
 static tap_packet_t *tap_packet_list_free=NULL;
 static tap_packet_t *tap_packet_list_queue=NULL;
@@ -167,7 +167,7 @@ register_tap(char *name)
    to by the tap specific data pointer.
 */
 void 
-tap_queue_packet(int tap_id, packet_info *pinfo, void *tap_specific_data)
+tap_queue_packet(int tap_id, packet_info *pinfo, const void *tap_specific_data)
 {
        tap_packet_t *tpt;
 
index 491ed3cae57c348f5cb545a05a5315f05907b4ad..4ecb1fb91ddb9fc26710393e651df0e0c77b9ab8 100644 (file)
@@ -40,7 +40,7 @@ typedef void (*tap_draw_cb)(void *tapdata);
 extern void tap_init(void);
 extern int register_tap(char *name);
 extern int find_tap_id(char *name);
-extern void tap_queue_packet(int tap_id, packet_info *pinfo, void *tap_specific_data);
+extern void tap_queue_packet(int tap_id, packet_info *pinfo, const void *tap_specific_data);
 extern void tap_queue_init(epan_dissect_t *edt);
 extern void tap_push_tapped_queue(epan_dissect_t *edt);
 extern void reset_tap_listeners(void);
index 325f19c4707f3401741945d8c47ad31abea8d158..7fa58b5ee67aa482adec036bc5ee67a7a795dd34 100644 (file)
@@ -944,25 +944,19 @@ ct_create_popup_menu(conversations_table *ct)
 static void
 draw_ct_table_address(conversations_table *ct, int conversation_idx)
 {
-    char *entry;
+    const char *entry;
     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) {
-    case(AT_IPv4):
-        entry=get_hostname((*(guint *)ct->conversations[conversation_idx].src_address.data));
-        break;
-    case(AT_ETHER):
-        entry=get_ether_name(ct->conversations[conversation_idx].src_address.data);
-        break;
-    default:
+    if(!ct->resolve_names)
         entry=address_to_str(&ct->conversations[conversation_idx].src_address);
+    else {
+        entry=get_addr_name(&ct->conversations[conversation_idx].src_address.data);
+        if(!entry)
+            entry=address_to_str(&ct->conversations[conversation_idx].src_address);
     }
     gtk_clist_set_text(ct->table, rownum, 0, entry);
 
@@ -981,17 +975,12 @@ draw_ct_table_address(conversations_table *ct, int conversation_idx)
     }
     gtk_clist_set_text(ct->table, rownum, 1, entry);
 
-    at = ct->conversations[conversation_idx].dst_address.type;
-    if(!ct->resolve_names) at = AT_NONE;
-    switch(at) {
-    case(AT_IPv4):
-        entry=get_hostname((*(guint *)ct->conversations[conversation_idx].dst_address.data));
-        break;
-    case(AT_ETHER):
-        entry=get_ether_name(ct->conversations[conversation_idx].dst_address.data);
-        break;
-    default:
+    if(!ct->resolve_names)
         entry=address_to_str(&ct->conversations[conversation_idx].dst_address);
+    else {
+        entry=get_addr_name(&ct->conversations[conversation_idx].dst_address.data);
+        if(!entry)
+            entry=address_to_str(&ct->conversations[conversation_idx].dst_address);
     }
     gtk_clist_set_text(ct->table, rownum, 2, entry);
 
index 84e3cc4589b4702e10c96f871960a7615880c684..afe9540c3ee3d9c5036b4a27b0997ce1c0cd679c 100644 (file)
@@ -194,8 +194,8 @@ hostlist_sort_column(GtkCList *clist, gconstpointer ptr1, gconstpointer ptr2)
        char *text2 = NULL;
        int i1, i2;
 
-       GtkCListRow *row1 = (GtkCListRow *) ptr1;
-       GtkCListRow *row2 = (GtkCListRow *) ptr2;
+       const GtkCListRow *row1 = ptr1;
+       const GtkCListRow *row2 = ptr2;
 
        text1 = GTK_CELL_TEXT (row1->cell[clist->sort_column])->text;
        text2 = GTK_CELL_TEXT (row2->cell[clist->sort_column])->text;
@@ -457,25 +457,19 @@ hostlist_create_popup_menu(hostlist_table *hl)
 static void
 draw_hostlist_table_address(hostlist_table *hl, int hostlist_idx)
 {
-    char *entry;
+    const char *entry;
     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) {
-    case(AT_IPv4):
-        entry=get_hostname((*(guint *)hl->hosts[hostlist_idx].address.data));
-        break;
-    case(AT_ETHER):
-        entry=get_ether_name(hl->hosts[hostlist_idx].address.data);
-        break;
-    default:
+    if(!hl->resolve_names)
         entry=address_to_str(&hl->hosts[hostlist_idx].address);
+    else {
+        entry=get_addr_name(&hl->hosts[hostlist_idx].address);
+        if(!entry)
+            entry=address_to_str(&hl->hosts[hostlist_idx].address);
     }
     gtk_clist_set_text(hl->table, rownum, 0, entry);
 
diff --git a/util.c b/util.c
index 807e5aa029449ce79d2632786fb1732147646148..7b61d1b3f1e35967f664f10a32b309e8195b6e94 100644 (file)
--- a/util.c
+++ b/util.c
@@ -56,6 +56,7 @@ typedef int mode_t;   /* for win32 */
 #endif /* __MINGW32__ */
 #endif /* HAVE_IO_H */
 
+#include <epan/address.h>
 #include <epan/addr_resolv.h>
 
 /*