2013-11-25 14:15:49 +00:00
/* capture_interfaces_dialog.cpp
*
* Wireshark - Network traffic analyzer
* 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
* of the License , or ( at your option ) any later version .
*
* This program is distributed in the hope that it will be useful ,
* but WITHOUT ANY WARRANTY ; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE . See the
* GNU General Public License for more details .
*
* You should have received a copy of the GNU General Public License
* along with this program ; if not , write to the Free Software
* Foundation , Inc . , 51 Franklin Street , Fifth Floor , Boston , MA 02110 - 1301 USA .
*/
2013-11-25 22:01:03 +00:00
# include "config.h"
2013-11-25 14:15:49 +00:00
2013-12-13 18:36:59 +00:00
# include <glib.h>
2013-11-25 14:15:49 +00:00
# include "capture_interfaces_dialog.h"
2017-07-05 14:56:45 +00:00
# include <ui/qt/widgets/capture_filter_combo.h>
2015-06-25 16:17:03 +00:00
# include <ui_capture_interfaces_dialog.h>
2014-06-04 09:03:59 +00:00
# include "compiled_filter_output.h"
2014-06-24 09:36:51 +00:00
# include "manage_interfaces_dialog.h"
2013-11-25 14:15:49 +00:00
2013-12-13 18:36:59 +00:00
# include "wireshark_application.h"
2013-11-25 21:50:58 +00:00
2013-12-13 18:36:59 +00:00
# ifdef HAVE_LIBPCAP
2013-11-25 14:15:49 +00:00
2016-01-19 00:02:48 +00:00
# include <QAbstractItemModel>
2014-08-18 08:04:16 +00:00
# include <QFileDialog>
# include <QMessageBox>
2016-01-19 00:02:48 +00:00
# include <QTimer>
2013-11-25 14:15:49 +00:00
2014-08-18 08:04:16 +00:00
# include "ringbuffer.h"
2014-06-30 01:36:22 +00:00
# include "ui/capture_ui_utils.h"
2013-11-25 14:15:49 +00:00
# include "ui/capture_globals.h"
# include "ui/iface_lists.h"
2014-08-18 08:04:16 +00:00
# include "ui/last_open_dir.h"
2013-11-25 17:01:10 +00:00
2017-10-14 20:14:14 +00:00
# include "ui/ws_ui_util.h"
2014-08-18 08:04:16 +00:00
# include "ui/util.h"
2015-10-04 17:10:29 +00:00
# include <wsutil/utf8_entities.h>
2014-06-04 09:03:59 +00:00
# include "ui/preference_utils.h"
2013-11-25 14:15:49 +00:00
# include <cstdio>
# include <epan/prefs.h>
# include <epan/prefs-int.h>
2013-12-21 18:40:20 +00:00
# include <epan/addr_resolv.h>
2014-08-18 08:04:16 +00:00
# include <wsutil/filesystem.h>
2013-11-25 14:15:49 +00:00
2017-03-27 14:17:51 +00:00
# include <wiretap/wtap.h>
2017-07-25 14:15:18 +00:00
# include <ui/qt/utils/qt_ui_utils.h>
2017-07-25 14:47:16 +00:00
# include <ui/qt/models/sparkline_delegate.h>
2013-11-25 14:15:49 +00:00
2014-08-06 21:50:48 +00:00
// To do:
// - Set a size hint for item delegates.
2016-05-24 23:49:54 +00:00
// - Make promiscuous and monitor mode checkboxes.
2016-01-19 00:02:48 +00:00
// - Fix InterfaceTreeDelegate method names.
// - You can edit filters via the main CaptureFilterCombo and via each
// individual interface row. We should probably do one or the other.
2014-08-06 21:50:48 +00:00
2013-11-25 14:15:49 +00:00
const int stat_update_interval_ = 1000 ; // ms
2015-03-25 03:22:00 +00:00
# ifdef CAN_SET_CAPTURE_BUFFER_SIZE
2014-08-06 21:50:48 +00:00
# define SHOW_BUFFER_COLUMN 1
# endif
# if defined(HAVE_PCAP_CREATE)
# define SHOW_MONITOR_COLUMN 1
# endif
/*
* Symbolic names for column indices .
*/
enum
{
col_interface_ = 0 ,
col_traffic_ ,
col_link_ ,
col_pmode_ ,
col_snaplen_ ,
col_buffer_ ,
col_monitor_ ,
col_filter_ ,
col_num_columns_
} ;
2015-02-15 23:37:03 +00:00
static interface_t * find_device_by_if_name ( const QString & interface_name )
{
interface_t * device ;
guint i ;
for ( i = 0 ; i < global_capture_opts . all_ifaces - > len ; i + + ) {
device = & g_array_index ( global_capture_opts . all_ifaces , interface_t , i ) ;
if ( ! interface_name . compare ( device - > display_name ) & & ! device - > hidden & & device - > type ! = IF_PIPE ) {
return device ;
}
}
return NULL ;
}
2014-08-06 21:50:48 +00:00
class InterfaceTreeWidgetItem : public QTreeWidgetItem
{
public :
2016-05-27 17:31:45 +00:00
InterfaceTreeWidgetItem ( QTreeWidget * tree ) : QTreeWidgetItem ( tree ) { }
2014-08-06 21:50:48 +00:00
bool operator < ( const QTreeWidgetItem & other ) const ;
2017-03-13 12:47:34 +00:00
QVariant data ( int column , int role ) const ;
void setData ( int column , int role , const QVariant & value ) ;
2015-12-11 10:41:07 +00:00
QList < int > points ;
2016-05-24 23:49:54 +00:00
void updateInterfaceColumns ( interface_t * device )
{
if ( ! device ) return ;
2016-05-27 17:31:45 +00:00
2016-05-24 23:49:54 +00:00
QString default_str = QObject : : tr ( " default " ) ;
2016-05-27 17:31:45 +00:00
QString linkname = QObject : : tr ( " DLT %1 " ) . arg ( device - > active_dlt ) ;
2016-05-24 23:49:54 +00:00
for ( GList * list = device - > links ; list ! = NULL ; list = g_list_next ( list ) ) {
link_row * linkr = ( link_row * ) ( list - > data ) ;
// XXX ...and if they're both -1?
if ( linkr - > dlt = = device - > active_dlt ) {
linkname = linkr - > name ;
break ;
}
}
setText ( col_link_ , linkname ) ;
# ifdef HAVE_EXTCAP
if ( device - > if_info . type = = IF_EXTCAP ) {
/* extcap interfaces does not have this settings */
2016-05-27 17:31:45 +00:00
setApplicable ( col_pmode_ , false ) ;
setApplicable ( col_snaplen_ , false ) ;
2016-05-24 23:49:54 +00:00
# ifdef SHOW_BUFFER_COLUMN
2016-05-27 17:31:45 +00:00
setApplicable ( col_buffer_ , false ) ;
2016-05-24 23:49:54 +00:00
# endif
} else {
# endif
2016-05-27 17:31:45 +00:00
setApplicable ( col_pmode_ , true ) ;
setCheckState ( col_pmode_ , device - > pmode ? Qt : : Checked : Qt : : Unchecked ) ;
2016-05-24 23:49:54 +00:00
QString snaplen_string = device - > has_snaplen ? QString : : number ( device - > snaplen ) : default_str ;
setText ( col_snaplen_ , snaplen_string ) ;
# ifdef SHOW_BUFFER_COLUMN
setText ( col_buffer_ , QString : : number ( device - > buffer ) ) ;
# endif
# ifdef HAVE_EXTCAP
}
# endif
setText ( col_filter_ , device - > cfilter ) ;
# ifdef SHOW_MONITOR_COLUMN
2016-05-27 17:31:45 +00:00
if ( device - > monitor_mode_supported ) {
setApplicable ( col_monitor_ , true ) ;
setCheckState ( col_monitor_ , device - > monitor_mode_enabled ? Qt : : Checked : Qt : : Unchecked ) ;
} else {
setApplicable ( col_monitor_ , false ) ;
}
2016-05-24 23:49:54 +00:00
# endif
2016-05-27 17:31:45 +00:00
}
void setApplicable ( int column , bool applicable = false ) {
QPalette palette = wsApp - > palette ( ) ;
2016-05-24 23:49:54 +00:00
2016-05-27 17:31:45 +00:00
if ( applicable ) {
setText ( column , QString ( ) ) ;
} else {
2016-06-05 18:58:19 +00:00
setData ( column , Qt : : CheckStateRole , QVariant ( ) ) ;
2016-05-27 17:31:45 +00:00
palette . setCurrentColorGroup ( QPalette : : Disabled ) ;
setText ( column , UTF8_EM_DASH ) ;
}
setTextColor ( column , palette . text ( ) . color ( ) ) ;
2016-05-24 23:49:54 +00:00
}
2014-08-06 21:50:48 +00:00
} ;
2013-11-25 14:15:49 +00:00
CaptureInterfacesDialog : : CaptureInterfacesDialog ( QWidget * parent ) :
2016-02-28 18:23:20 +00:00
GeometryStateDialog ( parent ) ,
2013-11-25 14:15:49 +00:00
ui ( new Ui : : CaptureInterfacesDialog )
{
ui - > setupUi ( this ) ;
2016-02-28 18:23:20 +00:00
loadGeometry ( ) ;
2014-12-31 22:21:50 +00:00
setWindowTitle ( wsApp - > windowTitleString ( tr ( " Capture Interfaces " ) ) ) ;
2013-11-25 14:15:49 +00:00
stat_timer_ = NULL ;
stat_cache_ = NULL ;
2016-05-31 19:43:42 +00:00
ui - > buttonBox - > button ( QDialogButtonBox : : Ok ) - > setText ( tr ( " Start " ) ) ;
2013-12-13 18:36:59 +00:00
2016-02-27 02:51:32 +00:00
// Start out with the list *not* sorted, so they show up in the order
// in which they were provided
ui - > interfaceTree - > sortByColumn ( - 1 , Qt : : AscendingOrder ) ;
2014-08-06 21:50:48 +00:00
ui - > interfaceTree - > setItemDelegateForColumn ( col_interface_ , & interface_item_delegate_ ) ;
ui - > interfaceTree - > setItemDelegateForColumn ( col_traffic_ , new SparkLineDelegate ( ) ) ;
ui - > interfaceTree - > setItemDelegateForColumn ( col_link_ , & interface_item_delegate_ ) ;
2016-05-27 17:31:45 +00:00
2014-08-06 21:50:48 +00:00
ui - > interfaceTree - > setItemDelegateForColumn ( col_snaplen_ , & interface_item_delegate_ ) ;
# ifdef SHOW_BUFFER_COLUMN
ui - > interfaceTree - > setItemDelegateForColumn ( col_buffer_ , & interface_item_delegate_ ) ;
# else
ui - > interfaceTree - > setColumnHidden ( col_buffer_ , true ) ;
# endif
2016-05-27 17:31:45 +00:00
# ifndef SHOW_MONITOR_COLUMN
2014-08-06 21:50:48 +00:00
ui - > interfaceTree - > setColumnHidden ( col_monitor_ , true ) ;
# endif
ui - > interfaceTree - > setItemDelegateForColumn ( col_filter_ , & interface_item_delegate_ ) ;
2014-08-14 20:20:09 +00:00
interface_item_delegate_ . setTree ( ui - > interfaceTree ) ;
2016-01-13 22:11:00 +00:00
ui - > filenameLineEdit - > setPlaceholderText ( tr ( " Leave blank to use a temporary file " ) ) ;
2016-02-23 18:04:16 +00:00
// Changes in interface selections or capture filters should be propagated
// to the main welcome screen where they will be applied to the global
// capture options.
connect ( this , SIGNAL ( interfacesChanged ( ) ) , ui - > captureFilterComboBox , SIGNAL ( interfacesChanged ( ) ) ) ;
2016-01-19 00:02:48 +00:00
connect ( ui - > captureFilterComboBox , SIGNAL ( captureFilterSyntaxChanged ( bool ) ) , this , SLOT ( updateWidgets ( ) ) ) ;
connect ( ui - > captureFilterComboBox - > lineEdit ( ) , SIGNAL ( textEdited ( QString ) ) ,
this , SLOT ( filterEdited ( ) ) ) ;
2016-02-23 18:04:16 +00:00
connect ( ui - > captureFilterComboBox - > lineEdit ( ) , SIGNAL ( textEdited ( QString ) ) ,
this , SIGNAL ( captureFilterTextEdited ( QString ) ) ) ;
2016-01-19 00:02:48 +00:00
connect ( & interface_item_delegate_ , SIGNAL ( filterChanged ( QString ) ) ,
ui - > captureFilterComboBox - > lineEdit ( ) , SLOT ( setText ( QString ) ) ) ;
2016-02-23 18:04:16 +00:00
connect ( & interface_item_delegate_ , SIGNAL ( filterChanged ( QString ) ) ,
this , SIGNAL ( captureFilterTextEdited ( QString ) ) ) ;
2014-06-24 09:36:51 +00:00
connect ( this , SIGNAL ( ifsChanged ( ) ) , this , SLOT ( refreshInterfaceList ( ) ) ) ;
2014-07-22 00:15:31 +00:00
connect ( wsApp , SIGNAL ( localInterfaceListChanged ( ) ) , this , SLOT ( updateLocalInterfaces ( ) ) ) ;
2015-06-25 21:39:43 +00:00
connect ( ui - > browseButton , SIGNAL ( clicked ( ) ) , this , SLOT ( browseButtonClicked ( ) ) ) ;
2017-02-24 17:26:40 +00:00
updateWidgets ( ) ;
2014-06-04 09:03:59 +00:00
}
2016-10-01 06:54:57 +00:00
/* Update global device selections based on the TreeWidget selection. */
void CaptureInterfacesDialog : : updateGlobalDeviceSelections ( )
{
# ifdef HAVE_LIBPCAP
QTreeWidgetItemIterator iter ( ui - > interfaceTree ) ;
global_capture_opts . num_selected = 0 ;
while ( * iter ) {
QString device_name = ( * iter ) - > data ( col_interface_ , Qt : : UserRole ) . value < QString > ( ) ;
for ( guint i = 0 ; i < global_capture_opts . all_ifaces - > len ; i + + ) {
2017-08-24 14:16:34 +00:00
interface_t * device = & g_array_index ( global_capture_opts . all_ifaces , interface_t , i ) ;
if ( device_name . compare ( QString ( ) . fromUtf8 ( device - > name ) ) = = 0 ) {
2017-08-28 08:38:31 +00:00
if ( ( * iter ) - > isSelected ( ) ) {
device - > selected = TRUE ;
global_capture_opts . num_selected + + ;
} else {
device - > selected = FALSE ;
2016-10-01 06:54:57 +00:00
}
break ;
}
}
+ + iter ;
}
# endif
}
2017-03-10 13:37:18 +00:00
/* Update TreeWidget selection based on global device selections. */
void CaptureInterfacesDialog : : updateFromGlobalDeviceSelections ( )
2014-06-04 09:03:59 +00:00
{
2017-03-10 13:37:18 +00:00
# ifdef HAVE_LIBPCAP
QTreeWidgetItemIterator iter ( ui - > interfaceTree ) ;
// Prevent recursive interface interfaceSelected signals
ui - > interfaceTree - > blockSignals ( true ) ;
while ( * iter ) {
QString device_name = ( * iter ) - > data ( col_interface_ , Qt : : UserRole ) . value < QString > ( ) ;
for ( guint i = 0 ; i < global_capture_opts . all_ifaces - > len ; i + + ) {
2017-08-24 14:16:34 +00:00
interface_t * device = & g_array_index ( global_capture_opts . all_ifaces , interface_t , i ) ;
if ( device_name . compare ( QString ( ) . fromUtf8 ( device - > name ) ) = = 0 ) {
if ( ( bool ) device - > selected ! = ( * iter ) - > isSelected ( ) ) {
( * iter ) - > setSelected ( device - > selected ) ;
2017-03-10 13:37:18 +00:00
}
break ;
}
}
+ + iter ;
}
2016-02-23 18:04:16 +00:00
2017-03-10 13:37:18 +00:00
ui - > interfaceTree - > blockSignals ( false ) ;
# endif
}
void CaptureInterfacesDialog : : interfaceSelected ( )
{
if ( sender ( ) = = ui - > interfaceTree ) {
// Local changes, propagate our changes
updateGlobalDeviceSelections ( ) ;
emit interfacesChanged ( ) ;
} else {
// Changes from the welcome screen, adjust to its state.
updateFromGlobalDeviceSelections ( ) ;
}
2016-02-23 18:04:16 +00:00
updateSelectedFilter ( ) ;
2014-06-04 09:03:59 +00:00
2014-07-22 00:33:38 +00:00
updateWidgets ( ) ;
}
2016-01-19 00:02:48 +00:00
void CaptureInterfacesDialog : : filterEdited ( )
{
QList < QTreeWidgetItem * > si = ui - > interfaceTree - > selectedItems ( ) ;
foreach ( QTreeWidgetItem * ti , si ) {
ti - > setText ( col_filter_ , ui - > captureFilterComboBox - > lineEdit ( ) - > text ( ) ) ;
}
2016-03-10 08:02:28 +00:00
if ( si . count ( ) > 0 ) {
QModelIndex col_filter_idx = ui - > interfaceTree - > model ( ) - > index ( ui - > interfaceTree - > indexOfTopLevelItem ( si [ 0 ] ) , col_filter_ ) ;
ui - > interfaceTree - > scrollTo ( col_filter_idx ) ;
}
2016-01-19 00:02:48 +00:00
}
2014-07-22 00:33:38 +00:00
void CaptureInterfacesDialog : : updateWidgets ( )
{
2016-01-19 00:02:48 +00:00
SyntaxLineEdit * sle = qobject_cast < SyntaxLineEdit * > ( ui - > captureFilterComboBox - > lineEdit ( ) ) ;
2014-07-22 00:33:38 +00:00
if ( ! sle ) {
return ;
}
bool can_capture = false ;
2014-08-06 21:50:48 +00:00
if ( ui - > interfaceTree - > selectedItems ( ) . count ( ) > 0 & & sle - > syntaxState ( ) ! = SyntaxLineEdit : : Invalid ) {
2014-07-22 00:33:38 +00:00
can_capture = true ;
}
ui - > compileBPF - > setEnabled ( can_capture ) ;
2016-05-31 19:43:42 +00:00
ui - > buttonBox - > button ( QDialogButtonBox : : Ok ) - > setEnabled ( can_capture ) ;
2013-11-25 14:15:49 +00:00
}
CaptureInterfacesDialog : : ~ CaptureInterfacesDialog ( )
{
delete ui ;
}
2016-09-27 16:55:08 +00:00
void CaptureInterfacesDialog : : setTab ( int idx )
2013-11-25 14:15:49 +00:00
{
2016-09-27 16:55:08 +00:00
ui - > tabWidget - > setCurrentIndex ( idx ) ;
2013-11-25 14:15:49 +00:00
}
void CaptureInterfacesDialog : : on_capturePromModeCheckBox_toggled ( bool checked )
{
2015-02-15 23:37:03 +00:00
interface_t * device ;
2013-11-25 14:15:49 +00:00
prefs . capture_prom_mode = checked ;
2014-08-06 21:50:48 +00:00
for ( int row = 0 ; row < ui - > interfaceTree - > topLevelItemCount ( ) ; row + + ) {
2016-05-24 23:49:54 +00:00
InterfaceTreeWidgetItem * ti = dynamic_cast < InterfaceTreeWidgetItem * > ( ui - > interfaceTree - > topLevelItem ( row ) ) ;
if ( ! ti ) continue ;
2016-02-23 18:04:16 +00:00
QString device_name = ti - > data ( col_interface_ , Qt : : UserRole ) . toString ( ) ;
device = getDeviceByName ( device_name ) ;
if ( ! device ) continue ;
2015-02-15 23:37:03 +00:00
device - > pmode = checked ;
2016-05-24 23:49:54 +00:00
ti - > updateInterfaceColumns ( device ) ;
2014-06-04 09:03:59 +00:00
}
2013-11-25 14:15:49 +00:00
}
2015-06-25 21:39:43 +00:00
void CaptureInterfacesDialog : : browseButtonClicked ( )
2014-08-18 08:04:16 +00:00
{
char * open_dir = NULL ;
switch ( prefs . gui_fileopen_style ) {
case FO_STYLE_LAST_OPENED :
open_dir = get_last_open_dir ( ) ;
break ;
case FO_STYLE_SPECIFIED :
if ( prefs . gui_fileopen_dir [ 0 ] ! = ' \0 ' )
open_dir = prefs . gui_fileopen_dir ;
break ;
}
2015-06-25 21:39:43 +00:00
QString file_name = QFileDialog : : getSaveFileName ( this , tr ( " Specify a Capture File " ) , open_dir ) ;
2016-01-13 22:11:00 +00:00
ui - > filenameLineEdit - > setText ( file_name ) ;
2014-08-18 08:04:16 +00:00
}
2016-05-27 17:31:45 +00:00
void CaptureInterfacesDialog : : interfaceItemChanged ( QTreeWidgetItem * item , int column )
{
QWidget * editor = ui - > interfaceTree - > indexWidget ( ui - > interfaceTree - > currentIndex ( ) ) ;
if ( editor ) {
ui - > interfaceTree - > closePersistentEditor ( item , ui - > interfaceTree - > currentColumn ( ) ) ;
}
InterfaceTreeWidgetItem * ti = dynamic_cast < InterfaceTreeWidgetItem * > ( item ) ;
if ( ! ti ) return ;
interface_t * device ;
QString interface_name = ti - > text ( col_interface_ ) ;
device = find_device_by_if_name ( interface_name ) ;
if ( ! device ) return ;
switch ( column ) {
case col_pmode_ :
device - > pmode = item - > checkState ( col_pmode_ ) = = Qt : : Checked ? TRUE : FALSE ;
ti - > updateInterfaceColumns ( device ) ;
break ;
# ifdef SHOW_MONITOR_COLUMN
case col_monitor_ :
{
gboolean monitor_mode = FALSE ;
if ( ti - > checkState ( col_monitor_ ) = = Qt : : Checked ) monitor_mode = TRUE ;
if_capabilities_t * caps ;
char * auth_str = NULL ;
QString active_dlt_name ;
set_active_dlt ( device , global_capture_opts . default_options . linktype ) ;
# ifdef HAVE_PCAP_REMOTE
if ( device - > remote_opts . remote_host_opts . auth_type = = CAPTURE_AUTH_PWD ) {
auth_str = g_strdup_printf ( " %s:%s " , device - > remote_opts . remote_host_opts . auth_username ,
device - > remote_opts . remote_host_opts . auth_password ) ;
}
# endif
caps = capture_get_if_capabilities ( device - > name , monitor_mode , auth_str , NULL , main_window_update ) ;
g_free ( auth_str ) ;
if ( caps ! = NULL ) {
for ( int i = ( gint ) g_list_length ( device - > links ) - 1 ; i > = 0 ; i - - ) {
GList * rem = g_list_nth ( device - > links , i ) ;
device - > links = g_list_remove_link ( device - > links , rem ) ;
g_list_free_1 ( rem ) ;
}
device - > active_dlt = - 1 ;
device - > monitor_mode_supported = caps - > can_set_rfmon ;
device - > monitor_mode_enabled = monitor_mode ;
for ( GList * lt_entry = caps - > data_link_types ; lt_entry ! = NULL ; lt_entry = g_list_next ( lt_entry ) ) {
link_row * linkr = ( link_row * ) g_malloc ( sizeof ( link_row ) ) ;
data_link_info_t * data_link_info = ( data_link_info_t * ) lt_entry - > data ;
/*
* For link - layer types libpcap / WinPcap doesn ' t know about , the
* name will be " DLT n " , and the description will be null .
* We mark those as unsupported , and don ' t allow them to be
* used - capture filters won ' t work on them , for example .
*/
if ( data_link_info - > description ! = NULL ) {
linkr - > dlt = data_link_info - > dlt ;
if ( active_dlt_name . isEmpty ( ) ) {
device - > active_dlt = data_link_info - > dlt ;
active_dlt_name = data_link_info - > description ;
}
linkr - > name = g_strdup ( data_link_info - > description ) ;
} else {
gchar * str ;
/* XXX - should we just omit them? */
str = g_strdup_printf ( " %s (not supported) " , data_link_info - > name ) ;
linkr - > dlt = - 1 ;
linkr - > name = g_strdup ( str ) ;
g_free ( str ) ;
}
device - > links = g_list_append ( device - > links , linkr ) ;
}
free_if_capabilities ( caps ) ;
} else {
/* We don't know whether this supports monitor mode or not;
don ' t ask for monitor mode . */
device - > monitor_mode_enabled = FALSE ;
device - > monitor_mode_supported = FALSE ;
}
ti - > updateInterfaceColumns ( device ) ;
break ;
}
# endif // SHOW_MONITOR_COLUMN
default :
break ;
}
}
2013-12-13 18:36:59 +00:00
void CaptureInterfacesDialog : : on_gbStopCaptureAuto_toggled ( bool checked )
2013-11-25 14:15:49 +00:00
{
2017-06-27 20:04:33 +00:00
global_capture_opts . has_file_interval = checked ;
2013-11-25 14:15:49 +00:00
}
2013-12-13 18:36:59 +00:00
void CaptureInterfacesDialog : : on_gbNewFileAuto_toggled ( bool checked )
2013-11-25 14:15:49 +00:00
{
global_capture_opts . multi_files_on = checked ;
2014-08-18 08:04:16 +00:00
ui - > stopMBCheckBox - > setEnabled ( checked ? false : true ) ;
ui - > stopMBSpinBox - > setEnabled ( checked ? false : true ) ;
ui - > stopMBComboBox - > setEnabled ( checked ? false : true ) ;
2013-11-25 14:15:49 +00:00
}
void CaptureInterfacesDialog : : on_cbUpdatePacketsRT_toggled ( bool checked )
{
global_capture_opts . real_time_mode = checked ;
}
void CaptureInterfacesDialog : : on_cbAutoScroll_toggled ( bool checked )
{
2014-08-18 08:04:16 +00:00
auto_scroll_live = checked ;
2013-11-25 14:15:49 +00:00
}
void CaptureInterfacesDialog : : on_cbExtraCaptureInfo_toggled ( bool checked )
{
global_capture_opts . show_info = checked ;
}
void CaptureInterfacesDialog : : on_cbResolveMacAddresses_toggled ( bool checked )
{
gbl_resolv_flags . mac_name = checked ;
}
void CaptureInterfacesDialog : : on_cbResolveNetworkNames_toggled ( bool checked )
{
gbl_resolv_flags . network_name = checked ;
}
void CaptureInterfacesDialog : : on_cbResolveTransportNames_toggled ( bool checked )
{
gbl_resolv_flags . transport_name = checked ;
}
2016-05-31 19:43:42 +00:00
void CaptureInterfacesDialog : : on_buttonBox_accepted ( )
2013-11-25 14:15:49 +00:00
{
2014-08-18 08:04:16 +00:00
if ( saveOptionsToPreferences ( ) ) {
2016-01-19 00:02:48 +00:00
emit setFilterValid ( true , ui - > captureFilterComboBox - > lineEdit ( ) - > text ( ) ) ;
2014-08-18 08:04:16 +00:00
accept ( ) ;
}
2013-11-25 14:15:49 +00:00
}
2013-12-13 18:36:59 +00:00
// Not sure why we have to do this manually.
void CaptureInterfacesDialog : : on_buttonBox_rejected ( )
{
2014-08-18 08:04:16 +00:00
if ( saveOptionsToPreferences ( ) ) {
reject ( ) ;
}
2013-12-13 18:36:59 +00:00
}
void CaptureInterfacesDialog : : on_buttonBox_helpRequested ( )
{
// Probably the wrong URL.
wsApp - > helpTopicAction ( HELP_CAPTURE_INTERFACES_DIALOG ) ;
}
2014-08-06 21:50:48 +00:00
void CaptureInterfacesDialog : : updateInterfaces ( )
2013-11-25 14:15:49 +00:00
{
2013-12-13 18:36:59 +00:00
if ( prefs . capture_pcap_ng ) {
ui - > rbPcapng - > setChecked ( true ) ;
} else {
ui - > rbPcap - > setChecked ( true ) ;
}
2013-11-25 14:15:49 +00:00
ui - > capturePromModeCheckBox - > setChecked ( prefs . capture_prom_mode ) ;
2014-08-18 08:04:16 +00:00
if ( global_capture_opts . saving_to_file ) {
2016-01-13 22:11:00 +00:00
ui - > filenameLineEdit - > setText ( QString ( global_capture_opts . orig_save_file ) ) ;
2014-08-18 08:04:16 +00:00
}
2013-12-13 18:36:59 +00:00
ui - > gbNewFileAuto - > setChecked ( global_capture_opts . multi_files_on ) ;
2016-01-13 22:11:00 +00:00
ui - > MBCheckBox - > setChecked ( global_capture_opts . has_autostop_filesize ) ;
2017-06-27 20:04:33 +00:00
ui - > SecsCheckBox - > setChecked ( global_capture_opts . has_file_interval ) ;
2014-08-18 08:04:16 +00:00
if ( global_capture_opts . has_autostop_filesize ) {
int value = global_capture_opts . autostop_filesize ;
if ( value > 1000000 ) {
if ( global_capture_opts . multi_files_on ) {
ui - > MBSpinBox - > setValue ( value / 1000000 ) ;
ui - > MBComboBox - > setCurrentIndex ( 2 ) ;
} else {
ui - > stopMBCheckBox - > setChecked ( true ) ;
ui - > stopMBSpinBox - > setValue ( value / 1000000 ) ;
ui - > stopMBComboBox - > setCurrentIndex ( 2 ) ;
}
} else if ( value > 1000 & & value % 1000 = = 0 ) {
if ( global_capture_opts . multi_files_on ) {
ui - > MBSpinBox - > setValue ( value / 1000 ) ;
ui - > MBComboBox - > setCurrentIndex ( 1 ) ;
} else {
ui - > stopMBCheckBox - > setChecked ( true ) ;
ui - > stopMBSpinBox - > setValue ( value / 1000 ) ;
ui - > stopMBComboBox - > setCurrentIndex ( 1 ) ;
}
} else {
if ( global_capture_opts . multi_files_on ) {
ui - > MBSpinBox - > setValue ( value ) ;
ui - > MBComboBox - > setCurrentIndex ( 0 ) ;
} else {
ui - > stopMBCheckBox - > setChecked ( true ) ;
ui - > stopMBSpinBox - > setValue ( value ) ;
ui - > stopMBComboBox - > setCurrentIndex ( 0 ) ;
}
}
}
2017-06-27 20:04:33 +00:00
if ( global_capture_opts . has_file_interval ) {
int value = global_capture_opts . file_interval ;
2014-08-18 08:04:16 +00:00
if ( value > 3600 & & value % 3600 = = 0 ) {
ui - > SecsSpinBox - > setValue ( value / 3600 ) ;
ui - > SecsComboBox - > setCurrentIndex ( 2 ) ;
} else if ( value > 60 & & value % 60 = = 0 ) {
ui - > SecsSpinBox - > setValue ( value / 60 ) ;
ui - > SecsComboBox - > setCurrentIndex ( 1 ) ;
} else {
ui - > SecsSpinBox - > setValue ( value ) ;
ui - > SecsComboBox - > setCurrentIndex ( 0 ) ;
}
}
if ( global_capture_opts . has_ring_num_files ) {
ui - > RbSpinBox - > setValue ( global_capture_opts . ring_num_files ) ;
ui - > RbCheckBox - > setCheckState ( Qt : : Checked ) ;
}
if ( global_capture_opts . has_autostop_duration ) {
ui - > stopSecsCheckBox - > setChecked ( true ) ;
2017-06-27 20:04:33 +00:00
int value = global_capture_opts . file_interval ;
2014-08-18 08:04:16 +00:00
if ( value > 3600 & & value % 3600 = = 0 ) {
ui - > stopSecsSpinBox - > setValue ( value / 3600 ) ;
ui - > stopSecsComboBox - > setCurrentIndex ( 2 ) ;
} else if ( value > 60 & & value % 60 = = 0 ) {
ui - > stopSecsSpinBox - > setValue ( value / 60 ) ;
ui - > stopSecsComboBox - > setCurrentIndex ( 1 ) ;
} else {
ui - > stopSecsSpinBox - > setValue ( value ) ;
ui - > stopSecsComboBox - > setCurrentIndex ( 0 ) ;
}
}
if ( global_capture_opts . has_autostop_packets ) {
ui - > stopPktCheckBox - > setChecked ( true ) ;
ui - > stopPktSpinBox - > setValue ( global_capture_opts . autostop_packets ) ;
}
2013-11-25 14:15:49 +00:00
2015-06-25 21:39:43 +00:00
if ( global_capture_opts . has_autostop_files ) {
ui - > stopFilesCheckBox - > setChecked ( true ) ;
ui - > stopFilesSpinBox - > setValue ( global_capture_opts . autostop_files ) ;
}
2013-11-25 14:15:49 +00:00
ui - > cbUpdatePacketsRT - > setChecked ( global_capture_opts . real_time_mode ) ;
ui - > cbAutoScroll - > setChecked ( true ) ;
ui - > cbExtraCaptureInfo - > setChecked ( global_capture_opts . show_info ) ;
ui - > cbResolveMacAddresses - > setChecked ( gbl_resolv_flags . mac_name ) ;
ui - > cbResolveNetworkNames - > setChecked ( gbl_resolv_flags . network_name ) ;
ui - > cbResolveTransportNames - > setChecked ( gbl_resolv_flags . transport_name ) ;
2016-02-23 18:04:16 +00:00
// Rebuild the interface list without disturbing the main welcome screen.
disconnect ( ui - > interfaceTree , SIGNAL ( itemSelectionChanged ( ) ) , this , SLOT ( interfaceSelected ( ) ) ) ;
2014-08-06 21:50:48 +00:00
ui - > interfaceTree - > clear ( ) ;
2013-11-25 14:15:49 +00:00
2014-08-06 21:50:48 +00:00
# ifdef SHOW_BUFFER_COLUMN
2013-11-25 14:15:49 +00:00
gint buffer ;
2014-08-06 21:50:48 +00:00
# endif
2013-11-25 14:15:49 +00:00
gint snaplen ;
gboolean hassnap , pmode ;
2016-02-23 18:04:16 +00:00
QList < QTreeWidgetItem * > selected_interfaces ;
2013-11-25 14:15:49 +00:00
2016-05-27 17:31:45 +00:00
disconnect ( ui - > interfaceTree , SIGNAL ( itemChanged ( QTreeWidgetItem * , int ) ) , this , SLOT ( interfaceItemChanged ( QTreeWidgetItem * , int ) ) ) ;
2014-06-04 09:03:59 +00:00
if ( global_capture_opts . all_ifaces - > len > 0 ) {
2015-02-15 23:37:03 +00:00
interface_t * device ;
2013-11-25 14:15:49 +00:00
2016-01-19 00:02:48 +00:00
for ( guint device_idx = 0 ; device_idx < global_capture_opts . all_ifaces - > len ; device_idx + + ) {
device = & g_array_index ( global_capture_opts . all_ifaces , interface_t , device_idx ) ;
2013-11-25 14:15:49 +00:00
/* Continue if capture device is hidden */
2015-02-15 23:37:03 +00:00
if ( device - > hidden ) {
2013-11-25 14:15:49 +00:00
continue ;
}
2014-08-06 21:50:48 +00:00
// Traffic sparklines
InterfaceTreeWidgetItem * ti = new InterfaceTreeWidgetItem ( ui - > interfaceTree ) ;
ti - > setFlags ( ti - > flags ( ) | Qt : : ItemIsEditable ) ;
2016-02-23 18:04:16 +00:00
ti - > setData ( col_interface_ , Qt : : UserRole , QString ( device - > name ) ) ;
2017-01-10 23:33:46 +00:00
ti - > setData ( col_traffic_ , Qt : : UserRole , qVariantFromValue ( ti - > points ) ) ;
2014-08-06 21:50:48 +00:00
2015-02-15 23:37:03 +00:00
ti - > setText ( col_interface_ , device - > display_name ) ;
if ( device - > no_addresses > 0 ) {
QString addr_str = tr ( " %1: %2 " ) . arg ( device - > no_addresses > 1 ? tr ( " Addresses " ) : tr ( " Address " ) ) . arg ( device - > addresses ) ;
2014-08-06 21:50:48 +00:00
QTreeWidgetItem * addr_ti = new QTreeWidgetItem ( ti ) ;
addr_str . replace ( ' \n ' , " , " ) ;
addr_ti - > setText ( 0 , addr_str ) ;
addr_ti - > setFlags ( addr_ti - > flags ( ) ^ Qt : : ItemIsSelectable ) ;
addr_ti - > setFirstColumnSpanned ( true ) ;
2014-08-14 20:20:09 +00:00
addr_ti - > setToolTip ( col_interface_ , QString ( " <span>%1</span> " ) . arg ( addr_str ) ) ;
2014-08-06 21:50:48 +00:00
ti - > setToolTip ( col_interface_ , QString ( " <span>%1</span> " ) . arg ( addr_str ) ) ;
} else {
ti - > setToolTip ( col_interface_ , tr ( " no addresses " ) ) ;
}
2015-04-04 21:01:56 +00:00
if ( capture_dev_user_pmode_find ( device - > name , & pmode ) ) {
2015-02-15 23:37:03 +00:00
device - > pmode = pmode ;
2013-11-25 14:15:49 +00:00
}
2015-03-18 23:58:15 +00:00
if ( capture_dev_user_snaplen_find ( device - > name , & hassnap , & snaplen ) ) {
2014-08-06 21:50:48 +00:00
/* Default snap length set in preferences */
2015-02-15 23:37:03 +00:00
device - > snaplen = snaplen ;
Allow bigger snapshot lengths for D-Bus captures.
Use WTAP_MAX_PACKET_SIZE_STANDARD, set to 256KB, for everything except
for D-Bus captures. Use WTAP_MAX_PACKET_SIZE_DBUS, set to 128MB, for
them, because that's the largest possible D-Bus message size. See
https://bugs.freedesktop.org/show_bug.cgi?id=100220
for an example of the problems caused by limiting the snapshot length to
256KB for D-Bus.
Have a snapshot length of 0 in a capture_file structure mean "there is
no snapshot length for the file"; we don't need the has_snap field in
that case, a value of 0 mean "no, we don't have a snapshot length".
In dumpcap, start out with a pipe buffer size of 2KB, and grow it as
necessary. When checking for a too-big packet from a pipe, check
against the appropriate maximum - 128MB for DLT_DBUS, 256KB for
everything else.
Change-Id: Ib2ce7a0cf37b971fbc0318024fd011e18add8b20
Reviewed-on: https://code.wireshark.org/review/21952
Petri-Dish: Guy Harris <guy@alum.mit.edu>
Tested-by: Petri Dish Buildbot <buildbot-no-reply@wireshark.org>
Reviewed-by: Guy Harris <guy@alum.mit.edu>
2017-06-05 01:58:40 +00:00
device - > has_snaplen = snaplen = = WTAP_MAX_PACKET_SIZE_STANDARD ? FALSE : hassnap ;
2013-11-25 14:15:49 +00:00
} else {
2014-08-06 21:50:48 +00:00
/* No preferences set yet, use default values */
Allow bigger snapshot lengths for D-Bus captures.
Use WTAP_MAX_PACKET_SIZE_STANDARD, set to 256KB, for everything except
for D-Bus captures. Use WTAP_MAX_PACKET_SIZE_DBUS, set to 128MB, for
them, because that's the largest possible D-Bus message size. See
https://bugs.freedesktop.org/show_bug.cgi?id=100220
for an example of the problems caused by limiting the snapshot length to
256KB for D-Bus.
Have a snapshot length of 0 in a capture_file structure mean "there is
no snapshot length for the file"; we don't need the has_snap field in
that case, a value of 0 mean "no, we don't have a snapshot length".
In dumpcap, start out with a pipe buffer size of 2KB, and grow it as
necessary. When checking for a too-big packet from a pipe, check
against the appropriate maximum - 128MB for DLT_DBUS, 256KB for
everything else.
Change-Id: Ib2ce7a0cf37b971fbc0318024fd011e18add8b20
Reviewed-on: https://code.wireshark.org/review/21952
Petri-Dish: Guy Harris <guy@alum.mit.edu>
Tested-by: Petri Dish Buildbot <buildbot-no-reply@wireshark.org>
Reviewed-by: Guy Harris <guy@alum.mit.edu>
2017-06-05 01:58:40 +00:00
device - > snaplen = WTAP_MAX_PACKET_SIZE_STANDARD ;
2015-02-15 23:37:03 +00:00
device - > has_snaplen = FALSE ;
2013-11-25 14:15:49 +00:00
}
2014-08-06 21:50:48 +00:00
# ifdef SHOW_BUFFER_COLUMN
2015-02-15 23:37:03 +00:00
if ( capture_dev_user_buffersize_find ( device - > name ) ! = - 1 ) {
buffer = capture_dev_user_buffersize_find ( device - > name ) ;
device - > buffer = buffer ;
2013-11-25 14:15:49 +00:00
} else {
2015-02-15 23:37:03 +00:00
device - > buffer = DEFAULT_CAPTURE_BUFFER_SIZE ;
2013-11-25 14:15:49 +00:00
}
2014-08-06 21:50:48 +00:00
# endif
2016-05-24 23:49:54 +00:00
ti - > updateInterfaceColumns ( device ) ;
2013-11-25 14:15:49 +00:00
2016-02-23 18:04:16 +00:00
if ( device - > selected ) {
selected_interfaces < < ti ;
2013-11-25 14:15:49 +00:00
}
}
}
2014-08-06 21:50:48 +00:00
2016-05-27 17:31:45 +00:00
connect ( ui - > interfaceTree , SIGNAL ( itemChanged ( QTreeWidgetItem * , int ) ) , this , SLOT ( interfaceItemChanged ( QTreeWidgetItem * , int ) ) ) ;
2016-02-23 18:04:16 +00:00
foreach ( QTreeWidgetItem * ti , selected_interfaces ) {
ti - > setSelected ( true ) ;
}
connect ( ui - > interfaceTree , SIGNAL ( itemSelectionChanged ( ) ) , this , SLOT ( interfaceSelected ( ) ) ) ;
updateSelectedFilter ( ) ;
2016-02-25 20:29:38 +00:00
// Manually or automatically size some columns as needed.
int one_em = fontMetrics ( ) . height ( ) ;
for ( int col = 0 ; col < ui - > interfaceTree - > topLevelItemCount ( ) ; col + + ) {
switch ( col ) {
case col_pmode_ :
2016-05-27 17:31:45 +00:00
ui - > interfaceTree - > setColumnWidth ( col , one_em * 3.25 ) ;
2016-02-25 20:29:38 +00:00
break ;
case col_snaplen_ :
ui - > interfaceTree - > setColumnWidth ( col , one_em * 4.25 ) ;
break ;
case col_buffer_ :
ui - > interfaceTree - > setColumnWidth ( col , one_em * 4.25 ) ;
break ;
case col_monitor_ :
2016-05-27 17:31:45 +00:00
ui - > interfaceTree - > setColumnWidth ( col , one_em * 3.25 ) ;
2016-02-25 20:29:38 +00:00
break ;
default :
ui - > interfaceTree - > resizeColumnToContents ( col ) ;
}
2014-08-06 21:50:48 +00:00
}
2017-02-24 17:26:40 +00:00
updateWidgets ( ) ;
2013-11-25 14:15:49 +00:00
if ( ! stat_timer_ ) {
updateStatistics ( ) ;
stat_timer_ = new QTimer ( this ) ;
connect ( stat_timer_ , SIGNAL ( timeout ( ) ) , this , SLOT ( updateStatistics ( ) ) ) ;
stat_timer_ - > start ( stat_update_interval_ ) ;
}
}
2016-02-23 18:04:16 +00:00
void CaptureInterfacesDialog : : showEvent ( QShowEvent * )
{
updateInterfaces ( ) ;
}
2014-06-24 09:36:51 +00:00
void CaptureInterfacesDialog : : refreshInterfaceList ( )
{
2014-08-06 21:50:48 +00:00
updateInterfaces ( ) ;
2014-06-24 09:36:51 +00:00
emit interfaceListChanged ( ) ;
}
2014-07-22 00:15:31 +00:00
void CaptureInterfacesDialog : : updateLocalInterfaces ( )
{
2014-08-06 21:50:48 +00:00
updateInterfaces ( ) ;
2014-07-22 00:15:31 +00:00
}
2013-11-25 17:01:10 +00:00
void CaptureInterfacesDialog : : updateStatistics ( void )
{
2015-02-15 23:37:03 +00:00
interface_t * device ;
2013-11-25 14:15:49 +00:00
2017-03-27 14:17:51 +00:00
disconnect ( ui - > interfaceTree , SIGNAL ( itemChanged ( QTreeWidgetItem * , int ) ) , this , SLOT ( interfaceItemChanged ( QTreeWidgetItem * , int ) ) ) ;
2014-08-06 21:50:48 +00:00
for ( int row = 0 ; row < ui - > interfaceTree - > topLevelItemCount ( ) ; row + + ) {
2013-11-25 14:15:49 +00:00
2014-06-04 09:03:59 +00:00
for ( guint if_idx = 0 ; if_idx < global_capture_opts . all_ifaces - > len ; if_idx + + ) {
2014-08-06 21:50:48 +00:00
QTreeWidgetItem * ti = ui - > interfaceTree - > topLevelItem ( row ) ;
if ( ! ti ) {
continue ;
}
2015-02-15 23:37:03 +00:00
device = & g_array_index ( global_capture_opts . all_ifaces , interface_t , if_idx ) ;
2014-08-06 21:50:48 +00:00
QString device_name = ti - > text ( col_interface_ ) ;
2015-02-15 23:37:03 +00:00
if ( device_name . compare ( device - > display_name ) | | device - > hidden | | device - > type = = IF_PIPE ) {
2014-06-04 09:03:59 +00:00
continue ;
}
2017-01-10 23:33:46 +00:00
QList < int > points = ti - > data ( col_traffic_ , Qt : : UserRole ) . value < QList < int > > ( ) ;
points . append ( device - > packet_diff ) ;
2014-08-06 21:50:48 +00:00
ti - > setData ( col_traffic_ , Qt : : UserRole , qVariantFromValue ( points ) ) ;
2014-06-04 09:03:59 +00:00
}
2013-11-25 14:15:49 +00:00
}
2017-03-27 14:17:51 +00:00
connect ( ui - > interfaceTree , SIGNAL ( itemChanged ( QTreeWidgetItem * , int ) ) , this , SLOT ( interfaceItemChanged ( QTreeWidgetItem * , int ) ) ) ;
2014-08-06 21:50:48 +00:00
ui - > interfaceTree - > viewport ( ) - > update ( ) ;
2014-06-04 09:03:59 +00:00
}
2013-11-25 14:15:49 +00:00
2014-06-04 09:03:59 +00:00
void CaptureInterfacesDialog : : on_compileBPF_clicked ( )
{
2014-08-06 21:50:48 +00:00
QStringList interfaces ;
foreach ( QTreeWidgetItem * ti , ui - > interfaceTree - > selectedItems ( ) ) {
interfaces . append ( ti - > text ( col_interface_ ) ) ;
2014-06-04 09:03:59 +00:00
}
2013-11-25 14:15:49 +00:00
2016-01-19 00:02:48 +00:00
QString filter = ui - > captureFilterComboBox - > currentText ( ) ;
2014-06-04 09:03:59 +00:00
CompiledFilterOutput * cfo = new CompiledFilterOutput ( this , interfaces , filter ) ;
2013-11-25 14:15:49 +00:00
2014-06-04 09:03:59 +00:00
cfo - > show ( ) ;
}
2013-11-25 14:15:49 +00:00
2014-08-18 08:04:16 +00:00
bool CaptureInterfacesDialog : : saveOptionsToPreferences ( )
2014-06-04 09:03:59 +00:00
{
2014-08-18 08:04:16 +00:00
if ( ui - > rbPcapng - > isChecked ( ) ) {
global_capture_opts . use_pcapng = true ;
prefs . capture_pcap_ng = true ;
} else {
global_capture_opts . use_pcapng = false ;
prefs . capture_pcap_ng = false ;
}
2016-01-13 22:11:00 +00:00
QString filename = ui - > filenameLineEdit - > text ( ) ;
2014-08-18 08:04:16 +00:00
if ( filename . length ( ) > 0 ) {
/* User specified a file to which the capture should be written. */
global_capture_opts . saving_to_file = true ;
2014-08-14 20:20:09 +00:00
global_capture_opts . save_file = qstring_strdup ( filename ) ;
global_capture_opts . orig_save_file = qstring_strdup ( filename ) ;
2014-08-18 08:04:16 +00:00
/* Save the directory name for future file dialogs. */
2014-08-14 20:20:09 +00:00
set_last_open_dir ( get_dirname ( filename . toUtf8 ( ) . data ( ) ) ) ;
2014-08-18 08:04:16 +00:00
} else {
/* User didn't specify a file; save to a temporary file. */
global_capture_opts . save_file = NULL ;
}
global_capture_opts . has_ring_num_files = ui - > RbCheckBox - > isChecked ( ) ;
if ( global_capture_opts . has_ring_num_files ) {
global_capture_opts . ring_num_files = ui - > RbSpinBox - > value ( ) ;
if ( global_capture_opts . ring_num_files > RINGBUFFER_MAX_NUM_FILES )
global_capture_opts . ring_num_files = RINGBUFFER_MAX_NUM_FILES ;
# if RINGBUFFER_MIN_NUM_FILES > 0
else if ( global_capture_opts . ring_num_files < RINGBUFFER_MIN_NUM_FILES )
global_capture_opts . ring_num_files = RINGBUFFER_MIN_NUM_FILES ;
# endif
}
global_capture_opts . multi_files_on = ui - > gbNewFileAuto - > isChecked ( ) ;
if ( global_capture_opts . multi_files_on ) {
2017-06-27 20:04:33 +00:00
global_capture_opts . has_file_interval = ui - > SecsCheckBox - > isChecked ( ) ;
if ( global_capture_opts . has_file_interval ) {
global_capture_opts . file_interval = ui - > SecsSpinBox - > value ( ) ;
2014-08-18 08:04:16 +00:00
int index = ui - > SecsComboBox - > currentIndex ( ) ;
switch ( index ) {
2017-06-27 20:04:33 +00:00
case 1 : global_capture_opts . file_interval * = 60 ;
2014-08-18 08:04:16 +00:00
break ;
2017-06-27 20:04:33 +00:00
case 2 : global_capture_opts . file_interval * = 3600 ;
2014-08-18 08:04:16 +00:00
break ;
}
}
2016-01-13 22:11:00 +00:00
global_capture_opts . has_autostop_filesize = ui - > MBCheckBox - > isChecked ( ) ;
2014-08-18 08:04:16 +00:00
if ( global_capture_opts . has_autostop_filesize ) {
global_capture_opts . autostop_filesize = ui - > MBSpinBox - > value ( ) ;
int index = ui - > MBComboBox - > currentIndex ( ) ;
switch ( index ) {
case 1 : if ( global_capture_opts . autostop_filesize > 2000 ) {
QMessageBox : : warning ( this , tr ( " Error " ) ,
2017-02-19 18:58:47 +00:00
tr ( " Multiple files: Requested filesize too large. The filesize cannot be greater than 2 GiB. " ) ) ;
2014-08-18 08:04:16 +00:00
return false ;
} else {
global_capture_opts . autostop_filesize * = 1000 ;
}
break ;
case 2 : if ( global_capture_opts . autostop_filesize > 2 ) {
QMessageBox : : warning ( this , tr ( " Error " ) ,
2017-02-19 18:58:47 +00:00
tr ( " Multiple files: Requested filesize too large. The filesize cannot be greater than 2 GiB. " ) ) ;
2014-08-18 08:04:16 +00:00
return false ;
} else {
global_capture_opts . autostop_filesize * = 1000000 ;
}
break ;
}
}
/* test if the settings are ok for a ringbuffer */
if ( global_capture_opts . save_file = = NULL ) {
QMessageBox : : warning ( this , tr ( " Error " ) ,
2017-02-19 18:58:47 +00:00
tr ( " Multiple files: No capture file name given. You must specify a filename if you want to use multiple files. " ) ) ;
2014-08-18 08:04:16 +00:00
return false ;
2017-06-27 20:04:33 +00:00
} else if ( ! global_capture_opts . has_autostop_filesize & & ! global_capture_opts . has_file_interval ) {
2014-08-18 08:04:16 +00:00
QMessageBox : : warning ( this , tr ( " Error " ) ,
2017-06-27 20:04:33 +00:00
tr ( " Multiple files: No file limit given. You must specify a file size or interval at which is switched to the next capture file \n if you want to use multiple files. " ) ) ;
2014-08-18 08:04:16 +00:00
g_free ( global_capture_opts . save_file ) ;
global_capture_opts . save_file = NULL ;
return false ;
}
} else {
global_capture_opts . has_autostop_filesize = ui - > stopMBCheckBox - > isChecked ( ) ;
if ( global_capture_opts . has_autostop_filesize ) {
global_capture_opts . autostop_filesize = ui - > stopMBSpinBox - > value ( ) ;
int index = ui - > stopMBComboBox - > currentIndex ( ) ;
switch ( index ) {
case 1 : if ( global_capture_opts . autostop_filesize > 2000 ) {
QMessageBox : : warning ( this , tr ( " Error " ) ,
2017-02-19 18:58:47 +00:00
tr ( " Multiple files: Requested filesize too large. The filesize cannot be greater than 2 GiB. " ) ) ;
2014-08-18 08:04:16 +00:00
return false ;
} else {
global_capture_opts . autostop_filesize * = 1000 ;
}
break ;
case 2 : if ( global_capture_opts . autostop_filesize > 2 ) {
QMessageBox : : warning ( this , tr ( " Error " ) ,
2017-02-19 18:58:47 +00:00
tr ( " Multiple files: Requested filesize too large. The filesize cannot be greater than 2 GiB. " ) ) ;
2014-08-18 08:04:16 +00:00
return false ;
} else {
global_capture_opts . autostop_filesize * = 1000000 ;
}
break ;
}
}
}
global_capture_opts . has_autostop_duration = ui - > stopSecsCheckBox - > isChecked ( ) ;
if ( global_capture_opts . has_autostop_duration ) {
global_capture_opts . autostop_duration = ui - > stopSecsSpinBox - > value ( ) ;
int index = ui - > stopSecsComboBox - > currentIndex ( ) ;
switch ( index ) {
case 1 : global_capture_opts . autostop_duration * = 60 ;
break ;
case 2 : global_capture_opts . autostop_duration * = 3600 ;
break ;
}
}
global_capture_opts . has_autostop_packets = ui - > stopPktCheckBox - > isChecked ( ) ;
if ( global_capture_opts . has_autostop_packets ) {
global_capture_opts . autostop_packets = ui - > stopPktSpinBox - > value ( ) ;
}
2015-06-25 21:39:43 +00:00
global_capture_opts . has_autostop_files = ui - > stopFilesCheckBox - > isChecked ( ) ;
if ( global_capture_opts . has_autostop_files ) {
global_capture_opts . autostop_files = ui - > stopFilesSpinBox - > value ( ) ;
}
2016-01-19 00:02:48 +00:00
interface_t * device ;
for ( int col = col_link_ ; col < = col_filter_ ; col + + ) {
2014-08-06 21:50:48 +00:00
if ( ui - > interfaceTree - > isColumnHidden ( col ) ) {
2014-06-04 09:03:59 +00:00
continue ;
}
/* All entries are separated by comma. There is also one before the first interface to be able to identify
word boundaries . As ' lo ' is part of ' nflog ' an exact match is necessary . */
switch ( col ) {
2014-08-06 21:50:48 +00:00
case col_link_ :
2014-08-14 20:20:09 +00:00
{
QStringList link_list ;
2014-06-04 09:03:59 +00:00
2014-08-06 21:50:48 +00:00
for ( int row = 0 ; row < ui - > interfaceTree - > topLevelItemCount ( ) ; row + + ) {
2016-01-19 00:02:48 +00:00
QTreeWidgetItem * ti = ui - > interfaceTree - > topLevelItem ( row ) ;
2016-02-23 18:04:16 +00:00
QString device_name = ti - > data ( col_interface_ , Qt : : UserRole ) . toString ( ) ;
device = getDeviceByName ( device_name ) ;
if ( ! device | | device - > active_dlt = = - 1 ) {
2014-06-04 09:03:59 +00:00
continue ;
}
2015-02-15 23:37:03 +00:00
link_list < < QString ( " %1(%2) " ) . arg ( device - > name ) . arg ( device - > active_dlt ) ;
2014-06-04 09:03:59 +00:00
}
g_free ( prefs . capture_devices_linktypes ) ;
2014-08-14 20:20:09 +00:00
prefs . capture_devices_linktypes = qstring_strdup ( link_list . join ( " , " ) ) ;
2014-06-04 09:03:59 +00:00
break ;
2014-08-14 20:20:09 +00:00
}
2014-08-06 21:50:48 +00:00
# ifdef SHOW_BUFFER_COLUMN
case col_buffer_ :
2014-08-14 20:20:09 +00:00
{
QStringList buffer_size_list ;
2014-06-04 09:03:59 +00:00
2014-08-06 21:50:48 +00:00
for ( int row = 0 ; row < ui - > interfaceTree - > topLevelItemCount ( ) ; row + + ) {
2016-01-19 00:02:48 +00:00
QTreeWidgetItem * ti = ui - > interfaceTree - > topLevelItem ( row ) ;
2016-02-23 18:04:16 +00:00
QString device_name = ti - > data ( col_interface_ , Qt : : UserRole ) . toString ( ) ;
device = getDeviceByName ( device_name ) ;
if ( ! device | | device - > buffer = = - 1 ) {
2014-06-04 09:03:59 +00:00
continue ;
}
2015-02-15 23:37:03 +00:00
buffer_size_list < < QString ( " %1(%2) " ) . arg ( device - > name ) . arg ( device - > buffer ) ;
2014-06-04 09:03:59 +00:00
}
g_free ( prefs . capture_devices_buffersize ) ;
2014-08-14 20:20:09 +00:00
prefs . capture_devices_buffersize = qstring_strdup ( buffer_size_list . join ( " , " ) ) ;
2014-06-04 09:03:59 +00:00
break ;
2014-08-14 20:20:09 +00:00
}
2014-08-06 21:50:48 +00:00
# endif // HAVE_BUFFER_SETTING
case col_snaplen_ :
2014-08-14 20:20:09 +00:00
{
QStringList snaplen_list ;
2014-06-04 09:03:59 +00:00
2014-08-06 21:50:48 +00:00
for ( int row = 0 ; row < ui - > interfaceTree - > topLevelItemCount ( ) ; row + + ) {
2016-01-19 00:02:48 +00:00
QTreeWidgetItem * ti = ui - > interfaceTree - > topLevelItem ( row ) ;
2016-02-23 18:04:16 +00:00
QString device_name = ti - > data ( col_interface_ , Qt : : UserRole ) . toString ( ) ;
device = getDeviceByName ( device_name ) ;
if ( ! device ) continue ;
2014-08-14 20:20:09 +00:00
snaplen_list < < QString ( " %1:%2(%3) " )
2015-02-15 23:37:03 +00:00
. arg ( device - > name )
. arg ( device - > has_snaplen )
Allow bigger snapshot lengths for D-Bus captures.
Use WTAP_MAX_PACKET_SIZE_STANDARD, set to 256KB, for everything except
for D-Bus captures. Use WTAP_MAX_PACKET_SIZE_DBUS, set to 128MB, for
them, because that's the largest possible D-Bus message size. See
https://bugs.freedesktop.org/show_bug.cgi?id=100220
for an example of the problems caused by limiting the snapshot length to
256KB for D-Bus.
Have a snapshot length of 0 in a capture_file structure mean "there is
no snapshot length for the file"; we don't need the has_snap field in
that case, a value of 0 mean "no, we don't have a snapshot length".
In dumpcap, start out with a pipe buffer size of 2KB, and grow it as
necessary. When checking for a too-big packet from a pipe, check
against the appropriate maximum - 128MB for DLT_DBUS, 256KB for
everything else.
Change-Id: Ib2ce7a0cf37b971fbc0318024fd011e18add8b20
Reviewed-on: https://code.wireshark.org/review/21952
Petri-Dish: Guy Harris <guy@alum.mit.edu>
Tested-by: Petri Dish Buildbot <buildbot-no-reply@wireshark.org>
Reviewed-by: Guy Harris <guy@alum.mit.edu>
2017-06-05 01:58:40 +00:00
. arg ( device - > has_snaplen ? device - > snaplen : WTAP_MAX_PACKET_SIZE_STANDARD ) ;
2014-06-04 09:03:59 +00:00
}
g_free ( prefs . capture_devices_snaplen ) ;
2014-08-14 20:20:09 +00:00
prefs . capture_devices_snaplen = qstring_strdup ( snaplen_list . join ( " , " ) ) ;
2014-06-04 09:03:59 +00:00
break ;
2014-08-14 20:20:09 +00:00
}
2014-08-06 21:50:48 +00:00
case col_pmode_ :
2014-08-14 20:20:09 +00:00
{
QStringList pmode_list ;
2014-06-04 09:03:59 +00:00
2014-08-06 21:50:48 +00:00
for ( int row = 0 ; row < ui - > interfaceTree - > topLevelItemCount ( ) ; row + + ) {
2016-01-19 00:02:48 +00:00
QTreeWidgetItem * ti = ui - > interfaceTree - > topLevelItem ( row ) ;
2016-02-23 18:04:16 +00:00
QString device_name = ti - > data ( col_interface_ , Qt : : UserRole ) . toString ( ) ;
device = getDeviceByName ( device_name ) ;
if ( ! device | | device - > pmode = = - 1 ) {
2014-06-04 09:03:59 +00:00
continue ;
}
2015-02-15 23:37:03 +00:00
pmode_list < < QString ( " %1(%2) " ) . arg ( device - > name ) . arg ( device - > pmode ) ;
2014-06-04 09:03:59 +00:00
}
g_free ( prefs . capture_devices_pmode ) ;
2014-08-14 20:20:09 +00:00
prefs . capture_devices_pmode = qstring_strdup ( pmode_list . join ( " , " ) ) ;
2014-06-04 09:03:59 +00:00
break ;
2014-08-14 20:20:09 +00:00
}
2016-05-27 17:31:45 +00:00
2014-08-06 21:50:48 +00:00
# ifdef SHOW_MONITOR_COLUMN
case col_monitor_ :
2014-08-14 20:20:09 +00:00
{
QStringList monitor_list ;
2014-06-04 09:03:59 +00:00
2014-08-06 21:50:48 +00:00
for ( int row = 0 ; row < ui - > interfaceTree - > topLevelItemCount ( ) ; row + + ) {
2016-01-19 00:02:48 +00:00
QTreeWidgetItem * ti = ui - > interfaceTree - > topLevelItem ( row ) ;
2016-02-23 18:04:16 +00:00
QString device_name = ti - > data ( col_interface_ , Qt : : UserRole ) . toString ( ) ;
device = getDeviceByName ( device_name ) ;
if ( ! device | | ! device - > monitor_mode_supported | | ( device - > monitor_mode_supported & & ! device - > monitor_mode_enabled ) ) {
2014-06-04 09:03:59 +00:00
continue ;
}
2015-02-15 23:37:03 +00:00
monitor_list < < device - > name ;
2014-06-04 09:03:59 +00:00
}
g_free ( prefs . capture_devices_monitor_mode ) ;
2014-08-14 20:20:09 +00:00
prefs . capture_devices_monitor_mode = qstring_strdup ( monitor_list . join ( " , " ) ) ;
2014-06-04 09:03:59 +00:00
break ;
2014-08-14 20:20:09 +00:00
}
2014-08-06 21:50:48 +00:00
# endif // HAVE_MONITOR_SETTING
2016-02-23 18:04:16 +00:00
#if 0
// The device cfilter should have been applied at this point.
// We shouldn't change it here.
2014-08-06 21:50:48 +00:00
case col_filter_ :
2014-08-14 20:20:09 +00:00
{
2016-01-19 00:02:48 +00:00
// XXX Update selected interfaces only?
2014-08-06 21:50:48 +00:00
for ( int row = 0 ; row < ui - > interfaceTree - > topLevelItemCount ( ) ; row + + ) {
2016-01-19 00:02:48 +00:00
QTreeWidgetItem * ti = ui - > interfaceTree - > topLevelItem ( row ) ;
2016-02-23 18:04:16 +00:00
QString device_name = ti - > data ( col_interface_ , Qt : : UserRole ) . toString ( ) ;
device = getDeviceByName ( device_name ) ;
if ( ! device ) continue ;
2016-01-19 00:02:48 +00:00
g_free ( device - > cfilter ) ;
if ( ti - > text ( col_filter_ ) . isEmpty ( ) ) {
device - > cfilter = NULL ;
} else {
device - > cfilter = qstring_strdup ( ti - > text ( col_filter_ ) ) ;
2014-06-04 09:03:59 +00:00
}
}
}
2016-02-23 18:04:16 +00:00
# endif
2014-08-14 20:20:09 +00:00
}
2014-06-04 09:03:59 +00:00
}
if ( ! prefs . gui_use_pref_save ) {
prefs_main_write ( ) ;
}
2014-08-18 08:04:16 +00:00
return true ;
2014-06-04 09:03:59 +00:00
}
2013-11-25 14:15:49 +00:00
2016-02-23 18:04:16 +00:00
void CaptureInterfacesDialog : : updateSelectedFilter ( )
{
// Should match MainWelcome::interfaceSelected.
QPair < const QString , bool > sf_pair = CaptureFilterEdit : : getSelectedFilter ( ) ;
const QString user_filter = sf_pair . first ;
bool conflict = sf_pair . second ;
if ( conflict ) {
ui - > captureFilterComboBox - > lineEdit ( ) - > clear ( ) ;
ui - > captureFilterComboBox - > setConflict ( true ) ;
} else {
ui - > captureFilterComboBox - > lineEdit ( ) - > setText ( user_filter ) ;
}
}
2016-05-24 23:49:54 +00:00
void CaptureInterfacesDialog : : on_manageButton_clicked ( )
2014-06-24 09:36:51 +00:00
{
2014-08-18 08:04:16 +00:00
if ( saveOptionsToPreferences ( ) ) {
ManageInterfacesDialog * dlg = new ManageInterfacesDialog ( this ) ;
dlg - > show ( ) ;
}
2014-06-24 09:36:51 +00:00
}
2013-12-21 16:55:43 +00:00
void CaptureInterfacesDialog : : changeEvent ( QEvent * event )
{
if ( 0 ! = event )
{
switch ( event - > type ( ) )
{
case QEvent : : LanguageChange :
ui - > retranslateUi ( this ) ;
break ;
default :
break ;
}
}
QDialog : : changeEvent ( event ) ;
}
2016-02-23 18:04:16 +00:00
interface_t * CaptureInterfacesDialog : : getDeviceByName ( const QString device_name )
{
for ( guint i = 0 ; i < global_capture_opts . all_ifaces - > len ; i + + ) {
interface_t * device = & g_array_index ( global_capture_opts . all_ifaces , interface_t , i ) ;
if ( device_name . compare ( QString ( ) . fromUtf8 ( device - > name ) ) = = 0 ) {
return device ;
}
}
return NULL ;
}
2014-08-06 21:50:48 +00:00
//
// InterfaceTreeItem
//
bool InterfaceTreeWidgetItem : : operator < ( const QTreeWidgetItem & other ) const {
if ( treeWidget ( ) - > sortColumn ( ) = = col_traffic_ ) {
2017-01-10 23:33:46 +00:00
QList < int > points = data ( col_traffic_ , Qt : : UserRole ) . value < QList < int > > ( ) ;
QList < int > other_points = other . data ( col_traffic_ , Qt : : UserRole ) . value < QList < int > > ( ) ;
2014-08-06 21:50:48 +00:00
double avg = 0 , other_avg = 0 ;
2017-01-10 23:33:46 +00:00
foreach ( int point , points ) {
avg + = ( double ) point / points . length ( ) ;
2014-08-06 21:50:48 +00:00
}
2017-01-10 23:33:46 +00:00
foreach ( int point , other_points ) {
other_avg + = ( double ) point / other_points . length ( ) ;
2014-08-06 21:50:48 +00:00
}
return avg < other_avg ;
}
return QTreeWidgetItem : : operator < ( other ) ;
}
2017-03-13 12:47:34 +00:00
QVariant InterfaceTreeWidgetItem : : data ( int column , int role ) const
{
// See setData for the special col_traffic_ treatment.
if ( column = = col_traffic_ & & role = = Qt : : UserRole ) {
return qVariantFromValue ( points ) ;
}
return QTreeWidgetItem : : data ( column , role ) ;
}
void InterfaceTreeWidgetItem : : setData ( int column , int role , const QVariant & value )
{
// Workaround for closing editors on updates to the points list: normally
// QTreeWidgetItem::setData emits dataChanged when the value (list) changes.
// We could store a pointer to the list, or just have this hack that does
// not emit dataChanged.
if ( column = = col_traffic_ & & role = = Qt : : UserRole ) {
points = value . value < QList < int > > ( ) ;
return ;
}
QTreeWidgetItem : : setData ( column , role , value ) ;
}
2014-08-06 21:50:48 +00:00
//
// InterfaceTreeDelegate
//
2014-06-04 09:03:59 +00:00
# include <QComboBox>
2013-11-25 14:15:49 +00:00
2014-08-06 21:50:48 +00:00
InterfaceTreeDelegate : : InterfaceTreeDelegate ( QObject * parent )
2016-07-04 20:47:27 +00:00
: QStyledItemDelegate ( parent ) , tree_ ( NULL )
2014-06-04 09:03:59 +00:00
{
}
2014-08-06 21:50:48 +00:00
InterfaceTreeDelegate : : ~ InterfaceTreeDelegate ( )
2014-06-04 09:03:59 +00:00
{
}
2016-09-27 16:55:08 +00:00
QWidget * InterfaceTreeDelegate : : createEditor ( QWidget * parent , const QStyleOptionViewItem & , const QModelIndex & idx ) const
2014-06-04 09:03:59 +00:00
{
QWidget * w = NULL ;
2014-08-06 21:50:48 +00:00
# ifdef SHOW_BUFFER_COLUMN
2014-06-04 09:03:59 +00:00
gint buffer = DEFAULT_CAPTURE_BUFFER_SIZE ;
# endif
Allow bigger snapshot lengths for D-Bus captures.
Use WTAP_MAX_PACKET_SIZE_STANDARD, set to 256KB, for everything except
for D-Bus captures. Use WTAP_MAX_PACKET_SIZE_DBUS, set to 128MB, for
them, because that's the largest possible D-Bus message size. See
https://bugs.freedesktop.org/show_bug.cgi?id=100220
for an example of the problems caused by limiting the snapshot length to
256KB for D-Bus.
Have a snapshot length of 0 in a capture_file structure mean "there is
no snapshot length for the file"; we don't need the has_snap field in
that case, a value of 0 mean "no, we don't have a snapshot length".
In dumpcap, start out with a pipe buffer size of 2KB, and grow it as
necessary. When checking for a too-big packet from a pipe, check
against the appropriate maximum - 128MB for DLT_DBUS, 256KB for
everything else.
Change-Id: Ib2ce7a0cf37b971fbc0318024fd011e18add8b20
Reviewed-on: https://code.wireshark.org/review/21952
Petri-Dish: Guy Harris <guy@alum.mit.edu>
Tested-by: Petri Dish Buildbot <buildbot-no-reply@wireshark.org>
Reviewed-by: Guy Harris <guy@alum.mit.edu>
2017-06-05 01:58:40 +00:00
guint snap = WTAP_MAX_PACKET_SIZE_STANDARD ;
2014-06-12 18:54:21 +00:00
GList * links = NULL ;
2013-11-25 14:15:49 +00:00
2016-09-27 16:55:08 +00:00
if ( idx . column ( ) > 1 & & idx . data ( ) . toString ( ) . compare ( UTF8_EM_DASH ) ) {
QTreeWidgetItem * ti = tree_ - > topLevelItem ( idx . row ( ) ) ;
2014-08-06 21:50:48 +00:00
QString interface_name = ti - > text ( col_interface_ ) ;
2016-01-03 12:37:16 +00:00
interface_t * device = find_device_by_if_name ( interface_name ) ;
2015-02-15 23:37:03 +00:00
if ( device ) {
2014-08-06 21:50:48 +00:00
# ifdef SHOW_BUFFER_COLUMN
2015-02-15 23:37:03 +00:00
buffer = device - > buffer ;
2014-06-04 09:03:59 +00:00
# endif
2015-02-15 23:37:03 +00:00
snap = device - > snaplen ;
links = device - > links ;
2014-06-04 09:03:59 +00:00
}
2016-09-27 16:55:08 +00:00
switch ( idx . column ( ) ) {
2014-08-06 21:50:48 +00:00
case col_interface_ :
case col_traffic_ :
2014-06-04 09:03:59 +00:00
break ;
2014-08-06 21:50:48 +00:00
case col_link_ :
2014-06-04 09:03:59 +00:00
{
GList * list ;
2016-05-24 23:49:54 +00:00
link_row * linkr ;
QStringList valid_link_types ;
// XXX The GTK+ UI fills in all link types, valid or not. We add
// only the valid ones. If we *do* wish to include invalid link
// types we'll have to jump through the hoops necessary to disable
// QComboBox items.
2014-08-06 21:50:48 +00:00
2016-05-24 23:49:54 +00:00
for ( list = links ; list ! = NULL ; list = g_list_next ( list ) ) {
linkr = ( link_row * ) ( list - > data ) ;
if ( linkr - > dlt > = 0 ) {
valid_link_types < < linkr - > name ;
}
}
if ( valid_link_types . size ( ) < 2 ) {
2014-08-06 21:50:48 +00:00
break ;
}
2014-06-04 09:03:59 +00:00
QComboBox * cb = new QComboBox ( parent ) ;
2016-05-24 23:49:54 +00:00
cb - > addItems ( valid_link_types ) ;
connect ( cb , SIGNAL ( currentIndexChanged ( QString ) ) , this , SLOT ( linkTypeChanged ( QString ) ) ) ;
2014-06-04 09:03:59 +00:00
w = ( QWidget * ) cb ;
break ;
}
2014-08-06 21:50:48 +00:00
case col_snaplen_ :
2014-06-04 09:03:59 +00:00
{
QSpinBox * sb = new QSpinBox ( parent ) ;
Allow bigger snapshot lengths for D-Bus captures.
Use WTAP_MAX_PACKET_SIZE_STANDARD, set to 256KB, for everything except
for D-Bus captures. Use WTAP_MAX_PACKET_SIZE_DBUS, set to 128MB, for
them, because that's the largest possible D-Bus message size. See
https://bugs.freedesktop.org/show_bug.cgi?id=100220
for an example of the problems caused by limiting the snapshot length to
256KB for D-Bus.
Have a snapshot length of 0 in a capture_file structure mean "there is
no snapshot length for the file"; we don't need the has_snap field in
that case, a value of 0 mean "no, we don't have a snapshot length".
In dumpcap, start out with a pipe buffer size of 2KB, and grow it as
necessary. When checking for a too-big packet from a pipe, check
against the appropriate maximum - 128MB for DLT_DBUS, 256KB for
everything else.
Change-Id: Ib2ce7a0cf37b971fbc0318024fd011e18add8b20
Reviewed-on: https://code.wireshark.org/review/21952
Petri-Dish: Guy Harris <guy@alum.mit.edu>
Tested-by: Petri Dish Buildbot <buildbot-no-reply@wireshark.org>
Reviewed-by: Guy Harris <guy@alum.mit.edu>
2017-06-05 01:58:40 +00:00
sb - > setRange ( 1 , WTAP_MAX_PACKET_SIZE_STANDARD ) ;
2014-06-04 09:03:59 +00:00
sb - > setValue ( snap ) ;
sb - > setWrapping ( true ) ;
2016-05-24 23:49:54 +00:00
connect ( sb , SIGNAL ( valueChanged ( int ) ) , this , SLOT ( snapshotLengthChanged ( int ) ) ) ;
2014-06-04 09:03:59 +00:00
w = ( QWidget * ) sb ;
break ;
}
2014-08-06 21:50:48 +00:00
# ifdef SHOW_BUFFER_COLUMN
case col_buffer_ :
2014-06-04 09:03:59 +00:00
{
QSpinBox * sb = new QSpinBox ( parent ) ;
Allow bigger snapshot lengths for D-Bus captures.
Use WTAP_MAX_PACKET_SIZE_STANDARD, set to 256KB, for everything except
for D-Bus captures. Use WTAP_MAX_PACKET_SIZE_DBUS, set to 128MB, for
them, because that's the largest possible D-Bus message size. See
https://bugs.freedesktop.org/show_bug.cgi?id=100220
for an example of the problems caused by limiting the snapshot length to
256KB for D-Bus.
Have a snapshot length of 0 in a capture_file structure mean "there is
no snapshot length for the file"; we don't need the has_snap field in
that case, a value of 0 mean "no, we don't have a snapshot length".
In dumpcap, start out with a pipe buffer size of 2KB, and grow it as
necessary. When checking for a too-big packet from a pipe, check
against the appropriate maximum - 128MB for DLT_DBUS, 256KB for
everything else.
Change-Id: Ib2ce7a0cf37b971fbc0318024fd011e18add8b20
Reviewed-on: https://code.wireshark.org/review/21952
Petri-Dish: Guy Harris <guy@alum.mit.edu>
Tested-by: Petri Dish Buildbot <buildbot-no-reply@wireshark.org>
Reviewed-by: Guy Harris <guy@alum.mit.edu>
2017-06-05 01:58:40 +00:00
sb - > setRange ( 1 , WTAP_MAX_PACKET_SIZE_STANDARD ) ;
2014-06-04 09:03:59 +00:00
sb - > setValue ( buffer ) ;
sb - > setWrapping ( true ) ;
2016-05-24 23:49:54 +00:00
connect ( sb , SIGNAL ( valueChanged ( int ) ) , this , SLOT ( bufferSizeChanged ( int ) ) ) ;
2014-06-04 09:03:59 +00:00
w = ( QWidget * ) sb ;
break ;
}
2014-08-06 21:50:48 +00:00
# endif
case col_filter_ :
2014-06-04 09:03:59 +00:00
{
2016-01-29 06:55:03 +00:00
CaptureFilterCombo * cf = new CaptureFilterCombo ( parent , true ) ;
2016-01-19 00:02:48 +00:00
connect ( cf - > lineEdit ( ) , SIGNAL ( textEdited ( QString ) ) , this , SIGNAL ( filterChanged ( QString ) ) ) ;
2014-06-04 09:03:59 +00:00
w = ( QWidget * ) cf ;
}
2014-08-06 21:50:48 +00:00
default :
break ;
2014-06-04 09:03:59 +00:00
}
2014-08-06 21:50:48 +00:00
// if (w) {
// ti->setSizeHint(index.column(), w->sizeHint());
// }
2013-11-25 14:15:49 +00:00
}
2014-06-04 09:03:59 +00:00
return w ;
2013-11-25 14:15:49 +00:00
}
2014-08-06 21:50:48 +00:00
bool InterfaceTreeDelegate : : eventFilter ( QObject * object , QEvent * event )
2013-11-25 17:01:10 +00:00
{
2014-06-04 09:03:59 +00:00
QComboBox * comboBox = dynamic_cast < QComboBox * > ( object ) ;
if ( comboBox ) {
if ( event - > type ( ) = = QEvent : : MouseButtonRelease ) {
comboBox - > showPopup ( ) ;
return true ;
}
} else {
2016-01-23 12:18:30 +00:00
return QStyledItemDelegate : : eventFilter ( object , event ) ;
2013-11-25 14:15:49 +00:00
}
2014-06-04 09:03:59 +00:00
return false ;
2013-11-25 14:15:49 +00:00
}
2016-05-24 23:49:54 +00:00
void InterfaceTreeDelegate : : linkTypeChanged ( QString selected_link_type )
2014-06-04 09:03:59 +00:00
{
GList * list ;
link_row * temp ;
2015-02-15 23:37:03 +00:00
interface_t * device ;
2014-06-04 09:03:59 +00:00
2014-08-06 21:50:48 +00:00
QTreeWidgetItem * ti = tree_ - > currentItem ( ) ;
if ( ! ti ) {
return ;
}
QString interface_name = ti - > text ( col_interface_ ) ;
2015-02-15 23:37:03 +00:00
device = find_device_by_if_name ( interface_name ) ;
if ( ! device ) {
return ;
2014-06-04 09:03:59 +00:00
}
2015-02-15 23:37:03 +00:00
for ( list = device - > links ; list ! = NULL ; list = g_list_next ( list ) ) {
2014-06-04 09:03:59 +00:00
temp = ( link_row * ) ( list - > data ) ;
2016-05-24 23:49:54 +00:00
if ( ! selected_link_type . compare ( temp - > name ) ) {
2015-02-15 23:37:03 +00:00
device - > active_dlt = temp - > dlt ;
2014-06-04 09:03:59 +00:00
}
}
2016-05-24 23:49:54 +00:00
// XXX We might want to verify that active_dlt is valid at this point.
2014-06-04 09:03:59 +00:00
}
2016-05-24 23:49:54 +00:00
void InterfaceTreeDelegate : : snapshotLengthChanged ( int value )
2014-06-04 09:03:59 +00:00
{
2015-02-15 23:37:03 +00:00
interface_t * device ;
2014-08-06 21:50:48 +00:00
QTreeWidgetItem * ti = tree_ - > currentItem ( ) ;
if ( ! ti ) {
return ;
}
QString interface_name = ti - > text ( col_interface_ ) ;
2015-02-15 23:37:03 +00:00
device = find_device_by_if_name ( interface_name ) ;
if ( ! device ) {
return ;
2014-06-04 09:03:59 +00:00
}
Allow bigger snapshot lengths for D-Bus captures.
Use WTAP_MAX_PACKET_SIZE_STANDARD, set to 256KB, for everything except
for D-Bus captures. Use WTAP_MAX_PACKET_SIZE_DBUS, set to 128MB, for
them, because that's the largest possible D-Bus message size. See
https://bugs.freedesktop.org/show_bug.cgi?id=100220
for an example of the problems caused by limiting the snapshot length to
256KB for D-Bus.
Have a snapshot length of 0 in a capture_file structure mean "there is
no snapshot length for the file"; we don't need the has_snap field in
that case, a value of 0 mean "no, we don't have a snapshot length".
In dumpcap, start out with a pipe buffer size of 2KB, and grow it as
necessary. When checking for a too-big packet from a pipe, check
against the appropriate maximum - 128MB for DLT_DBUS, 256KB for
everything else.
Change-Id: Ib2ce7a0cf37b971fbc0318024fd011e18add8b20
Reviewed-on: https://code.wireshark.org/review/21952
Petri-Dish: Guy Harris <guy@alum.mit.edu>
Tested-by: Petri Dish Buildbot <buildbot-no-reply@wireshark.org>
Reviewed-by: Guy Harris <guy@alum.mit.edu>
2017-06-05 01:58:40 +00:00
if ( value ! = WTAP_MAX_PACKET_SIZE_STANDARD ) {
2015-02-15 23:37:03 +00:00
device - > has_snaplen = true ;
device - > snaplen = value ;
2014-06-04 09:03:59 +00:00
} else {
2015-02-15 23:37:03 +00:00
device - > has_snaplen = false ;
Allow bigger snapshot lengths for D-Bus captures.
Use WTAP_MAX_PACKET_SIZE_STANDARD, set to 256KB, for everything except
for D-Bus captures. Use WTAP_MAX_PACKET_SIZE_DBUS, set to 128MB, for
them, because that's the largest possible D-Bus message size. See
https://bugs.freedesktop.org/show_bug.cgi?id=100220
for an example of the problems caused by limiting the snapshot length to
256KB for D-Bus.
Have a snapshot length of 0 in a capture_file structure mean "there is
no snapshot length for the file"; we don't need the has_snap field in
that case, a value of 0 mean "no, we don't have a snapshot length".
In dumpcap, start out with a pipe buffer size of 2KB, and grow it as
necessary. When checking for a too-big packet from a pipe, check
against the appropriate maximum - 128MB for DLT_DBUS, 256KB for
everything else.
Change-Id: Ib2ce7a0cf37b971fbc0318024fd011e18add8b20
Reviewed-on: https://code.wireshark.org/review/21952
Petri-Dish: Guy Harris <guy@alum.mit.edu>
Tested-by: Petri Dish Buildbot <buildbot-no-reply@wireshark.org>
Reviewed-by: Guy Harris <guy@alum.mit.edu>
2017-06-05 01:58:40 +00:00
device - > snaplen = WTAP_MAX_PACKET_SIZE_STANDARD ;
2014-06-04 09:03:59 +00:00
}
}
2016-05-24 23:49:54 +00:00
void InterfaceTreeDelegate : : bufferSizeChanged ( int value )
2014-06-04 09:03:59 +00:00
{
2014-08-06 21:50:48 +00:00
# ifdef SHOW_BUFFER_COLUMN
2015-02-15 23:37:03 +00:00
interface_t * device ;
2014-08-06 21:50:48 +00:00
QTreeWidgetItem * ti = tree_ - > currentItem ( ) ;
if ( ! ti ) {
return ;
}
QString interface_name = ti - > text ( col_interface_ ) ;
2015-02-15 23:37:03 +00:00
device = find_device_by_if_name ( interface_name ) ;
if ( ! device ) {
return ;
2014-06-04 09:03:59 +00:00
}
2015-02-15 23:37:03 +00:00
device - > buffer = value ;
2016-09-27 07:39:07 +00:00
# else
2017-04-25 20:51:53 +00:00
Q_UNUSED ( value )
2014-06-04 09:03:59 +00:00
# endif
}
2013-11-25 21:50:58 +00:00
# endif /* HAVE_LIBPCAP */
2013-11-25 14:15:49 +00:00
/*
* Editor modelines
*
* Local Variables :
* c - basic - offset : 4
* tab - width : 8
* indent - tabs - mode : nil
* End :
*
* ex : set shiftwidth = 4 tabstop = 8 expandtab :
* : indentSize = 4 : tabSize = 8 : noTabs = true :
*/