/* interface_frame.cpp
* Display of interfaces, including their respective data, and the
* capability to filter interfaces by type
*
* Wireshark - Network traffic analyzer
* By Gerald Combs "
"Local interfaces are unavailable because no packet capture driver is installed."
" "
"You can fix this by installing Npcap."
" "
"Local interfaces are unavailable because the packet capture driver isn't loaded."
" "
"You can fix this by running net start npcap
if you have Npcap installed"
" or net start npf
if you have WinPcap installed."
" Both commands must be run as Administrator."
"
" "You don't have permission to capture on local interfaces." "
" "You can fix this by installing ChmodBPF." "
") .arg(install_chmodbpf_path)); #else // // XXX - should this give similar platform-dependent recommendations, // just as dumpcap gives platform-dependent recommendations in its // PLATFORM_PERMISSIONS_SUGGESTION #define? // ui->warningLabel->setText(tr("You don't have permission to capture on local interfaces.")); #endif } if (proxy_model_.rowCount() == 0) { ui->warningLabel->setText(tr("No interfaces found.")); ui->warningLabel->setText(proxy_model_.interfaceError()); if (prefs.capture_no_interface_load) { ui->warningLabel->setText(tr("Interfaces not loaded (due to preference). Go to Capture " UTF8_RIGHTWARDS_ARROW " Refresh Interfaces to load.")); } } // XXX Should we have a separate recent pref for each message? if (!ui->warningLabel->text().isEmpty() && recent.sys_warn_if_no_capture) { QString warning_text = ui->warningLabel->text(); warning_text.append(QString("") .arg(no_capture_link) .arg(SimpleDialog::dontShowThisAgain())); ui->warningLabel->setText(warning_text); ui->warningLabel->show(); } #endif // HAVE_LIBPCAP if (proxy_model_.rowCount() > 0) { ui->interfaceTree->show(); ui->interfaceTree->resizeColumnToContents(proxy_model_.mapSourceToColumn(IFTREE_COL_EXTCAP)); ui->interfaceTree->resizeColumnToContents(proxy_model_.mapSourceToColumn(IFTREE_COL_DISPLAY_NAME)); ui->interfaceTree->resizeColumnToContents(proxy_model_.mapSourceToColumn(IFTREE_COL_STATS)); } else { ui->interfaceTree->hide(); } } // XXX Should this be in capture/capture-pcap-util.[ch]? bool InterfaceFrame::haveLocalCapturePermissions() const { #ifdef Q_OS_MAC QFileInfo bpf0_fi = QFileInfo("/dev/bpf0"); return bpf0_fi.isReadable() && bpf0_fi.isWritable(); #else // XXX Add checks for other platforms. return true; #endif } void InterfaceFrame::updateSelectedInterfaces() { if (source_model_.rowCount() == 0) return; #ifdef HAVE_LIBPCAP QItemSelection sourceSelection = source_model_.selectedDevices(); QItemSelection mySelection = info_model_.mapSelectionFromSource(proxy_model_.mapSelectionFromSource(sourceSelection)); ui->interfaceTree->selectionModel()->clearSelection(); ui->interfaceTree->selectionModel()->select(mySelection, QItemSelectionModel::SelectCurrent); #endif } void InterfaceFrame::interfaceTreeSelectionChanged(const QItemSelection & selected, const QItemSelection & deselected) { if (selected.count() == 0 && deselected.count() == 0) return; if (source_model_.rowCount() == 0) return; #ifdef HAVE_LIBPCAP /* Take all selected interfaces, not just the newly ones */ QItemSelection allSelected = ui->interfaceTree->selectionModel()->selection(); QItemSelection sourceSelection = proxy_model_.mapSelectionToSource(info_model_.mapSelectionToSource(allSelected)); if (source_model_.updateSelectedDevices(sourceSelection)) emit itemSelectionChanged(); #endif } void InterfaceFrame::on_interfaceTree_doubleClicked(const QModelIndex &index) { QModelIndex realIndex = proxy_model_.mapToSource(info_model_.mapToSource(index)); if (! realIndex.isValid()) return; QStringList interfaces; #ifdef HAVE_LIBPCAP QString device_name = source_model_.getColumnContent(realIndex.row(), IFTREE_COL_NAME).toString(); QString extcap_string = source_model_.getColumnContent(realIndex.row(), IFTREE_COL_EXTCAP_PATH).toString(); interfaces << device_name; /* We trust the string here. If this interface is really extcap, the string is * being checked immediatly before the dialog is being generated */ if (extcap_string.length() > 0) { /* this checks if configuration is required and not yet provided or saved via prefs */ if (extcap_requires_configuration((const char *)(device_name.toStdString().c_str()))) { emit showExtcapOptions(device_name, true); return; } } #endif // Start capture for all columns except the first one with extcap if (IFTREE_COL_EXTCAP != realIndex.column()) { startCapture(interfaces); } } #ifdef HAVE_LIBPCAP void InterfaceFrame::on_interfaceTree_clicked(const QModelIndex &index) { if (index.column() == 0) { QModelIndex realIndex = proxy_model_.mapToSource(info_model_.mapToSource(index)); if (! realIndex.isValid()) return; QString device_name = source_model_.getColumnContent(realIndex.row(), IFTREE_COL_NAME).toString(); QString extcap_string = source_model_.getColumnContent(realIndex.row(), IFTREE_COL_EXTCAP_PATH).toString(); /* We trust the string here. If this interface is really extcap, the string is * being checked immediatly before the dialog is being generated */ if (extcap_string.length() > 0) { /* this checks if configuration is required and not yet provided or saved via prefs */ if (extcap_has_configuration((const char *)(device_name.toStdString().c_str()))) { emit showExtcapOptions(device_name, false); return; } } } } #endif void InterfaceFrame::updateStatistics(void) { if (source_model_.rowCount() == 0) return; #ifdef HAVE_LIBPCAP for (int idx = 0; idx < source_model_.rowCount(); idx++) { QModelIndex selectIndex = info_model_.mapFromSource(proxy_model_.mapFromSource(source_model_.index(idx, 0))); /* Proxy model has not masked out the interface */ if (selectIndex.isValid()) source_model_.updateStatistic(idx); } #endif } void InterfaceFrame::showRunOnFile(void) { ui->warningLabel->setText("Interfaces not loaded on startup (run on capture file). Go to Capture -> Refresh Interfaces to load."); } void InterfaceFrame::showContextMenu(QPoint pos) { QMenu * ctx_menu = new QMenu(this); // Work around QTBUG-106718. For some reason Qt::WA_DeleteOnClose + // Qt::QueuedConnection don't work here. QObject::connect(ctx_menu, &QMenu::triggered, ctx_menu, &QMenu::deleteLater); ctx_menu->addAction(tr("Start capture"), this, [=] () { QStringList ifaces; QModelIndexList selIndices = ui->interfaceTree->selectionModel()->selectedIndexes(); foreach(QModelIndex idx, selIndices) { QModelIndex realIndex = proxy_model_.mapToSource(info_model_.mapToSource(idx)); if (realIndex.column() != IFTREE_COL_NAME) realIndex = realIndex.sibling(realIndex.row(), IFTREE_COL_NAME); QString name = realIndex.data(Qt::DisplayRole).toString(); if (! ifaces.contains(name)) ifaces << name; } startCapture(ifaces); }); ctx_menu->addSeparator(); QModelIndex actIndex = ui->interfaceTree->indexAt(pos); QModelIndex realIndex = proxy_model_.mapToSource(info_model_.mapToSource(actIndex)); bool isHidden = realIndex.sibling(realIndex.row(), IFTREE_COL_HIDDEN).data(Qt::UserRole).toBool(); QAction * hideAction = ctx_menu->addAction(tr("Hide Interface"), this, [=] () { /* Attention! Only realIndex.row is a 1:1 correlation to all_ifaces */ interface_t *device = &g_array_index(global_capture_opts.all_ifaces, interface_t, realIndex.row()); device->hidden = ! device->hidden; mainApp->emitAppSignal(MainApplication::LocalInterfacesChanged); }); hideAction->setCheckable(true); hideAction->setChecked(isHidden); ctx_menu->popup(ui->interfaceTree->mapToGlobal(pos)); } void InterfaceFrame::on_warningLabel_linkActivated(const QString &link) { if (link.compare(no_capture_link) == 0) { recent.sys_warn_if_no_capture = FALSE; resetInterfaceTreeDisplay(); } else { QDesktopServices::openUrl(QUrl(link)); } }