GeoIP expects IPv4 addresses in host byte order.
authorGerald Combs <gerald@wireshark.org>
Tue, 23 Dec 2008 18:17:01 +0000 (18:17 -0000)
committerGerald Combs <gerald@wireshark.org>
Tue, 23 Dec 2008 18:17:01 +0000 (18:17 -0000)
svn path=/trunk/; revision=27097

epan/dissectors/packet-ip.c
gtk/hostlist_table.c

index 756d310e2924df5e7a38ff5c40631a24176753df..bd799f7efb7652d2d2500f8c97ee4ce5ad43da06 100644 (file)
@@ -1214,7 +1214,7 @@ dissect_ip(tvbuff_t *tvb, packet_info *pinfo, proto_tree *parent_tree)
 {
   proto_tree *ip_tree = NULL, *field_tree;
   proto_item *ti = NULL, *tf;
-  guint32    src_naddr, dst_naddr;
+  guint32    addr;
   int        offset = 0;
   guint      hlen, optlen;
   guint16    flags;
@@ -1440,13 +1440,13 @@ dissect_ip(tvbuff_t *tvb, packet_info *pinfo, proto_tree *parent_tree)
   if (tree) {
     const char *src_host;
 
-    memcpy(&src_naddr, iph->ip_src.data, 4);
-    src_host = get_hostname(src_naddr);
+    memcpy(&addr, iph->ip_src.data, 4);
+    src_host = get_hostname(addr);
     if (ip_summary_in_tree) {
       proto_item_append_text(ti, ", Src: %s (%s)", src_host, ip_to_str(iph->ip_src.data));
     }
-    proto_tree_add_ipv4(ip_tree, hf_ip_src, tvb, offset + 12, 4, src_naddr);
-    item = proto_tree_add_ipv4(ip_tree, hf_ip_addr, tvb, offset + 12, 4, src_naddr);
+    proto_tree_add_ipv4(ip_tree, hf_ip_src, tvb, offset + 12, 4, addr);
+    item = proto_tree_add_ipv4(ip_tree, hf_ip_addr, tvb, offset + 12, 4, addr);
     PROTO_ITEM_SET_HIDDEN(item);
     item = proto_tree_add_string(ip_tree, hf_ip_src_host, tvb, offset + 12, 4, src_host);
     PROTO_ITEM_SET_GENERATED(item);
@@ -1483,13 +1483,13 @@ dissect_ip(tvbuff_t *tvb, packet_info *pinfo, proto_tree *parent_tree)
   if (tree) {
     const char *dst_host;
 
-    memcpy(&dst_naddr, iph->ip_dst.data, 4);
-    dst_host = get_hostname(dst_naddr);
+    memcpy(&addr, iph->ip_dst.data, 4);
+    dst_host = get_hostname(addr);
     if (ip_summary_in_tree) {
       proto_item_append_text(ti, ", Dst: %s (%s)", dst_host, ip_to_str(iph->ip_dst.data));
     }
-    proto_tree_add_ipv4(ip_tree, hf_ip_dst, tvb, offset + 16, 4, dst_naddr);
-    item = proto_tree_add_ipv4(ip_tree, hf_ip_addr, tvb, offset + 16, 4, dst_naddr);
+    proto_tree_add_ipv4(ip_tree, hf_ip_dst, tvb, offset + 16, 4, addr);
+    item = proto_tree_add_ipv4(ip_tree, hf_ip_addr, tvb, offset + 16, 4, addr);
     PROTO_ITEM_SET_HIDDEN(item);
     item = proto_tree_add_string(ip_tree, hf_ip_dst_host, tvb, offset + 16, 4, dst_host);
     PROTO_ITEM_SET_GENERATED(item);
@@ -1502,8 +1502,8 @@ dissect_ip(tvbuff_t *tvb, packet_info *pinfo, proto_tree *parent_tree)
 #ifdef HAVE_GEOIP
   if (tree && ip_use_geoip) {
     for (dbnum = 0; dbnum < geoip_num_dbs(); dbnum++) {
-      geoip_src_str = geoip_db_lookup_ipv4(dbnum, src_naddr, NULL);
-      geoip_dst_str = geoip_db_lookup_ipv4(dbnum, dst_naddr, NULL);
+      geoip_src_str = geoip_db_lookup_ipv4(dbnum, src32, NULL);
+      geoip_dst_str = geoip_db_lookup_ipv4(dbnum, dst32, NULL);
 
       switch (geoip_db_type(dbnum)) {
         case GEOIP_COUNTRY_EDITION:
index e7f9c9863c7f89cc4333e9ddea41cc2fbc184f4f..c28321e1bec3e86cd6e10c7fa72a498437db20c1 100644 (file)
@@ -41,6 +41,7 @@
 #include <epan/strutil.h>
 #ifdef HAVE_GEOIP
 #include <epan/geoip_db.h>
+#include <epan/pint.h>
 #endif
 
 #include "../simple_dialog.h"
@@ -1108,7 +1109,7 @@ add_hostlist_table_data(hostlist_table *hl, const address *addr, guint32 port, g
         /* Filled in from the GeoIP config, if any */
         for (i = 0; i < NUM_GEOIP_COLS; i++) {
             if (i < geoip_num_dbs() && talker->address.type == AT_IPv4) {
-                const guchar *name = geoip_db_lookup_ipv4(i, *(guint32*)talker->address.data, "-");
+                const guchar *name = geoip_db_lookup_ipv4(i, pntohl(talker->address.data), "-");
                 g_snprintf(geoip[i], COL_STR_LEN, "%s", format_text (name, strlen(name)));
                 entries[NUM_BUILTIN_COLS + i] = geoip[i];
                 gtk_clist_set_column_visibility(hl->table, NUM_BUILTIN_COLS + i, TRUE);