summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--acinclude.m430
-rw-r--r--configure.in25
-rw-r--r--epan/Makefile.am5
-rw-r--r--epan/Makefile.common2
-rw-r--r--epan/epan.c7
-rw-r--r--epan/geoip.c256
-rw-r--r--epan/geoip.h59
-rw-r--r--gtk/hostlist_table.c137
-rw-r--r--gtk/hostlist_table.h16
-rw-r--r--gtk/prefs_nameres.c93
10 files changed, 550 insertions, 80 deletions
diff --git a/acinclude.m4 b/acinclude.m4
index d2ef5a59e5..794ed097f7 100644
--- a/acinclude.m4
+++ b/acinclude.m4
@@ -1542,6 +1542,36 @@ AC_DEFUN([AC_WIRESHARK_KRB5_CHECK],
])
#
+# AC_WIRESHARK_GEOIP_CHECK
+#
+AC_DEFUN([AC_WIRESHARK_GEOIP_CHECK],
+[
+ want_geoip=defaultyes
+
+ if test "x$want_geoip" = "xdefaultyes"; then
+ want_geoip=yes
+ if test "x$ac_cv_enable_usr_local" = "xyes" ; then
+ withval=/usr/local
+ if test -d "$withval"; then
+ AC_WIRESHARK_ADD_DASH_L(LDFLAGS, ${withval}/lib)
+ fi
+ fi
+ fi
+
+ if test "x$want_geoip" = "xyes"; then
+ AC_CHECK_LIB(GeoIP, GeoIP_new,
+ [
+ GEOIP_LIBS=-lGeoIP
+ AC_DEFINE(HAVE_GEOIP, 1, [Define to use GeoIP library])
+ have_good_geoip=yes
+ ],,
+ )
+ else
+ AC_MSG_RESULT(not required)
+ fi
+])
+
+#
# AC_WIRESHARK_GCC_CFLAGS_CHECK
#
# $1 : cflags to test
diff --git a/configure.in b/configure.in
index 9a432a6b03..8c44d5b171 100644
--- a/configure.in
+++ b/configure.in
@@ -1293,6 +1293,31 @@ else
fi
AC_SUBST(ADNS_LIBS)
+dnl GEOIP Check
+GEOIP_LIBS=''
+AC_MSG_CHECKING(whether to use the GeoIP IP address mapping library if available)
+
+AC_ARG_WITH(geoip,
+ AC_HELP_STRING( [--with-geoip@<:@=DIR@:>@],
+ [use GeoIP (located in directory DIR, if supplied). @<:@default=yes, if present@:>@]),
+[
+if test "x$withval" = "xno"; then
+ want_geoip=no
+elif test "x$withval" = "xyes"; then
+ want_geoip=yes
+elif test -d "$withval"; then
+ want_geoip=yes
+ AC_WIRESHARK_ADD_DASH_L(LDFLAGS, ${withval}/lib)
+fi
+])
+if test "x$want_geoip" = "xno"; then
+ AC_MSG_RESULT(no)
+else
+ AC_MSG_RESULT(yes)
+ AC_WIRESHARK_GEOIP_CHECK
+fi
+AC_SUBST(GEOIP_LIBS)
+
#
# Define WS_VAR_IMPORT appropriately for declarations of external
# variables exported from dynamically-linked libraries.
diff --git a/epan/Makefile.am b/epan/Makefile.am
index 60a8908bbb..a214e95f7c 100644
--- a/epan/Makefile.am
+++ b/epan/Makefile.am
@@ -48,7 +48,8 @@ libwireshark_la_LDFLAGS = -version-info 0:1:0 @LDFLAGS_SHAREDLIB@
include Makefile.common
INCLUDES = -I$(srcdir)/.. -I$(srcdir)/$(LEMON) @LUA_INCLUDES@ \
- $(LIBGNUTLS_CFLAGS) $(LIBGCRYPT_CFLAGS) $(LIBSMI_CFLAGS)
+ $(LIBGNUTLS_CFLAGS) $(LIBGCRYPT_CFLAGS) $(LIBSMI_CFLAGS) \
+ $(LIBGEOIP_CFLAGS)
if HAVE_WARNINGS_AS_ERRORS
@@ -128,7 +129,7 @@ libwireshark_la_LIBADD = \
dfilter/libdfilter.la dissectors/libdissectors.la \
dissectors/libdirtydissectors.la $(wslua_lib) @SOCKET_LIBS@ @NSL_LIBS@ \
@C_ARES_LIBS@ @ADNS_LIBS@ @LIBGCRYPT_LIBS@ @LIBGNUTLS_LIBS@ \
- @KRB5_LIBS@ @SSL_LIBS@ @LIBSMI_LDFLAGS@ \
+ @KRB5_LIBS@ @SSL_LIBS@ @LIBSMI_LDFLAGS@ @GEOIP_LIBS@ \
${top_builddir}/wsutil/libwsutil.la -lm
libwireshark_la_DEPENDENCIES = \
diff --git a/epan/Makefile.common b/epan/Makefile.common
index eb044e648d..6529e792fc 100644
--- a/epan/Makefile.common
+++ b/epan/Makefile.common
@@ -56,6 +56,7 @@ LIBWIRESHARK_SRC = \
frequency-utils.c \
funnel.c \
gcp.c \
+ geoip.c \
golay.c \
guid-utils.c \
h225-persistentdata.c \
@@ -172,6 +173,7 @@ LIBWIRESHARK_INCLUDES = \
funnel.h \
garrayfix.h \
gcp.h \
+ geoip.h \
golay.h \
gnuc_format_check.h \
greproto.h \
diff --git a/epan/epan.c b/epan/epan.c
index 336530fa19..22f3940aff 100644
--- a/epan/epan.c
+++ b/epan/epan.c
@@ -59,6 +59,10 @@
int wslua_init(void*);
#endif
+#ifdef HAVE_GEOIP
+#include "geoip.h"
+#endif
+
gchar*
epan_get_version(void) {
return VERSION;
@@ -102,6 +106,9 @@ epan_init(void (*register_all_protocols_func)(register_cb cb, gpointer client_da
#ifdef HAVE_LUA_5_1
wslua_init(NULL);
#endif
+#ifdef HAVE_GEOIP
+ geoip_init();
+#endif
}
diff --git a/epan/geoip.c b/epan/geoip.c
new file mode 100644
index 0000000000..4e24e91019
--- /dev/null
+++ b/epan/geoip.c
@@ -0,0 +1,256 @@
+/* geoip.c
+ * GeoIP database support
+ *
+ * Copyright 2008, Gerald Combs <gerald@wireshark.org>
+ *
+ * $Id$
+ *
+ * Wireshark - Network traffic analyzer
+ * By Gerald Combs <gerald@wireshark.org>
+ * Copyright 1998 Gerald Combs
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ */
+
+/* To do:
+ * We currently return a single string for each database. Some databases,
+ * e.g. GeoIPCity, can return other info such as area codes.
+ */
+
+#ifdef HAVE_CONFIG_H
+# include "config.h"
+#endif
+
+#include <glib.h>
+
+#ifdef HAVE_GEOIP
+#include "GeoIP.h"
+#include "GeoIPCity.h"
+
+#include "geoip.h"
+#include "uat.h"
+#include "prefs.h"
+#include "report_err.h"
+#include "value_string.h"
+#include <wsutil/file_util.h>
+
+/* This needs to match NUM_GEOIP_COLS in hostlist_table.h */
+#define MAX_GEOIP_DBS 8
+
+/* Column names for each database type */
+value_string geoip_type_name_vals[] = {
+ { GEOIP_COUNTRY_EDITION, "Country" },
+ { GEOIP_REGION_EDITION_REV0, "Region" },
+ { GEOIP_CITY_EDITION_REV0, "City" },
+ { GEOIP_ORG_EDITION, "Organization" },
+ { GEOIP_ISP_EDITION, "ISP" },
+ { GEOIP_CITY_EDITION_REV1, "City" },
+ { GEOIP_REGION_EDITION_REV1, "Region" },
+ { GEOIP_PROXY_EDITION, "Proxy" },
+ { GEOIP_ASNUM_EDITION, "AS Number" },
+ { GEOIP_NETSPEED_EDITION, "Speed" },
+ { GEOIP_DOMAIN_EDITION, "Domain" },
+ { 0, NULL }
+};
+
+static GArray *geoip_dat_arr = NULL;
+
+/* UAT definitions. Copied from oids.c */
+typedef struct _geoip_db_path_t {
+ char* path;
+} geoip_db_path_t;
+
+static geoip_db_path_t *geoip_db_paths = NULL;
+static guint num_geoip_db_paths = 0;
+static uat_t *geoip_db_paths_uat = NULL;
+UAT_CSTRING_CB_DEF(geoip_mod, path, geoip_db_path_t)
+
+
+/**
+ * Scan a directory for GeoIP databases and load them
+ */
+static void
+geoip_dat_scan_dir(const char *dirname) {
+ WS_DIR *dir;
+ WS_DIRENT *file;
+ const char *name;
+ char *datname;
+ GeoIP *gi;
+
+ if ((dir = ws_dir_open(dirname, 0, NULL)) != NULL) {
+ while ((file = ws_dir_read_name(dir)) != NULL) {
+ name = ws_dir_get_name(file);
+ if (g_str_has_prefix(file, "Geo") && g_str_has_suffix(file, ".dat")) {
+ datname = g_strdup_printf("%s" G_DIR_SEPARATOR_S "%s", dirname, name);
+ gi = GeoIP_open(datname, GEOIP_MEMORY_CACHE);
+ if (gi) {
+ g_array_append_val(geoip_dat_arr, gi);
+ }
+ g_free(datname);
+ }
+ }
+ }
+}
+
+/* UAT callbacks */
+static void* geoip_path_copy_cb(void* dest, const void* orig, unsigned len _U_) {
+ const geoip_db_path_t *m = orig;
+ geoip_db_path_t *d = dest;
+
+ d->path = g_strdup(m->path);
+
+ return d;
+}
+
+static void geoip_path_free_cb(void* p) {
+ geoip_db_path_t *m = p;
+ if (m->path) g_free(m->path);
+}
+
+/**
+ * Initialize GeoIP lookups
+ */
+void
+geoip_init(void) {
+ int i;
+ static uat_field_t geoip_db_paths_fields[] = {
+ UAT_FLD_CSTRING(geoip_mod, path, "The database path"),
+ UAT_END_FIELDS
+ };
+ char* geoip_load_error = NULL;
+
+ geoip_dat_arr = g_array_new(FALSE, FALSE, sizeof(GeoIP *));
+
+ geoip_db_paths_uat = uat_new("GeoIP Database Paths",
+ sizeof(geoip_db_path_t),
+ "geoip_db_paths",
+ FALSE,
+ (void*)&geoip_db_paths,
+ &num_geoip_db_paths,
+ UAT_CAT_GENERAL,
+ "ChGeoIPDbPaths",
+ geoip_path_copy_cb,
+ NULL,
+ geoip_path_free_cb,
+ geoip_db_paths_fields);
+
+ uat_load(geoip_db_paths_uat, &geoip_load_error);
+
+ if (geoip_load_error) {
+ report_failure("Error loading GeoIP database path table: %s", geoip_load_error);
+ return;
+ }
+
+ for (i = 0; i < num_geoip_db_paths; i++) {
+ if (geoip_db_paths_fields[i].path) {
+ geoip_dat_scan_dir(geoip_db_paths_fields[i].path);
+ }
+ }
+
+}
+
+guint
+geoip_num_dbs(void) {
+ return geoip_dat_arr->len;
+}
+
+const gchar *
+geoip_db_name(guint dbnum) {
+ GeoIP *gi;
+
+ gi = g_array_index(geoip_dat_arr, GeoIP *, dbnum);
+ if (gi) {
+ return (val_to_str(gi->databaseType, geoip_type_name_vals, "Unknown database"));
+ }
+ return "Invalid database";
+}
+
+#define VAL_STR_LEN 100
+const char *
+geoip_db_lookup_ipv4(guint dbnum, guint32 addr) {
+ GeoIP *gi;
+ GeoIPRecord *gir;
+ const char *ret = NULL;
+ static char val[VAL_STR_LEN];
+
+ g_snprintf(val, VAL_STR_LEN, "-");
+ gi = g_array_index(geoip_dat_arr, GeoIP *, dbnum);
+ if (gi) {
+ switch (gi->databaseType) {
+ case GEOIP_COUNTRY_EDITION:
+ ret = GeoIP_country_name_by_ipnum(gi, addr);
+ break;
+
+ case GEOIP_CITY_EDITION_REV0:
+ case GEOIP_CITY_EDITION_REV1:
+ gir = GeoIP_record_by_ipnum(gi, addr);
+ if (gir && gir->city && gir->region) {
+ g_snprintf(val, VAL_STR_LEN, "%s, %s", gir->city, gir->region);
+ } else if (gir && gir->city) {
+ g_snprintf(val, VAL_STR_LEN, "%s", gir->city);
+ }
+ break;
+
+ case GEOIP_ORG_EDITION:
+ case GEOIP_ISP_EDITION:
+ case GEOIP_ASNUM_EDITION:
+ ret = GeoIP_name_by_ipnum(gi, addr);
+ break;
+
+ default:
+ ret = "Unsupported db type";
+ }
+ if (ret) {
+ g_snprintf (val, VAL_STR_LEN, "%s", ret);
+ }
+ return val;
+ }
+ return "Invalid database";
+}
+
+#else /* HAVE_GEOIP */
+void
+geoip_init(void) {}
+
+guint
+geoip_num_dbs(void) {
+ return 0;
+}
+
+const gchar *
+geoip_db_name(guint dbnum _U_) {
+ return "Unsupported";
+}
+
+const char *
+geoip_db_lookup_ipv4(guint dbnum _U_, guint32 addr _U_) {
+ return "";
+}
+
+#endif /* HAVE_GEOIP */
+
+/*
+ * Editor modelines
+ *
+ * Local Variables:
+ * c-basic-offset: 4
+ * tab-width: 4
+ * indent-tabs-mode: t
+ * End:
+ *
+ * ex: set shiftwidth=4 tabstop=4 noexpandtab
+ * :indentSize=4:tabSize=4:noTabs=false:
+ */
+
diff --git a/epan/geoip.h b/epan/geoip.h
new file mode 100644
index 0000000000..b8e4b29490
--- /dev/null
+++ b/epan/geoip.h
@@ -0,0 +1,59 @@
+/* geoip.h
+ * GeoIP database support
+ *
+ * $Id$
+ *
+ * Copyright 2008, Gerald Combs <gerald@wireshark.org>
+ *
+ * Wireshark - Network traffic analyzer
+ * By Gerald Combs <gerald@wireshark.org>
+ * Copyright 1998 Gerald Combs
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ */
+
+#ifndef __GEOIP_H__
+#define __GEOIP_H__
+
+/**
+ * Init function called from epan.h
+ */
+extern void geoip_init(void);
+
+/**
+ * Number of databases we have loaded
+ *
+ * @return The number GeoIP databases successfully loaded
+ */
+extern guint geoip_num_dbs(void);
+
+/**
+ * Fetch the name of a database
+ *
+ * @param dbnum Database index
+ * @return The number GeoIP databases successfully loaded
+ */
+const gchar *geoip_db_name(guint dbnum);
+
+/**
+ * Look up an IPv4 address in a database
+ *
+ * @param dbnum Database index
+ * @param addr IPv4 address to look up
+ * @return The number GeoIP databases successfully loaded
+ */
+const char *geoip_db_lookup_ipv4(guint dbnum, guint32 addr);
+
+#endif /* __GEOIP_H__ */
diff --git a/gtk/hostlist_table.c b/gtk/hostlist_table.c
index 6ab18bc58b..45034f7e16 100644
--- a/gtk/hostlist_table.c
+++ b/gtk/hostlist_table.c
@@ -38,6 +38,9 @@
#include <epan/to_str.h>
#include <epan/addr_resolv.h>
#include <epan/tap.h>
+#ifdef HAVE_GEOIP
+#include <epan/geoip.h>
+#endif
#include "../simple_dialog.h"
#include "../globals.h"
@@ -56,7 +59,6 @@
#include "image/clist_descend.xpm"
-#define NUM_COLS 8
#define HOST_PTR_KEY "hostlist-pointer"
#define NB_PAGES_KEY "notebook-pages"
@@ -240,40 +242,37 @@ hostlist_win_destroy_cb(GtkWindow *win _U_, gpointer data)
static gint
hostlist_sort_column(GtkCList *clist, gconstpointer ptr1, gconstpointer ptr2)
{
- char *text1 = NULL;
- char *text2 = NULL;
- guint64 i1, i2;
-
- 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;
-
- switch(clist->sort_column){
- case 0: /* Address */
- case 1: /* (Port) */
- return strcmp (text1, text2);
- case 2: /* Packets */
- case 3: /* Bytes */
- case 4: /* Tx Packets */
- case 5: /* Tx Bytes */
- case 6: /* Rx Packets */
- case 7: /* Rx Bytes */
- sscanf(text1, "%" G_GINT64_MODIFIER "u", &i1);
- sscanf(text2, "%" G_GINT64_MODIFIER "u", &i2);
- /* XXX - this might cause trouble because of overflow problems */
- /* XXX - is this correct anyway? Subtracting two unsigned values will still be an unsigned value, which will never become negative */
- return (gint) (i1-i2);
- }
- g_assert_not_reached();
+ char *text1 = NULL;
+ char *text2 = NULL;
+ guint64 i1, i2;
+
+ 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;
+
+ if (clist->sort_column < 2 || clist->sort_column > 7) { /* Integers */
+ sscanf(text1, "%" G_GINT64_MODIFIER "u", &i1);
+ sscanf(text2, "%" G_GINT64_MODIFIER "u", &i2);
+ if (i1 > i2) {
+ return 1;
+ } else if (i1 < i2) {
+ return -1;
+ } else {
+ return 0;
+ }
+ } else { /* Strings */
+ return strcmp (text1, text2);
+ }
+ g_assert_not_reached();
- /* Allow clist to redraw */
+ /* Allow clist to redraw */
- gtk_clist_thaw(clist);
- gtk_clist_freeze(clist);
+ gtk_clist_thaw(clist);
+ gtk_clist_freeze(clist);
- return 0;
+ return 0;
}
static void
@@ -282,7 +281,7 @@ hostlist_click_column_cb(GtkCList *clist, gint column, gpointer data)
column_arrows *col_arrows = (column_arrows *) data;
int i;
- for (i = 0; i < NUM_COLS; i++) {
+ for (i = 0; i < NUM_HOSTLIST_COLS; i++) {
gtk_widget_hide(col_arrows[i].ascend_pm);
gtk_widget_hide(col_arrows[i].descend_pm);
}
@@ -444,7 +443,7 @@ draw_hostlist_table_address(hostlist_table *hl, int hostlist_idx)
else
entry=get_addr_name(&hl->hosts[hostlist_idx].address);
- gtk_clist_set_text(hl->table, rownum, 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;
@@ -583,22 +582,33 @@ copy_as_csv_cb(GtkWindow *copy_bt, gpointer data _U_)
static gboolean
init_hostlist_table_page(hostlist_table *hosttable, GtkWidget *vbox, gboolean hide_ports, const char *table_name, const char *tap_name, const char *filter, tap_packet_cb packet_func)
{
- int i;
+ guint i;
column_arrows *col_arrows;
GtkStyle *win_style;
GtkWidget *column_lb;
GString *error_string;
char title[256];
- hosttable->num_columns=NUM_COLS;
- hosttable->default_titles[0] = "Address";
- hosttable->default_titles[1] = "Port";
- hosttable->default_titles[2] = "Packets";
- hosttable->default_titles[3] = "Bytes";
- hosttable->default_titles[4] = "Tx Packets";
- hosttable->default_titles[5] = "Tx Bytes";
- hosttable->default_titles[6] = "Rx Packets";
- hosttable->default_titles[7] = "Rx Bytes";
+ hosttable->num_columns=NUM_HOSTLIST_COLS;
+ hosttable->default_titles[0] = "Address";
+ hosttable->default_titles[1] = "Port";
+ hosttable->default_titles[2] = "Packets";
+ hosttable->default_titles[3] = "Bytes";
+ hosttable->default_titles[4] = "Tx Packets";
+ hosttable->default_titles[5] = "Tx Bytes";
+ hosttable->default_titles[6] = "Rx Packets";
+ hosttable->default_titles[7] = "Rx Bytes";
+
+#ifdef HAVE_GEOIP
+ for (i = 0; i < NUM_GEOIP_COLS; i++) {
+ if (i < geoip_num_dbs()) {
+ hosttable->default_titles[NUM_BUILTIN_COLS + i] = geoip_db_name(i);
+ } else {
+ hosttable->default_titles[NUM_BUILTIN_COLS + i] = "";
+ }
+ }
+#endif /* HAVE_GEOIP */
+
if (strcmp(table_name, "NCP")==0) {
hosttable->default_titles[1] = "Connection";
}
@@ -615,11 +625,11 @@ init_hostlist_table_page(hostlist_table *hosttable, GtkWidget *vbox, gboolean hi
hosttable->scrolled_window=scrolled_window_new(NULL, NULL);
gtk_box_pack_start(GTK_BOX(vbox), hosttable->scrolled_window, TRUE, TRUE, 0);
- hosttable->table=(GtkCList *)gtk_clist_new(NUM_COLS);
+ hosttable->table=(GtkCList *)gtk_clist_new(NUM_HOSTLIST_COLS);
- col_arrows = (column_arrows *) g_malloc(sizeof(column_arrows) * NUM_COLS);
+ col_arrows = (column_arrows *) g_malloc(sizeof(column_arrows) * NUM_HOSTLIST_COLS);
win_style = gtk_widget_get_style(hosttable->scrolled_window);
- for (i = 0; i < NUM_COLS; i++) {
+ for (i = 0; i < NUM_HOSTLIST_COLS; i++) {
col_arrows[i].table = gtk_table_new(2, 2, FALSE);
gtk_table_set_col_spacings(GTK_TABLE(col_arrows[i].table), 5);
column_lb = gtk_label_new(hosttable->default_titles[i]);
@@ -643,7 +653,7 @@ init_hostlist_table_page(hostlist_table *hosttable, GtkWidget *vbox, gboolean hi
gtk_clist_set_sort_column(hosttable->table, 4);
gtk_clist_set_sort_type(hosttable->table, GTK_SORT_DESCENDING);
- for (i = 0; i < NUM_COLS; i++) {
+ for (i = 0; i < NUM_HOSTLIST_COLS; i++) {
gtk_clist_set_column_auto_resize(hosttable->table, i, TRUE);
}
@@ -661,6 +671,13 @@ init_hostlist_table_page(hostlist_table *hosttable, GtkWidget *vbox, gboolean hi
gtk_clist_set_column_visibility(hosttable->table, 1, FALSE);
}
+#ifdef HAVE_GEOIP
+ /* Hide all of the GeoIP columns initially */
+ for (i = 0; i < NUM_GEOIP_COLS; i++) {
+ gtk_clist_set_column_visibility(hosttable->table, NUM_BUILTIN_COLS + i, FALSE);
+ }
+#endif /* HAVE_GEOIP */
+
/* create popup menu for this table */
hostlist_create_popup_menu(hosttable);
@@ -927,8 +944,9 @@ init_hostlist_notebook_cb(GtkWidget *w _U_, gpointer d _U_)
while(current_table) {
registered = current_table->data;
page_lb = gtk_label_new("");
- hosttable = init_hostlist_notebook_page_cb(registered->hide_ports, registered->table_name, registered->tap_name,
- registered->filter, registered->packet_func);
+ hosttable = init_hostlist_notebook_page_cb(registered->hide_ports,
+ registered->table_name, registered->tap_name,
+ registered->filter, registered->packet_func);
g_object_set_data(G_OBJECT(hosttable->win), HOST_PTR_KEY, hosttable);
gtk_notebook_append_page(GTK_NOTEBOOK(nb), hosttable->win, page_lb);
hosttable->win = win;
@@ -1057,8 +1075,12 @@ add_hostlist_table_data(hostlist_table *hl, const address *addr, guint32 port, g
/* if this was a new talker we have to create a clist row for it */
if(new_talker){
- char *entries[NUM_COLS];
+ char *entries[NUM_HOSTLIST_COLS];
char frames[16],bytes[16],txframes[16],txbytes[16],rxframes[16],rxbytes[16];
+#ifdef HAVE_GEOIP
+ char geoip[NUM_GEOIP_COLS][16];
+ guint i;
+#endif /* HAVE_GEOIP */
/* these values will be filled by call to draw_hostlist_table_addresses() below */
entries[0]="";
@@ -1079,6 +1101,19 @@ add_hostlist_table_data(hostlist_table *hl, const address *addr, guint32 port, g
g_snprintf(rxbytes, 16, "%" G_GINT64_MODIFIER "u", talker->rx_bytes);
entries[7]=rxbytes;
+#ifdef HAVE_GEOIP
+ /* 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) {
+ g_snprintf(geoip[i], 16, "%s", geoip_db_lookup_ipv4(i, *(guint32*)talker->address.data));
+ entries[NUM_BUILTIN_COLS + i] = geoip[i];
+ gtk_clist_set_column_visibility(hl->table, NUM_BUILTIN_COLS + i, TRUE);
+ } else {
+ entries[NUM_BUILTIN_COLS + i] = "";
+ }
+ }
+#endif /* HAVE_GEOIP */
+
gtk_clist_insert(hl->table, talker_idx, entries);
gtk_clist_set_row_data(hl->table, talker_idx, (gpointer)(long) talker_idx);
diff --git a/gtk/hostlist_table.h b/gtk/hostlist_table.h
index 561445548f..1a0e4ca644 100644
--- a/gtk/hostlist_table.h
+++ b/gtk/hostlist_table.h
@@ -7,17 +7,17 @@
* Wireshark - Network traffic analyzer
* By Gerald Combs <gerald@wireshark.org>
* Copyright 1998 Gerald Combs
- *
+ *
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
- *
+ *
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
- *
+ *
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
@@ -42,6 +42,14 @@ typedef struct _hostlist_talker_t {
guint64 tx_bytes; /**< number of transmitted bytes */
} hostlist_talker_t;
+#define NUM_BUILTIN_COLS 8
+#ifdef HAVE_GEOIP
+# define NUM_GEOIP_COLS 8
+#else
+# define NUM_GEOIP_COLS 0
+#endif
+#define NUM_HOSTLIST_COLS (NUM_BUILTIN_COLS + NUM_GEOIP_COLS)
+
/** Hostlist widget */
typedef struct _hostlist_table {
const char *name; /**< the name of the table */
@@ -53,7 +61,7 @@ typedef struct _hostlist_table {
GtkWidget *scrolled_window; /**< the scrolled window */
GtkCList *table; /**< the GTK table */
guint32 num_columns; /**< number of columns in the above table */
- const char *default_titles[8]; /**< Column headers */
+ const char *default_titles[NUM_HOSTLIST_COLS]; /**< Column headers */
GtkWidget *menu; /**< context menu */
gboolean has_ports; /**< table has ports */
guint32 num_hosts; /**< number of hosts (0 or 1) */
diff --git a/gtk/prefs_nameres.c b/gtk/prefs_nameres.c
index cc1f16529a..c52e0b5e97 100644
--- a/gtk/prefs_nameres.c
+++ b/gtk/prefs_nameres.c
@@ -45,28 +45,48 @@
#define M_RESOLVE_KEY "m_resolve"
#define N_RESOLVE_KEY "n_resolve"
#define T_RESOLVE_KEY "t_resolve"
+
#if defined(HAVE_C_ARES) || defined(HAVE_GNU_ADNS)
# define C_RESOLVE_KEY "c_resolve"
# define RESOLVE_CONCURRENCY_KEY "resolve_concurrency"
#endif /* HAVE_C_ARES || HAVE_GNU_ADNS */
+
#ifdef HAVE_LIBSMI
-#define SP_RESOLVE_KEY "sp_resolve"
-#define SM_RESOLVE_KEY "sm_resolve"
-#endif
+# define SP_RESOLVE_KEY "sp_resolve"
+# define SM_RESOLVE_KEY "sm_resolve"
+#endif /* HAVE_LIBSMI */
+
+#ifdef HAVE_GEOIP
+# define GEOIP_RESOLVE_KEY "geoip_resolve"
+#endif /* HAVE_GEOIP */
+
+#define BASE_TABLE_ROWS 3
#if defined(HAVE_C_ARES) || defined(HAVE_GNU_ADNS)
-# ifdef HAVE_LIBSMI
-# define RESOLV_TABLE_ROWS 7
-# else
-# define RESOLV_TABLE_ROWS 5
-# endif
+# define ASYNC_TABLE_ROWS 2
#else
-# ifdef HAVE_LIBSMI
-# define RESOLV_TABLE_ROWS 5
-# else
-# define RESOLV_TABLE_ROWS 3
-# endif
-#endif /* HAVE_C_ARES || HAVE_GNU_ADNS */
+# define ASYNC_TABLE_ROWS 0
+#endif
+
+#ifdef HAVE_LIBSMI
+# define SMI_TABLE_ROWS 2
+#else
+# define SMI_TABLE_ROWS 0
+#endif
+
+#ifdef HAVE_GEOIP
+# define GEOIP_TABLE_ROWS 1
+#else
+# define GEOIP_TABLE_ROWS 0
+#endif
+
+#define RESOLV_TABLE_ROWS (\
+ BASE_TABLE_ROWS + \
+ ASYNC_TABLE_ROWS + \
+ SMI_TABLE_ROWS + \
+ GEOIP_TABLE_ROWS \
+ )
+
GtkWidget*
nameres_prefs_show(void)
{
@@ -79,10 +99,14 @@ nameres_prefs_show(void)
char concur_str[10+1];
#endif /* HAVE_C_ARES || HAVE_GNU_ADNS */
#ifdef HAVE_LIBSMI
- GtkWidget *sp_resolv_cb, *sm_resolv_cb;
+ GtkWidget *sp_resolv_bt, *sm_resolv_bt;
uat_t *smi_paths_uat;
uat_t *smi_modules_uat;
#endif
+#ifdef HAVE_GEOIP
+ GtkWidget *geoip_resolv_bt;
+ uat_t *geoip_db_paths_uat;
+#endif
/*
* XXX - it would be nice if the current setting of the resolver
* flags could be different from the preference flags, so that
@@ -147,26 +171,43 @@ nameres_prefs_show(void)
smi_paths_uat = uat_get_table_by_name("SMI Paths");
if (smi_paths_uat) {
table_row++;
- sp_resolv_cb = create_preference_uat(main_tb, table_row,
+ sp_resolv_bt = create_preference_uat(main_tb, table_row,
"SMI (MIB and PIB) paths",
"Search paths for SMI (MIB and PIB) modules. You must\n"
"restart Wireshark for these changes to take effect.",
smi_paths_uat);
- g_object_set_data(G_OBJECT(main_vb), SP_RESOLVE_KEY, sp_resolv_cb);
+ g_object_set_data(G_OBJECT(main_vb), SP_RESOLVE_KEY, sp_resolv_bt);
}
/* SMI modules UAT */
smi_modules_uat = uat_get_table_by_name("SMI Modules");
if (smi_modules_uat) {
table_row++;
- sm_resolv_cb = create_preference_uat(main_tb, table_row,
+ sm_resolv_bt = create_preference_uat(main_tb, table_row,
"SMI (MIB and PIB) modules",
"List of enabled SMI (MIB and PIB) modules. You must\n"
"restart Wireshark for these changes to take effect.",
smi_modules_uat);
- g_object_set_data(G_OBJECT(main_vb), SM_RESOLVE_KEY, sm_resolv_cb);
+ g_object_set_data(G_OBJECT(main_vb), SM_RESOLVE_KEY, sm_resolv_bt);
}
-#endif
+#endif /* HAVE_LIBSMI */
+
+#ifdef HAVE_GEOIP
+ /* GeoIP databases http://www.maxmind.com/app/api */
+ geoip_db_paths_uat = uat_get_table_by_name("GeoIP Database Paths");
+g_warning("gdu: %p", geoip_db_paths_uat);
+ if (geoip_db_paths_uat) {
+ table_row++;
+ geoip_resolv_bt = create_preference_uat(main_tb, table_row,
+ "GeoIP database search paths",
+ "Paths to GeoIP address mapping databases. Database\n"
+ "names must begin with \"Geo\" and in with \".dat\".\n"
+ "You must restart Wireshark for these changes to take\n"
+ "effect.",
+ geoip_db_paths_uat);
+ g_object_set_data(G_OBJECT(main_vb), GEOIP_RESOLVE_KEY, geoip_resolv_bt);
+ }
+#endif /* HAVE_GEOIP */
/* Show 'em what we got */
gtk_widget_show_all(main_vb);
@@ -182,7 +223,10 @@ nameres_prefs_fetch(GtkWidget *w)
GtkWidget *c_resolv_cb, *resolv_concurrency_te;
#endif /* HAVE_C_ARES || HAVE_GNU_ADNS */
#ifdef HAVE_LIBSMI
- GtkWidget *sp_resolv_cb, *sm_resolv_cb;
+ GtkWidget *sp_resolv_bt, *sm_resolv_bt;
+#endif
+#ifdef HAVE_GEOIP
+ GtkWidget *geoip_resolv_bt;
#endif
m_resolv_cb = (GtkWidget *)g_object_get_data(G_OBJECT(w), M_RESOLVE_KEY);
@@ -194,8 +238,11 @@ nameres_prefs_fetch(GtkWidget *w)
resolv_concurrency_te = (GtkWidget *)g_object_get_data(G_OBJECT(w), RESOLVE_CONCURRENCY_KEY);
#endif /* HAVE_C_ARES || HAVE_GNU_ADNS */
#ifdef HAVE_LIBSMI
- sp_resolv_cb = (GtkWidget *)g_object_get_data(G_OBJECT(w), SP_RESOLVE_KEY);
- sm_resolv_cb = (GtkWidget *)g_object_get_data(G_OBJECT(w), SM_RESOLVE_KEY);
+ sp_resolv_bt = (GtkWidget *)g_object_get_data(G_OBJECT(w), SP_RESOLVE_KEY);
+ sm_resolv_bt = (GtkWidget *)g_object_get_data(G_OBJECT(w), SM_RESOLVE_KEY);
+#endif
+#ifdef HAVE_GEOIP
+ geoip_resolv_bt = (GtkWidget *)g_object_get_data(G_OBJECT(w), GEOIP_RESOLVE_KEY);
#endif
prefs.name_resolve = RESOLV_NONE;