aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--gtk/capture_dlg.c48
-rw-r--r--gtk/capture_if_dlg.c39
-rw-r--r--pcap-util-unix.c2
-rw-r--r--pcap-util.c29
-rw-r--r--pcap-util.h20
5 files changed, 88 insertions, 50 deletions
diff --git a/gtk/capture_dlg.c b/gtk/capture_dlg.c
index 0689dadbfa..56d06f75d7 100644
--- a/gtk/capture_dlg.c
+++ b/gtk/capture_dlg.c
@@ -213,23 +213,6 @@ get_if_name(char *if_text)
*/
static GtkWidget *cap_open_w;
-
-/* From tcptraceroute, convert a numeric IP address to a string */
-/* XXX - this functionality is already somewhere in our code */
-#define IPTOSBUFFERS 12
-char *iptos(u_long in)
-{
- static char output[IPTOSBUFFERS][3*4+3+1];
- static short which;
- u_char *p;
-
- p = (u_char *)∈
- which = (which + 1 == IPTOSBUFFERS ? 0 : which + 1);
- sprintf(output[which], "%d.%d.%d.%d", p[0], p[1], p[2], p[3]);
- return output[which];
-}
-
-
static void
set_link_type_list(GtkWidget *linktype_om, GtkWidget *entry)
{
@@ -252,6 +235,7 @@ set_link_type_list(GtkWidget *linktype_om, GtkWidget *entry)
GString *ip_str = g_string_new("IP address: ");
int ips = 0;
GSList *curr_ip;
+ if_addr_t *ip_addr;
lt_menu = gtk_menu_new();
entry_text = g_strdup(gtk_entry_get_text(GTK_ENTRY(entry)));
@@ -290,18 +274,28 @@ set_link_type_list(GtkWidget *linktype_om, GtkWidget *entry)
*/
lt_list = get_pcap_linktype_list(if_name, err_buf);
- /* create string of list of IP addresses of this interface */
- for( ; (curr_ip = g_slist_nth(if_info->ip_addr, ips)) != NULL; ips++) {
- if (ips != 0) {
- g_string_append(ip_str, ", ");
- }
+ /* create string of list of IP addresses of this interface */
+ for (; (curr_ip = g_slist_nth(if_info->ip_addr, ips)) != NULL; ips++) {
+ if (ips != 0)
+ g_string_append(ip_str, ", ");
- g_string_append(ip_str, iptos(*((guint32 *)curr_ip->data)));
- }
+ ip_addr = (if_addr_t *)curr_ip->data;
+ switch (ip_addr->family) {
- if(if_info->loopback) {
- g_string_append(ip_str, " (loopback)");
- }
+ case FAM_IPv4:
+ g_string_append(ip_str,
+ ip_to_str((guint8 *)&ip_addr->ip_addr.ip4_addr));
+ break;
+
+ case FAM_IPv6:
+ g_string_append(ip_str,
+ ip6_to_str((struct e_in6_addr *)&ip_addr->ip_addr.ip6_addr));
+ break;
+ }
+ }
+
+ if (if_info->loopback)
+ g_string_append(ip_str, " (loopback)");
}
}
free_interface_list(if_list);
diff --git a/gtk/capture_if_dlg.c b/gtk/capture_if_dlg.c
index f569647937..b4cc35de86 100644
--- a/gtk/capture_if_dlg.c
+++ b/gtk/capture_if_dlg.c
@@ -63,8 +63,6 @@
#include "capture.h"
-extern char *iptos(u_long in);
-
extern gboolean is_capture_in_progress(void);
/*
@@ -312,15 +310,14 @@ capture_if_cb(GtkWidget *w _U_, gpointer d _U_)
gchar *cant_get_if_list_errstr;
int row;
if_dlg_data_t *if_dlg_data;
- int ifs;
- GList *curr;
- if_info_t *if_info;
- GSList *curr_ip;
- guint32 ip_addr;
+ int ifs;
+ GList *curr;
+ if_info_t *if_info;
+ GSList *curr_ip;
+ if_addr_t *ip_addr;
GString *if_tool_str = g_string_new("");
gchar *tmp_str;
-
if (cap_if_w != NULL) {
/* There's already a "Capture Interfaces" dialog box; reactivate it. */
reactivate_window(cap_if_w);
@@ -440,19 +437,33 @@ capture_if_cb(GtkWidget *w _U_, gpointer d _U_)
}
/* IP address */
- /* only one IP address will be shown */
+ /* only the first IP address will be shown */
g_string_append(if_tool_str, "IP: ");
curr_ip = g_slist_nth(if_info->ip_addr, 0);
if(curr_ip) {
- ip_addr = *((guint32 *)curr_ip->data);
- if_dlg_data->ip_lb = gtk_label_new(iptos(ip_addr));
- g_string_append(if_tool_str, iptos(ip_addr));
+ ip_addr = (if_addr_t *)curr_ip->data;
+ switch (ip_addr->family) {
+
+ case FAM_IPv4:
+ tmp_str = ip_to_str((guint8 *)&ip_addr->ip_addr.ip4_addr);
+ break;
+
+ case FAM_IPv6:
+ tmp_str = ip6_to_str((struct e_in6_addr *)&ip_addr->ip_addr.ip6_addr);
+ break;
+
+ default:
+ g_assert_not_reached();
+ tmp_str = NULL;
+ }
+ if_dlg_data->ip_lb = gtk_label_new(tmp_str);
+ gtk_widget_set_sensitive(if_dlg_data->ip_lb, TRUE);
+ g_string_append(if_tool_str, tmp_str);
} else {
- ip_addr = 0;
if_dlg_data->ip_lb = gtk_label_new("unknown");
+ gtk_widget_set_sensitive(if_dlg_data->ip_lb, FALSE);
g_string_append(if_tool_str, "unknown");
}
- gtk_widget_set_sensitive(if_dlg_data->ip_lb, ip_addr);
gtk_table_attach_defaults(GTK_TABLE(if_tb), if_dlg_data->ip_lb, 2, 3, row, row+1);
g_string_append(if_tool_str, "\n");
diff --git a/pcap-util-unix.c b/pcap-util-unix.c
index 02b253c726..d9a697ee76 100644
--- a/pcap-util-unix.c
+++ b/pcap-util-unix.c
@@ -144,7 +144,7 @@ get_interface_list(int *err, char *err_str)
/*
* If we already have this interface name on the list,
- * don't add it, but, if we don't already have an IPv4
+ * don't add it, but, if we don't already have an IP
* address for it, add that address (SIOCGIFCONF returns,
* at least on BSD-flavored systems, one entry per
* interface *address*; if an interface has multiple
diff --git a/pcap-util.c b/pcap-util.c
index a1e9feb8cf..c0b92c91c4 100644
--- a/pcap-util.c
+++ b/pcap-util.c
@@ -197,23 +197,40 @@ if_info_new(char *name, char *description)
void
if_info_add_address(if_info_t *if_info, struct sockaddr *addr)
{
+ if_addr_t *ip_addr;
struct sockaddr_in *ai;
- guint32 *ip_addr;
+#ifdef AF_INET6
+ struct sockaddr_in6 *ai6;
+#endif
switch (addr->sa_family) {
case AF_INET:
ai = (struct sockaddr_in *)addr;
ip_addr = g_malloc(sizeof(*ip_addr));
- *ip_addr = *((guint32 *)&(ai->sin_addr.s_addr));
+ ip_addr->family = FAM_IPv4;
+ ip_addr->ip_addr.ip4_addr =
+ *((guint32 *)&(ai->sin_addr.s_addr));
+ if_info->ip_addr = g_slist_append(if_info->ip_addr, ip_addr);
+ break;
+
+#ifdef AF_INET6
+ case AF_INET6:
+ ai6 = (struct sockaddr_in6 *)addr;
+ ip_addr = g_malloc(sizeof(*ip_addr));
+ ip_addr->family = FAM_IPv6;
+ memcpy((void *)&ip_addr->ip_addr.ip6_addr,
+ (void *)&ai6->sin6_addr.s6_addr,
+ sizeof ip_addr->ip_addr.ip6_addr);
if_info->ip_addr = g_slist_append(if_info->ip_addr, ip_addr);
break;
+#endif
}
}
#ifdef HAVE_PCAP_FINDALLDEVS
/*
- * Get all IPv4 address information, and the loopback flag, for the given
+ * Get all IP address information, and the loopback flag, for the given
* interface.
*/
static void
@@ -265,7 +282,7 @@ get_interface_list_findalldevs(int *err, char *err_str)
static void
free_if_info_addr_cb(gpointer addr, gpointer user_data _U_)
{
- g_free(addr);
+ g_free(addr);
}
static void
@@ -277,8 +294,8 @@ free_if_cb(gpointer data, gpointer user_data _U_)
if (if_info->description != NULL)
g_free(if_info->description);
- g_slist_foreach(if_info->ip_addr, free_if_info_addr_cb, NULL);
- g_slist_free(if_info->ip_addr);
+ g_slist_foreach(if_info->ip_addr, free_if_info_addr_cb, NULL);
+ g_slist_free(if_info->ip_addr);
}
void
diff --git a/pcap-util.h b/pcap-util.h
index 7f864fd470..3a7ffc6652 100644
--- a/pcap-util.h
+++ b/pcap-util.h
@@ -50,10 +50,26 @@ extern "C" {
typedef struct {
char *name;
char *description;
- GSList *ip_addr; /* containing guint32 values */
- gboolean loopback;
+ GSList *ip_addr; /* containing address values */
+ gboolean loopback;
} if_info_t;
+/*
+ * An address in the "ip_addr" list.
+ */
+typedef enum {
+ FAM_IPv4,
+ FAM_IPv6
+} address_family;
+
+typedef struct {
+ address_family family;
+ union {
+ guint32 ip4_addr;
+ guint8 ip6_addr[16];
+ } ip_addr;
+} if_addr_t;
+
GList *get_interface_list(int *err, char *err_str);
/* Error values from "get_interface_list()". */