From 48986f4fb9912c75da19c77151eaea92e372745c Mon Sep 17 00:00:00 2001 From: Guy Harris Date: Mon, 21 Jul 2014 12:06:25 -0700 Subject: [PATCH] Make the Qt version update displays when interfaces appear or disappear. Change-Id: If1218baaae9dcd93ddb1cea81ac5457f90a57c6c Reviewed-on: https://code.wireshark.org/review/3152 Reviewed-by: Guy Harris --- ui/qt/capture_interfaces_dialog.cpp | 1 + ui/qt/main_window.cpp | 1 + ui/qt/wireshark_application.cpp | 78 +++++++++++++++++++++++++++++ ui/qt/wireshark_application.h | 4 ++ 4 files changed, 84 insertions(+) diff --git a/ui/qt/capture_interfaces_dialog.cpp b/ui/qt/capture_interfaces_dialog.cpp index eac07a43a0..f1f9aab283 100644 --- a/ui/qt/capture_interfaces_dialog.cpp +++ b/ui/qt/capture_interfaces_dialog.cpp @@ -73,6 +73,7 @@ CaptureInterfacesDialog::CaptureInterfacesDialog(QWidget *parent) : connect(ui->allFilterComboBox, SIGNAL(captureFilterSyntaxChanged(bool)), this, SLOT(allFilterChanged())); connect(this, SIGNAL(interfacesChanged()), ui->allFilterComboBox, SIGNAL(interfacesChanged())); connect(this, SIGNAL(ifsChanged()), this, SLOT(refreshInterfaceList())); + connect(wsApp, SIGNAL(ifListChanged()), this, SLOT(refreshInterfaceList())); } void CaptureInterfacesDialog::allFilterChanged() diff --git a/ui/qt/main_window.cpp b/ui/qt/main_window.cpp index 07e635979a..7cd3def4ad 100644 --- a/ui/qt/main_window.cpp +++ b/ui/qt/main_window.cpp @@ -308,6 +308,7 @@ MainWindow::MainWindow(QWidget *parent) : this->main_welcome_->getInterfaceTree(), SLOT(setSelectedInterfaces())); connect(&capture_interfaces_dialog_, SIGNAL(interfaceListChanged()), this->main_welcome_->getInterfaceTree(), SLOT(interfaceListChanged())); + connect(wsApp, SIGNAL(ifListChanged()), this, SLOT(interfaceListChanged())); #endif main_ui_->mainStack->setCurrentWidget(main_welcome_); diff --git a/ui/qt/wireshark_application.cpp b/ui/qt/wireshark_application.cpp index 88ad22306b..c799d1a6b1 100644 --- a/ui/qt/wireshark_application.cpp +++ b/ui/qt/wireshark_application.cpp @@ -29,6 +29,7 @@ #include "ui/decode_as_utils.h" #include "ui/preference_utils.h" +#include "ui/iface_lists.h" #include "ui/recent.h" #include "ui/simple_dialog.h" #include "ui/util.h" @@ -39,6 +40,10 @@ #include "log.h" #include "recent_file_status.h" +#ifdef HAVE_LIBPCAP +#include +#endif + #include "ui/capture.h" #include "ui/filters.h" #include "ui/capture_globals.h" @@ -625,6 +630,69 @@ void WiresharkApplication::emitStatCommandSignal(const QString &menu_path, const emit openStatCommandDialog(menu_path, arg, userdata); } +#ifdef HAVE_LIBPCAP + +static void +iface_mon_event_cb(const char *iface, int up) +{ + int present = 0; + guint ifs, j; + interface_t device; + interface_options interface_opts; + + for (ifs = 0; ifs < global_capture_opts.all_ifaces->len; ifs++) { + device = g_array_index(global_capture_opts.all_ifaces, interface_t, ifs); + if (strcmp(device.name, iface) == 0) { + present = 1; + if (!up) { + /* + * Interface went down or disappeared; remove all instances + * of it from the current list of interfaces selected + * for capturing. + */ + for (j = 0; j < global_capture_opts.ifaces->len; j++) { + interface_opts = g_array_index(global_capture_opts.ifaces, interface_options, j); + if (strcmp(interface_opts.name, device.name) == 0) { + g_array_remove_index(global_capture_opts.ifaces, j); + } + } + } + } + } + + if (present != up) { + /* + * We've been told that there's a new interface or that an old + * interface is gone; reload the local interface list. + */ + scan_local_interfaces(main_window_update); + } +} + +#endif + +void WiresharkApplication::ifChangeEventsAvailable() +{ +#ifdef HAVE_LIBPCAP + /* + * Something's readable from the descriptor for interface + * monitoring. + * + * Have the interface-monitoring code Read whatever interface-change + * events are available, and call the callback for them. + */ + iface_mon_event(); + + /* + * Now emit a signal to indicate that the list changed, so that all + * places displaying the list will get updated. + * + * XXX - only if it *did* change. + */ + emit ifListChanged(); +#endif +} + void WiresharkApplication::allSystemsGo() { QString display_filter = NULL; @@ -635,6 +703,16 @@ void WiresharkApplication::allSystemsGo() pending_open_files_.pop_front(); } software_update_init(); + +#ifdef HAVE_LIBPCAP + int err; + err = iface_mon_start(&iface_mon_event_cb); + if (err == 0) { + if_notifier_ = new QSocketNotifier(iface_mon_get_sock(), + QSocketNotifier::Read); + connect(if_notifier_, SIGNAL(activated(int)), SLOT(ifChangeEventsAvailable())); + } +#endif } e_prefs * WiresharkApplication::readConfigurationFiles(char **gdp_path, char **dp_path) diff --git a/ui/qt/wireshark_application.h b/ui/qt/wireshark_application.h index 6ac8359e60..8bf0912cfa 100644 --- a/ui/qt/wireshark_application.h +++ b/ui/qt/wireshark_application.h @@ -39,6 +39,7 @@ #include #include #include +#include #include #include @@ -95,12 +96,14 @@ private: QTimer recent_timer_; QTimer tap_update_timer_; QList pending_open_files_; + QSocketNotifier *if_notifier_; protected: bool event(QEvent *event); signals: void appInitialized(); + void ifListChanged(); void openCaptureFile(QString &cf_path, QString &display_filter, unsigned int type); void recentFilesRead(); void updateRecentItemStatus(const QString &filename, qint64 size, bool accessible); @@ -135,6 +138,7 @@ public slots: private slots: void cleanup(); + void ifChangeEventsAvailable(); void itemStatusFinished(const QString filename = "", qint64 size = 0, bool accessible = false); void refreshRecentFiles(void); void updateTaps();