diff options
author | Guy Harris <guy@alum.mit.edu> | 2007-01-21 23:45:36 +0000 |
---|---|---|
committer | Guy Harris <guy@alum.mit.edu> | 2007-01-21 23:45:36 +0000 |
commit | cc2274816903f4ef20b406e687dfa3d4de1ac488 (patch) | |
tree | 5512510787af52895ceb934713d75bf182fa3033 /gtk | |
parent | 62c148c1d58c84791033da807db32c5a5752c4b8 (diff) |
Have the routines to get interface lists take a pointer to a "gchar *"
as an argument, and, on an error, if they have an error message, have
them set that "gchar *" to point to a g_malloc()ed string containing the
error message, rather than taking a pointer to a buffer for that message
as an argument. That's more like what's done in Wiretap, and doesn't
impose an upper limit on the lengths of those error messages. If that
pointer is null, don't allocate the message string and return it.
Have that error message already have the "cant_get" processing applied
to it, so nobody other than those routines need to call the "cant_get"
routines to process the error messages.
Have get_airpcap_interface_list() explicitly set "*err" to the
appropriate error code.
Clean up indentation.
svn path=/trunk/; revision=20521
Diffstat (limited to 'gtk')
-rw-r--r-- | gtk/capture_dlg.c | 35 | ||||
-rw-r--r-- | gtk/capture_if_dlg.c | 65 | ||||
-rw-r--r-- | gtk/capture_prefs.c | 49 | ||||
-rw-r--r-- | gtk/main.c | 9 |
4 files changed, 69 insertions, 89 deletions
diff --git a/gtk/capture_dlg.c b/gtk/capture_dlg.c index 831381d3f6..8676b57a12 100644 --- a/gtk/capture_dlg.c +++ b/gtk/capture_dlg.c @@ -178,7 +178,6 @@ set_link_type_list(GtkWidget *linktype_om, GtkWidget *entry) if_info_t *if_info; GList *lt_list; int err; - char err_buf[CAPTURE_PCAP_ERRBUF_SIZE]; GtkWidget *lt_menu, *lt_menu_item; GList *lt_entry; data_link_info_t *data_link_info; @@ -237,7 +236,7 @@ set_link_type_list(GtkWidget *linktype_om, GtkWidget *entry) /* * Try to get the list of known interfaces. */ - if_list = get_interface_list(&err, err_buf); + if_list = get_interface_list(&err, NULL); if (if_list != NULL) { /* * We have the list - check it. @@ -250,7 +249,7 @@ set_link_type_list(GtkWidget *linktype_om, GtkWidget *entry) * It's in the list. * Get the list of link-layer types for it. */ - lt_list = get_pcap_linktype_list(if_name, err_buf); + lt_list = get_pcap_linktype_list(if_name, NULL); /* create string of list of IP addresses of this interface */ for (; (curr_ip = g_slist_nth(if_info->ip_addr, ips)) != NULL; ips++) { @@ -591,8 +590,7 @@ capture_prep_cb(GtkWidget *w _U_, gpointer d _U_) GList *if_list, *combo_list, *cfilter_list; int row; int err; - char err_str[CAPTURE_PCAP_ERRBUF_SIZE]; - gchar *cant_get_if_list_errstr; + gchar *err_str; #ifdef _WIN32 GtkAdjustment *buffer_size_adj; GtkWidget *buffer_size_lb, *buffer_size_sb; @@ -623,28 +621,25 @@ capture_prep_cb(GtkWidget *w _U_, gpointer d _U_) } #endif - if_list = get_interface_list(&err, err_str); + if_list = get_interface_list(&err, &err_str); if (if_list == NULL && err == CANT_GET_INTERFACE_LIST) { - cant_get_if_list_errstr = cant_get_if_list_error_message(err_str); - simple_dialog(ESD_TYPE_ERROR, ESD_BTN_OK, "%s", - cant_get_if_list_errstr); - g_free(cant_get_if_list_errstr); + simple_dialog(ESD_TYPE_ERROR, ESD_BTN_OK, "%s", err_str); + g_free(err_str); } #ifdef HAVE_AIRPCAP /* update airpcap interface list */ - /* load the airpcap interfaces */ - airpcap_if_list = get_airpcap_interface_list(&err, err_str); - decryption_cm = OBJECT_GET_DATA(airpcap_tb,AIRPCAP_TOOLBAR_DECRYPTION_KEY); - update_decryption_mode_list(decryption_cm); + /* load the airpcap interfaces */ + airpcap_if_list = get_airpcap_interface_list(&err, err_str); - if (airpcap_if_list == NULL && err == CANT_GET_AIRPCAP_INTERFACE_LIST) { - cant_get_if_list_errstr = cant_get_airpcap_if_list_error_message(err_str); - simple_dialog(ESD_TYPE_ERROR, ESD_BTN_OK, "%s", - cant_get_if_list_errstr); - g_free(cant_get_if_list_errstr); - } + decryption_cm = OBJECT_GET_DATA(airpcap_tb,AIRPCAP_TOOLBAR_DECRYPTION_KEY); + update_decryption_mode_list(decryption_cm); + + if (airpcap_if_list == NULL && err == CANT_GET_AIRPCAP_INTERFACE_LIST) { + simple_dialog(ESD_TYPE_ERROR, ESD_BTN_OK, "%s", err_str); + g_free(err_str); + } /* select the first ad default (THIS SHOULD BE CHANGED) */ airpcap_if_active = airpcap_get_default_if(airpcap_if_list); diff --git a/gtk/capture_if_dlg.c b/gtk/capture_if_dlg.c index b12e301271..fdcd0c6068 100644 --- a/gtk/capture_if_dlg.c +++ b/gtk/capture_if_dlg.c @@ -189,7 +189,7 @@ capture_details_cb(GtkWidget *details_bt _U_, gpointer if_data) static void open_if(gchar *name, if_dlg_data_t *if_dlg_data) { - gchar open_err_str[CAPTURE_PCAP_ERRBUF_SIZE]; + gchar open_err_str[PCAP_ERRBUF_SIZE]; /* * XXX - on systems with BPF, the number of BPF devices limits the @@ -412,8 +412,7 @@ capture_if_cb(GtkWidget *w _U_, gpointer d _U_) #endif GtkTooltips *tooltips; int err; - char err_str[CAPTURE_PCAP_ERRBUF_SIZE]; - gchar *cant_get_if_list_errstr; + gchar *err_str; GtkRequisition requisition; int row, height; if_dlg_data_t *if_dlg_data; @@ -444,46 +443,38 @@ capture_if_cb(GtkWidget *w _U_, gpointer d _U_) #endif /* LOAD THE INTERFACES */ - if_list = get_interface_list(&err, err_str); + if_list = get_interface_list(&err, &err_str); if (if_list == NULL && err == CANT_GET_INTERFACE_LIST) { - cant_get_if_list_errstr = cant_get_if_list_error_message(err_str); - simple_dialog(ESD_TYPE_ERROR, ESD_BTN_OK, "%s", - cant_get_if_list_errstr); - g_free(cant_get_if_list_errstr); + simple_dialog(ESD_TYPE_ERROR, ESD_BTN_OK, "%s", err_str); + g_free(err_str); return; } #ifdef HAVE_AIRPCAP /* LOAD AIRPCAP INTERFACES */ - /* load the airpcap interfaces */ - airpcap_if_list = get_airpcap_interface_list(&err, err_str); - if(airpcap_if_list == NULL) airpcap_if_active = airpcap_if_selected = NULL; - - decryption_cm = OBJECT_GET_DATA(airpcap_tb,AIRPCAP_TOOLBAR_DECRYPTION_KEY); - update_decryption_mode_list(decryption_cm); - - if (airpcap_if_list == NULL && err == CANT_GET_AIRPCAP_INTERFACE_LIST) { - cant_get_if_list_errstr = cant_get_airpcap_if_list_error_message(err_str); - simple_dialog(ESD_TYPE_ERROR, ESD_BTN_OK, "%s", - cant_get_if_list_errstr); - g_free(cant_get_if_list_errstr); - } - - /* If no airpcap interface is present, gray everything */ - if(airpcap_if_active == NULL) - { - if(airpcap_if_list == NULL) - { - /*No airpcap device found */ - airpcap_enable_toolbar_widgets(airpcap_tb,FALSE); - } - else - { - /* default adapter is not airpcap... or is airpcap but is not found*/ - airpcap_set_toolbar_stop_capture(airpcap_if_active); - airpcap_enable_toolbar_widgets(airpcap_tb,FALSE); - } - } + airpcap_if_list = get_airpcap_interface_list(&err, err_str); + if (airpcap_if_list == NULL) + airpcap_if_active = airpcap_if_selected = NULL; + + decryption_cm = OBJECT_GET_DATA(airpcap_tb,AIRPCAP_TOOLBAR_DECRYPTION_KEY); + update_decryption_mode_list(decryption_cm); + + if (airpcap_if_list == NULL && err == CANT_GET_AIRPCAP_INTERFACE_LIST) { + simple_dialog(ESD_TYPE_ERROR, ESD_BTN_OK, "%s", err_str); + g_free(err_str); + } + + /* If no airpcap interface is present, gray everything */ + if (airpcap_if_active == NULL) { + if (airpcap_if_list == NULL) { + /*No airpcap device found */ + airpcap_enable_toolbar_widgets(airpcap_tb,FALSE); + } else { + /* default adapter is not airpcap... or is airpcap but is not found*/ + airpcap_set_toolbar_stop_capture(airpcap_if_active); + airpcap_enable_toolbar_widgets(airpcap_tb,FALSE); + } + } airpcap_set_toolbar_start_capture(airpcap_if_active); #endif diff --git a/gtk/capture_prefs.c b/gtk/capture_prefs.c index 6ca7322f37..f761b0174c 100644 --- a/gtk/capture_prefs.c +++ b/gtk/capture_prefs.c @@ -84,9 +84,8 @@ capture_prefs_show(void) GtkWidget *ifopts_lb, *ifopts_bt; GList *if_list, *combo_list; int err; - char err_str[CAPTURE_PCAP_ERRBUF_SIZE]; - int row = 0; - GtkTooltips *tooltips = gtk_tooltips_new(); + int row = 0; + GtkTooltips *tooltips = gtk_tooltips_new(); /* Main vertical box */ main_vb = gtk_vbox_new(FALSE, 7); @@ -109,7 +108,7 @@ capture_prefs_show(void) /* * XXX - what if we can't get the list? */ - if_list = get_interface_list(&err, err_str); + if_list = get_interface_list(&err, NULL); combo_list = build_capture_combo_list(if_list, FALSE); free_interface_list(if_list); if (combo_list != NULL) { @@ -120,11 +119,11 @@ capture_prefs_show(void) gtk_entry_set_text(GTK_ENTRY(GTK_COMBO(if_cb)->entry), prefs.capture_device); gtk_table_attach_defaults(GTK_TABLE(main_tb), if_cb, 1, 2, row, row+1); - gtk_tooltips_set_tip(tooltips, GTK_COMBO(if_cb)->entry, - "The default interface to be captured from.", NULL); + gtk_tooltips_set_tip(tooltips, GTK_COMBO(if_cb)->entry, + "The default interface to be captured from.", NULL); gtk_widget_show(if_cb); OBJECT_SET_DATA(main_vb, DEVICE_KEY, if_cb); - row++; + row++; /* Interface properties */ ifopts_lb = gtk_label_new("Interfaces:"); @@ -133,27 +132,27 @@ capture_prefs_show(void) gtk_widget_show(ifopts_lb); ifopts_bt = BUTTON_NEW_FROM_STOCK(WIRESHARK_STOCK_EDIT); - gtk_tooltips_set_tip(tooltips, ifopts_bt, - "Open a dialog box to set various interface options.", NULL); + gtk_tooltips_set_tip(tooltips, ifopts_bt, + "Open a dialog box to set various interface options.", NULL); SIGNAL_CONNECT(ifopts_bt, "clicked", ifopts_edit_cb, NULL); gtk_table_attach_defaults(GTK_TABLE(main_tb), ifopts_bt, 1, 2, row, row+1); - row++; + row++; /* Promiscuous mode */ promisc_cb = create_preference_check_button(main_tb, row++, "Capture packets in promiscuous mode:", NULL, prefs.capture_prom_mode); - gtk_tooltips_set_tip(tooltips, promisc_cb, - "Usually a network card will only capture the traffic sent to its own network address. " - "If you want to capture all traffic that the network card can \"see\", mark this option. " - "See the FAQ for some more details of capturing packets from a switched network.", NULL); + gtk_tooltips_set_tip(tooltips, promisc_cb, + "Usually a network card will only capture the traffic sent to its own network address. " + "If you want to capture all traffic that the network card can \"see\", mark this option. " + "See the FAQ for some more details of capturing packets from a switched network.", NULL); OBJECT_SET_DATA(main_vb, PROM_MODE_KEY, promisc_cb); /* Real-time capture */ sync_cb = create_preference_check_button(main_tb, row++, "Update list of packets in real time:", NULL, prefs.capture_real_time); - gtk_tooltips_set_tip(tooltips, sync_cb, + gtk_tooltips_set_tip(tooltips, sync_cb, "Update the list of packets while capture is in progress. " "Don't use this option if you notice packet drops.", NULL); OBJECT_SET_DATA(main_vb, CAPTURE_REAL_TIME_KEY, sync_cb); @@ -162,7 +161,7 @@ capture_prefs_show(void) auto_scroll_cb = create_preference_check_button(main_tb, row++, "Automatic scrolling in live capture:", NULL, prefs.capture_auto_scroll); - gtk_tooltips_set_tip(tooltips, auto_scroll_cb, + gtk_tooltips_set_tip(tooltips, auto_scroll_cb, "Automatic scrolling of the packet list while live capture is in progress. ", NULL); OBJECT_SET_DATA(main_vb, AUTO_SCROLL_KEY, auto_scroll_cb); @@ -170,8 +169,8 @@ capture_prefs_show(void) show_info_cb = create_preference_check_button(main_tb, row++, "Hide capture info dialog:", NULL, !prefs.capture_show_info); - gtk_tooltips_set_tip(tooltips, show_info_cb, - "Hide the capture info dialog while capturing. ", NULL); + gtk_tooltips_set_tip(tooltips, show_info_cb, + "Hide the capture info dialog while capturing. ", NULL); OBJECT_SET_DATA(main_vb, SHOW_INFO_KEY, show_info_cb); /* Show 'em what we got */ @@ -692,19 +691,15 @@ ifopts_if_clist_add(void) { GList *if_list; int err; - char err_str[CAPTURE_PCAP_ERRBUF_SIZE]; - gchar *cant_get_if_list_errstr; + gchar *err_str; if_info_t *if_info; guint i; guint nitems; - if_list = get_interface_list(&err, err_str); + if_list = get_interface_list(&err, &err_str); if (if_list == NULL && err == CANT_GET_INTERFACE_LIST) { - cant_get_if_list_errstr = - cant_get_if_list_error_message(err_str); - simple_dialog(ESD_TYPE_ERROR, ESD_BTN_OK, "%s", - cant_get_if_list_errstr); - g_free(cant_get_if_list_errstr); + simple_dialog(ESD_TYPE_ERROR, ESD_BTN_OK, "%s", err_str); + g_free(err_str); return; } @@ -719,7 +714,7 @@ ifopts_if_clist_add(void) if (if_info == NULL) continue; - /* fill current options CList with current preference values */ + /* fill current options CList with current preference values */ ifopts_options_add(GTK_CLIST(cur_clist), if_info); } diff --git a/gtk/main.c b/gtk/main.c index 71933666b7..bfb442408f 100644 --- a/gtk/main.c +++ b/gtk/main.c @@ -2157,8 +2157,8 @@ main(int argc, char *argv[]) wpcap_packet_load(); #ifdef HAVE_AIRPCAP - /* Load the airpcap.dll. This must also be done before collecting - * run-time version information. */ + /* Load the airpcap.dll. This must also be done before collecting + * run-time version information. */ airpcap_dll_ret_val = load_airpcap(); switch (airpcap_dll_ret_val) { @@ -2167,9 +2167,8 @@ main(int argc, char *argv[]) airpcap_if_list = get_airpcap_interface_list(&err, err_str); if (airpcap_if_list == NULL && err == CANT_GET_AIRPCAP_INTERFACE_LIST) { - cant_get_if_list_errstr = cant_get_airpcap_if_list_error_message(err_str); - simple_dialog(ESD_TYPE_ERROR, ESD_BTN_OK, "%s", cant_get_if_list_errstr); - g_free(cant_get_if_list_errstr); + simple_dialog(ESD_TYPE_ERROR, ESD_BTN_OK, "%s", err_str); + g_free(err_str); } /* select the first ad default (THIS SHOULD BE CHANGED) */ airpcap_if_active = airpcap_get_default_if(airpcap_if_list); |