Add (preliminary, and a bit hacky) support for interface-type icons on

OS X.

Add some comments to the interface-type icon code, and, when looking for
certain text in the description on Windows, look in the interface
description supplied by WinPcap rather than the user-supplied
description (if we want to look in the latter, we presumably want to
look in both, so the user giving a wireless interface a name they like
won't break the code that checks for wireless interfaces).  There's
probably *some* NDIS OID that can give you the information you want -
hopefully, not an NDIS 6-only OID).

svn path=/trunk/; revision=27345
This commit is contained in:
Guy Harris 2009-02-01 22:20:42 +00:00
parent 3ad5b02052
commit ef07402aa5
3 changed files with 70 additions and 26 deletions

View File

@ -7,7 +7,6 @@
* 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
@ -87,11 +86,13 @@ capture_air_cb(GtkWidget *widget, gpointer data);
void
set_capture_if_dialog_for_capture_in_progress(gboolean capture_in_progress);
#include "capture-pcap-util.h" /* for if_info_t */
/*
* Used to retrieve the interface icon
*/
GtkWidget *
capture_get_if_icon(const gchar* name);
capture_get_if_icon(const if_info_t* if_info);
#ifdef HAVE_PCAP_REMOTE
struct remote_host {

View File

@ -35,6 +35,8 @@
#ifdef HAVE_LIBPCAP
#include <string.h>
#include <epan/prefs.h>
#include "../globals.h"
@ -69,8 +71,8 @@
#include "../image/toolbar/capture_ethernet_16.xpm"
#include "../image/toolbar/modem_16.xpm"
#include "../image/toolbar/network_wireless_16.xpm"
#endif
#include "../image/toolbar/network_wireless_16.xpm"
#include "../image/toolbar/network_wired_16.xpm"
@ -358,22 +360,60 @@ gint if_list_comparator_alph (const void *first_arg, const void *second_arg){
/*
* Used to retrieve the interface icon
* Used to retrieve the interface icon.
* This is hideously platform-dependent.
*/
GtkWidget * capture_get_if_icon(const gchar* name _U_)
GtkWidget * capture_get_if_icon(const if_info_t* if_info _U_)
{
#ifdef _WIN32
if ( strstr(name,"generic dialup") != NULL) {
#if defined(_WIN32)
/*
* Much digging failed to reveal any obvious way to get something such
* as the SNMP MIB-II ifType value for an interface:
*
* http://www.iana.org/assignments/ianaiftype-mib
*
* by making some NDIS request.
*/
if ( strstr(if_info->description,"generic dialup") != NULL) {
return xpm_to_widget(modem_16_xpm);
}
if ( strstr(name,"Wireless") != NULL || strstr(name,"802.11") != NULL) {
if ( strstr(if_info->description,"Wireless") != NULL || strstr(if_info->description,"802.11") != NULL) {
return xpm_to_widget(network_wireless_16_xpm);
}
/* TODO: check exact spelling and find a better icon! */
if ( strstr(name,"VMWare") != NULL) {
/* TODO: check exact spelling (the company is "VMware") and find a better icon! */
if ( strstr(if_info->description,"VMWare") != NULL) {
return xpm_to_widget(network_wireless_16_xpm);
}
#endif /* _WIN32 */
#elif defined(__APPLE__)
/*
* XXX - yes, fetching all the network addresses for an interface
* gets you an AF_LINK address, of type "struct sockaddr_dl", and,
* yes, that includes an SNMP MIB-II ifType value.
*
* However, it's IFT_ETHER, i.e. Ethernet, for AirPort interfaces,
* not IFT_IEEE80211 (which isn't defined in OS X in any case).
*
* Perhaps other BSD-flavored OSes won't make this mistake.
*
* One might be able to get the information one wants from IOKit.
*/
if ( strcmp(if_info->name, "en1") == 0) {
return xpm_to_widget(network_wireless_16_xpm);
}
/*
* XXX - PPP devices have names beginning with "ppp" and an IFT_ of
* IFT_PPP, but they could be dial-up, or PPPoE, or mobile phone modem,
* or VPN, or... devices. One might have to dive into the bowels of
* IOKit to find out.
*/
/*
* TODO: find a better icon!
* These devices have an IFT_ of IFT_ETHER, so we have to check the name.
*/
if ( strncmp(if_info->name,"vmnet",5) == 0) {
return xpm_to_widget(network_wireless_16_xpm);
}
#endif
return xpm_to_widget(network_wired_16_xpm);
}
@ -554,9 +594,9 @@ capture_if_cb(GtkWidget *w _U_, gpointer d _U_)
if(get_airpcap_if_from_name(airpcap_if_list,if_info->name) != NULL)
icon = xpm_to_widget(capture_airpcap_16_xpm);
else
icon = capture_get_if_icon(if_info->description);
icon = capture_get_if_icon(if_info);
#else
icon = capture_get_if_icon(if_info->description);
icon = capture_get_if_icon(if_info);
#endif
gtk_table_attach_defaults(GTK_TABLE(if_tb), icon, 0, 1, row, row+1);

View File

@ -504,7 +504,7 @@ welcome_if_press_cb(GtkWidget *widget _U_, GdkEvent *event _U_, gpointer data)
/* create a single interface entry */
static GtkWidget *
welcome_if_new(const char *if_name, GdkColor *topic_bg _U_, gpointer interf)
welcome_if_new(const if_info_t *if_info, const gchar *user_descr, GdkColor *topic_bg _U_, gpointer interf)
{
GtkWidget *interface_hb;
GtkWidget *w;
@ -524,10 +524,15 @@ welcome_if_new(const char *if_name, GdkColor *topic_bg _U_, gpointer interf)
gtk_container_add(GTK_CONTAINER(eb), interface_hb);
/* icon */
w = capture_get_if_icon(if_name);
w = capture_get_if_icon(if_info);
gtk_box_pack_start(GTK_BOX(interface_hb), w, FALSE, FALSE, 5);
message = g_string_new(if_name);
if (user_descr != NULL)
message = g_string_new(user_descr);
else if (if_info->description != NULL)
message = g_string_new(if_info->description);
else
message = g_string_new(if_info->name);
/* truncate string if it's too long */
/* (the number of chars is a bit arbitrary, though) */
@ -561,7 +566,7 @@ welcome_if_panel_load(void)
gchar *err_str;
int ifs;
GList *curr;
gchar *descr;
gchar *user_descr;
/* LOAD THE INTERFACES */
@ -583,19 +588,17 @@ welcome_if_panel_load(void)
continue;
}
descr = capture_dev_user_descr_find(if_info->name);
if (descr) {
user_descr = capture_dev_user_descr_find(if_info->name);
if (user_descr) {
#ifndef _WIN32
gchar *comment = descr;
descr = g_strdup_printf("%s (%s)", comment, if_info->name);
gchar *comment = user_descr;
user_descr = g_strdup_printf("%s (%s)", comment, if_info->name);
g_free (comment);
#endif
interface_hb = welcome_if_new(descr, &topic_content_bg, g_strdup(if_info->name));
g_free (descr);
} else if (if_info->description != NULL) {
interface_hb = welcome_if_new(if_info->description, &topic_content_bg, g_strdup(if_info->name));
interface_hb = welcome_if_new(if_info, user_descr, &topic_content_bg, g_strdup(if_info->name));
g_free (user_descr);
} else {
interface_hb = welcome_if_new(if_info->name, &topic_content_bg, g_strdup(if_info->name));
interface_hb = welcome_if_new(if_info, NULL, &topic_content_bg, g_strdup(if_info->name));
}
child_box = scroll_box_dynamic_add(welcome_if_panel_vb);