forked from wireshark/wireshark
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcapture_dlg.c
2431 lines (2098 loc) · 99.3 KB
/
capture_dlg.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/* capture_dlg.c
* Routines for packet capture windows
*
* $Id$
*
* 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
#ifdef HAVE_CONFIG_H
# include "config.h"
#endif
#ifdef HAVE_LIBPCAP
#ifdef HAVE_SYS_TYPES_H
#include <sys/types.h>
#endif
#include <string.h>
//#include <stdio.h> /* main_menu.h needs FILE XXX - true?*/
#include <gtk/gtk.h>
#include <epan/packet.h>
#include <epan/addr_resolv.h>
#include <epan/prefs.h>
#include <epan/filesystem.h>
#include "../capture.h"
#include "../globals.h"
#include "../capture_errs.h"
#include "../simple_dialog.h"
#include "../capture-pcap-util.h"
#include "../capture_ui_utils.h"
#include "../ringbuffer.h"
#include "gtk/main.h"
#include "gtk/main_menu.h"
#include "gtk/gui_utils.h"
#include "gtk/capture_dlg.h"
#include "gtk/filter_dlg.h"
#include "gtk/dlg_utils.h"
#include "gtk/file_dlg.h"
#include "gtk/stock_icons.h"
#include "gtk/capture_file_dlg.h"
#include "gtk/help_dlg.h"
#include "gtk/gtkglobals.h"
#include "gtk/cfilter_combo_utils.h"
#ifdef _WIN32
#include "../capture-wpcap.h"
#endif
#include "gtk/keys.h"
#ifdef HAVE_AIRPCAP
#include <airpcap.h>
#include "airpcap_loader.h"
#include "airpcap_gui_utils.h"
#include "airpcap_dlg.h"
#endif
/* Capture callback data keys */
#define E_CAP_IFACE_KEY "cap_iface"
#define E_CAP_IFACE_IP_KEY "cap_iface_ip"
#define E_CAP_SNAP_CB_KEY "cap_snap_cb"
#define E_CAP_LT_OM_KEY "cap_lt_om"
#define E_CAP_LT_OM_LABEL_KEY "cap_lt_om_label"
#ifdef _WIN32
#define E_CAP_BUFFER_SIZE_SB_KEY "cap_buffer_size_sb"
#endif
#define E_CAP_SNAP_SB_KEY "cap_snap_sb"
#define E_CAP_PROMISC_KEY "cap_promisc"
#define E_CAP_FILT_KEY "cap_filter_te"
#define E_CAP_FILE_TE_KEY "cap_file_te"
#define E_CAP_MULTI_FILES_ON_CB_KEY "cap_multi_files_on_cb"
#define E_CAP_RING_FILESIZE_CB_KEY "cap_ring_filesize_cb"
#define E_CAP_RING_FILESIZE_SB_KEY "cap_ring_filesize_sb"
#define E_CAP_RING_FILESIZE_OM_KEY "cap_ring_filesize_om"
#define E_CAP_FILE_DURATION_CB_KEY "cap_file_duration_cb"
#define E_CAP_FILE_DURATION_SB_KEY "cap_file_duration_sb"
#define E_CAP_FILE_DURATION_OM_KEY "cap_file_duration_om"
#define E_CAP_RING_NBF_CB_KEY "cap_ring_nbf_cb"
#define E_CAP_RING_NBF_SB_KEY "cap_ring_nbf_sb"
#define E_CAP_RING_NBF_LB_KEY "cap_ring_nbf_lb"
#define E_CAP_STOP_FILES_CB_KEY "cap_stop_files_cb"
#define E_CAP_STOP_FILES_SB_KEY "cap_stop_files_sb"
#define E_CAP_STOP_FILES_LB_KEY "cap_stop_files_lb"
#define E_CAP_SYNC_KEY "cap_sync"
#define E_CAP_AUTO_SCROLL_KEY "cap_auto_scroll"
#define E_CAP_HIDE_INFO_KEY "cap_hide_info"
#define E_CAP_STOP_PACKETS_CB_KEY "cap_stop_packets_cb"
#define E_CAP_STOP_PACKETS_SB_KEY "cap_stop_packets_sb"
#define E_CAP_STOP_PACKETS_LB_KEY "cap_stop_packets_lb"
#define E_CAP_STOP_FILESIZE_CB_KEY "cap_stop_filesize_cb"
#define E_CAP_STOP_FILESIZE_SB_KEY "cap_stop_filesize_sb"
#define E_CAP_STOP_FILESIZE_OM_KEY "cap_stop_filesize_om"
#define E_CAP_STOP_DURATION_CB_KEY "cap_stop_duration_cb"
#define E_CAP_STOP_DURATION_SB_KEY "cap_stop_duration_sb"
#define E_CAP_STOP_DURATION_OM_KEY "cap_stop_duration_om"
#define E_CAP_M_RESOLVE_KEY "cap_m_resolve"
#define E_CAP_N_RESOLVE_KEY "cap_n_resolve"
#define E_CAP_T_RESOLVE_KEY "cap_t_resolve"
#ifdef HAVE_PCAP_REMOTE
#define E_CAP_IFTYPE_OM_KEY "cap_iftype_om"
#define E_CAP_DATATX_UDP_CB_KEY "cap_datatx_udp_cb"
#define E_CAP_NOCAP_RPCAP_CB_KEY "cap_nocap_rpcap_cb"
#define E_CAP_REMOTE_DIALOG_PTR_KEY "cap_remote_dialog"
#define E_CAP_REMOTE_CALLER_PTR_KEY "cap_remote_caller"
#define E_REMOTE_HOST_TE_KEY "cap_remote_host"
#define E_REMOTE_PORT_TE_KEY "cap_remote_port"
#define E_REMOTE_AUTH_NULL_KEY "cap_remote_auth_null"
#define E_REMOTE_AUTH_PASSWD_KEY "cap_remote_auth_passwd"
#define E_REMOTE_USERNAME_LB_KEY "cap_remote_username_lb"
#define E_REMOTE_USERNAME_TE_KEY "cap_remote_username_te"
#define E_REMOTE_PASSWD_LB_KEY "cap_remote_passwd_lb"
#define E_REMOTE_PASSWD_TE_KEY "cap_remote_passwd_te"
#define E_CAP_OM_IFTYPE_VALUE_KEY "cap_om_iftype_value"
#endif
#ifdef HAVE_PCAP_SETSAMPLING
#define E_CAP_SAMP_NONE_RB_KEY "cap_samp_none_rb"
#define E_CAP_SAMP_COUNT_RB_KEY "cap_samp_count_rb"
#define E_CAP_SAMP_COUNT_SB_KEY "cap_samp_count_sb"
#define E_CAP_SAMP_TIMER_RB_KEY "cap_samp_timer_rb"
#define E_CAP_SAMP_TIMER_SB_KEY "cap_samp_timer_sb"
#endif
#define E_CAP_OM_LT_VALUE_KEY "cap_om_lt_value"
/*
* Keep a static pointer to the current "Capture Options" window, if
* any, so that if somebody tries to do "Capture:Start" while there's
* already a "Capture Options" window up, we just pop up the existing
* one, rather than creating a new one.
*/
static GtkWidget *cap_open_w;
static GtkWidget * dl_hdr_menu=NULL;
static guint linktype_history=0;
static void
capture_prep_file_cb(GtkWidget *file_bt, GtkWidget *file_te);
static void
select_link_type_cb(GtkWidget *w, gpointer data);
#ifdef HAVE_PCAP_REMOTE
static void
select_if_type_cb(GtkWidget *w, gpointer data);
static void
capture_remote_cb(GtkWidget *w, gpointer data);
#endif
static void
capture_prep_adjust_sensitivity(GtkWidget *tb, gpointer parent_w);
static void
capture_prep_destroy_cb(GtkWidget *win, gpointer user_data);
static void
capture_prep_interface_changed_cb(GtkWidget *entry, gpointer parent_w);
static void
capture_dlg_prep(gpointer parent_w);
/* stop the currently running capture */
void
capture_stop_cb(GtkWidget *w _U_, gpointer d _U_)
{
#ifdef HAVE_AIRPCAP
airpcap_set_toolbar_stop_capture(airpcap_if_active);
#endif
capture_stop(capture_opts);
}
/* restart (stop - delete old file - start) running capture */
void
capture_restart_cb(GtkWidget *w _U_, gpointer d _U_)
{
#ifdef HAVE_AIRPCAP
airpcap_set_toolbar_start_capture(airpcap_if_active);
#endif
capture_restart(capture_opts);
}
/* init the link type list */
/* (often this list has only one entry and will therefore be disabled) */
static void
set_link_type_list(GtkWidget *linktype_om, GtkWidget *entry)
{
gchar *entry_text;
gchar *if_text;
gchar *if_name;
GList *if_list;
GList *if_entry;
if_info_t *if_info;
GList *lt_list;
int err;
GtkWidget *lt_menu, *lt_menu_item;
GList *lt_entry;
data_link_info_t *data_link_info;
gchar *linktype_menu_label;
guint num_supported_link_types;
GtkWidget *linktype_lb = g_object_get_data(G_OBJECT(linktype_om), E_CAP_LT_OM_LABEL_KEY);
GtkWidget *if_ip_lb;
GString *ip_str = g_string_new("IP address: ");
int ips = 0;
GSList *curr_ip;
if_addr_t *ip_addr;
#ifdef HAVE_AIRPCAP
GtkWidget *advanced_bt;
#endif
/* Deallocate the existing menu for Datalink header type */
if (dl_hdr_menu != NULL)
gtk_widget_destroy(dl_hdr_menu);
lt_menu = gtk_menu_new();
dl_hdr_menu= lt_menu;
entry_text = g_strdup(gtk_entry_get_text(GTK_ENTRY(entry)));
if_text = g_strstrip(entry_text);
if_name = g_strdup(get_if_name(if_text));
#ifdef HAVE_AIRPCAP
/* is it an airpcap interface??? */
/* retrieve the advanced button pointer */
advanced_bt = g_object_get_data(G_OBJECT(entry),AIRPCAP_OPTIONS_ADVANCED_KEY);
airpcap_if_selected = get_airpcap_if_from_name(airpcap_if_list,if_name);
airpcap_enable_toolbar_widgets(airpcap_tb,FALSE);
if( airpcap_if_selected != NULL)
{
gtk_widget_set_sensitive(advanced_bt,TRUE);
}
else
{
gtk_widget_set_sensitive(advanced_bt,FALSE);
}
#endif
/*
* If the interface name is in the list of known interfaces, get
* its list of link-layer types and set the option menu to display it.
*
* If it's not, don't bother - the user might be in the middle of
* editing the list, or it might be a remote device in which case
* getting the list could take an arbitrarily-long period of time.
* The list currently won't contain any remote devices (as
* "pcap_findalldevs()" doesn't know about remote devices, and neither
* does the code we use if "pcap_findalldevs()" isn't available), but
* should contain all the local devices on which you can capture.
*/
lt_list = NULL;
if (*if_name != '\0') {
/*
* Try to get the list of known interfaces.
*/
if_list = capture_interface_list(&err, NULL);
if (if_list != NULL) {
/*
* We have the list - check it.
*/
for (if_entry = if_list; if_entry != NULL;
if_entry = g_list_next(if_entry)) {
if_info = if_entry->data;
if (strcmp(if_info->name, if_name) == 0) {
/*
* It's in the list.
* Get the list of link-layer types for it.
*/
lt_list = capture_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++) {
if (ips != 0)
g_string_append(ip_str, ", ");
ip_addr = (if_addr_t *)curr_ip->data;
switch (ip_addr->type) {
case AT_IPv4:
g_string_append(ip_str,
ip_to_str((guint8 *)&ip_addr->ip_addr.ip4_addr));
break;
case AT_IPv6:
g_string_append(ip_str,
ip6_to_str((struct e_in6_addr *)&ip_addr->ip_addr.ip6_addr));
break;
default:
g_assert_not_reached();
}
}
if (if_info->loopback)
g_string_append(ip_str, " (loopback)");
}
}
free_interface_list(if_list);
}
}
g_free(entry_text);
g_free(if_name);
num_supported_link_types = 0;
for (lt_entry = lt_list; lt_entry != NULL; lt_entry = g_list_next(lt_entry)) {
data_link_info = lt_entry->data;
if (data_link_info->description != NULL) {
lt_menu_item = gtk_menu_item_new_with_label(data_link_info->description);
g_object_set_data(G_OBJECT(lt_menu_item), E_CAP_LT_OM_KEY, linktype_om);
g_signal_connect(lt_menu_item, "activate", G_CALLBACK(select_link_type_cb),
GINT_TO_POINTER(data_link_info->dlt));
num_supported_link_types++;
} else {
/* Not supported - tell them about it but don't let them select it. */
linktype_menu_label = g_strdup_printf("%s (not supported)",
data_link_info->name);
lt_menu_item = gtk_menu_item_new_with_label(linktype_menu_label);
g_free(linktype_menu_label);
gtk_widget_set_sensitive(lt_menu_item, FALSE);
}
gtk_menu_append(GTK_MENU(lt_menu), lt_menu_item);
gtk_widget_show(lt_menu_item);
}
if (lt_list != NULL)
free_pcap_linktype_list(lt_list);
gtk_option_menu_set_menu(GTK_OPTION_MENU(linktype_om), lt_menu);
gtk_widget_set_sensitive(linktype_lb, num_supported_link_types >= 2);
gtk_widget_set_sensitive(linktype_om, num_supported_link_types >= 2);
/* Restore the menu to the last index used */
gtk_option_menu_set_history(GTK_OPTION_MENU(linktype_om),linktype_history);
if_ip_lb = g_object_get_data(G_OBJECT(linktype_om), E_CAP_IFACE_KEY);
if(ips == 0) {
g_string_append(ip_str, "unknown");
}
gtk_label_set_text(GTK_LABEL(if_ip_lb), ip_str->str);
#if GTK_CHECK_VERSION(2,6,0)
gtk_label_set_ellipsize(GTK_LABEL(if_ip_lb), PANGO_ELLIPSIZE_MIDDLE);
#endif
g_string_free(ip_str, TRUE);
}
#define TIME_UNIT_SECOND 0
#define TIME_UNIT_MINUTE 1
#define TIME_UNIT_HOUR 2
#define TIME_UNIT_DAY 3
#define MAX_TIME_UNITS 4
static const char *time_unit_name[MAX_TIME_UNITS] = {
"second(s)",
"minute(s)",
"hour(s)",
"day(s)",
};
/* create one of the duration options */
/* (and select the matching unit depending on the given value) */
static GtkWidget *time_unit_option_menu_new(guint32 value) {
GtkWidget *unit_om, *menu, *menu_item;
int i;
unit_om=gtk_option_menu_new();
menu=gtk_menu_new();
for(i=0;i<MAX_TIME_UNITS;i++){
menu_item=gtk_menu_item_new_with_label(time_unit_name[i]);
g_object_set_data(G_OBJECT(menu_item), "time_unit", GINT_TO_POINTER(i));
gtk_menu_append(GTK_MENU(menu), menu_item);
}
/* the selected menu item can't be changed, once the option_menu
is created, so set the matching menu item now */
/* days */
if(value >= 60 * 60 * 24) {
gtk_menu_set_active(GTK_MENU(menu), TIME_UNIT_DAY);
} else {
/* hours */
if(value >= 60 * 60) {
gtk_menu_set_active(GTK_MENU(menu), TIME_UNIT_HOUR);
} else {
/* minutes */
if(value >= 60) {
gtk_menu_set_active(GTK_MENU(menu), TIME_UNIT_MINUTE);
} else {
/* seconds */
gtk_menu_set_active(GTK_MENU(menu), TIME_UNIT_SECOND);
}
}
}
gtk_option_menu_set_menu(GTK_OPTION_MENU(unit_om), menu);
return unit_om;
}
/* convert time value from raw to displayed (e.g. 60s -> 1min) */
static guint32 time_unit_option_menu_convert_value(
guint32 value)
{
/* days */
if(value >= 60 * 60 * 24) {
return value / (60 * 60 * 24);
}
/* hours */
if(value >= 60 * 60) {
return value / (60 * 60);
}
/* minutes */
if(value >= 60) {
return value / 60;
}
/* seconds */
return value;
}
/* get raw value from unit and value fields */
static guint32 time_unit_option_menu_get_value(
GtkWidget *unit_om,
guint32 value)
{
GtkWidget *menu, *menu_item;
int unit;
menu = gtk_option_menu_get_menu(GTK_OPTION_MENU(unit_om));
menu_item = gtk_menu_get_active(GTK_MENU(menu));
unit = GPOINTER_TO_INT(g_object_get_data(G_OBJECT(menu_item), "time_unit"));
switch(unit) {
case(TIME_UNIT_SECOND):
return value;
case(TIME_UNIT_MINUTE):
return value * 60;
case(TIME_UNIT_HOUR):
return value * 60 * 60;
case(TIME_UNIT_DAY):
return value * 60 * 60 * 24;
default:
g_assert_not_reached();
return 0;
}
}
#define SIZE_UNIT_KILOBYTES 0
#define SIZE_UNIT_MEGABYTES 1
#define SIZE_UNIT_GIGABYTES 2
#define MAX_SIZE_UNITS 3
static const char *size_unit_name[MAX_SIZE_UNITS] = {
"kilobyte(s)",
"megabyte(s)",
"gigabyte(s)",
};
/* create one of the size options */
/* (and select the matching unit depending on the given value) */
static GtkWidget *size_unit_option_menu_new(guint32 value) {
GtkWidget *unit_om, *menu, *menu_item;
int i;
unit_om=gtk_option_menu_new();
menu=gtk_menu_new();
for(i=0;i<MAX_SIZE_UNITS;i++){
menu_item=gtk_menu_item_new_with_label(size_unit_name[i]);
g_object_set_data(G_OBJECT(menu_item), "size_unit", GINT_TO_POINTER(i));
gtk_menu_append(GTK_MENU(menu), menu_item);
}
/* the selected menu item can't be changed, once the option_menu
is created, so set the matching menu item now */
/* gigabytes */
if(value >= 1024 * 1024) {
gtk_menu_set_active(GTK_MENU(menu), SIZE_UNIT_GIGABYTES);
} else {
/* megabytes */
if(value >= 1024) {
gtk_menu_set_active(GTK_MENU(menu), SIZE_UNIT_MEGABYTES);
} else {
/* kilobytes */
gtk_menu_set_active(GTK_MENU(menu), SIZE_UNIT_KILOBYTES);
}
}
gtk_option_menu_set_menu(GTK_OPTION_MENU(unit_om), menu);
return unit_om;
}
/* convert size value from raw to displayed (e.g. 1024 Bytes -> 1 KB) */
static guint32 size_unit_option_menu_set_value(
guint32 value)
{
/* gigabytes */
if(value >= 1024 * 1024) {
return value / (1024 * 1024);
}
/* megabytes */
if(value >= 1024) {
return value / (1024);
}
/* kilobytes */
return value;
}
/* get raw value from unit and value fields */
static guint32 size_unit_option_menu_convert_value(
GtkWidget *unit_om,
guint32 value)
{
GtkWidget *menu, *menu_item;
int unit;
menu = gtk_option_menu_get_menu(GTK_OPTION_MENU(unit_om));
menu_item = gtk_menu_get_active(GTK_MENU(menu));
unit = GPOINTER_TO_INT(g_object_get_data(G_OBJECT(menu_item), "size_unit"));
switch(unit) {
case(SIZE_UNIT_KILOBYTES):
return value;
case(SIZE_UNIT_MEGABYTES):
if(value > G_MAXINT / 1024) {
return 0;
} else {
return value * 1024;
}
case(SIZE_UNIT_GIGABYTES):
if(value > G_MAXINT / (1024 * 1024)) {
return 0;
} else {
return value * 1024 * 1024;
}
default:
g_assert_not_reached();
return 0;
}
}
#ifdef HAVE_AIRPCAP
/*
* Sets the toolbar before calling the advanced dialog with for the right interface
*/
void
options_airpcap_advanced_cb(GtkWidget *w _U_, gpointer d _U_)
{
int *from_widget;
from_widget = (gint*)g_malloc(sizeof(gint));
*from_widget = AIRPCAP_ADVANCED_FROM_OPTIONS;
g_object_set_data(G_OBJECT(airpcap_tb),AIRPCAP_ADVANCED_FROM_KEY,from_widget);
airpcap_if_active = airpcap_if_selected;
airpcap_enable_toolbar_widgets(airpcap_tb,FALSE);
display_airpcap_advanced_cb(w,d);
}
#endif
#ifdef HAVE_PCAP_REMOTE
/* PCAP interface type menu item */
struct iftype_info {
capture_source id;
const char *name;
};
/* List of available types of PCAP interface */
static struct iftype_info iftype[] = {
{ CAPTURE_IFLOCAL, "Local" },
{ CAPTURE_IFREMOTE, "Remote" }
};
/* Fill the menu of available types of interfaces */
static GtkWidget *
iftype_option_menu_new(capture_source value)
{
GtkWidget *iftype_om, *menu, *menu_item;
unsigned int i, active = 0;
iftype_om = gtk_option_menu_new();
menu = gtk_menu_new();
for (i = 0; i < sizeof(iftype) / sizeof(iftype[0]); i++)
{
menu_item = gtk_menu_item_new_with_label(iftype[i].name);
g_object_set_data(G_OBJECT(menu_item), E_CAP_IFTYPE_OM_KEY, iftype_om);
g_signal_connect(menu_item, "activate", G_CALLBACK(select_if_type_cb),
GINT_TO_POINTER((int)iftype[i].id));
gtk_menu_append(GTK_MENU(menu), menu_item);
if (value == iftype[i].id)
active = i;
}
gtk_menu_set_active(GTK_MENU(menu), active);
gtk_option_menu_set_menu(GTK_OPTION_MENU(iftype_om), menu);
return iftype_om;
}
/* Retrieve the list of local or remote interfaces according to selected
* options and re-fill inteface name combobox */
static void
update_interface_list()
{
GtkWidget *if_cb;
GList *if_list, *combo_list;
int err;
gchar *err_str;
if (cap_open_w == NULL)
return;
if_cb = (GtkWidget *)g_object_get_data(G_OBJECT(cap_open_w), E_CAP_IFACE_KEY);
if (capture_opts->src_type == CAPTURE_IFREMOTE)
if_list = get_remote_interface_list(capture_opts->remote_host,
capture_opts->remote_port,
capture_opts->auth_type,
capture_opts->auth_username,
capture_opts->auth_password,
&err, &err_str);
else
if_list = get_interface_list(&err, &err_str);
if (if_list == NULL && err == CANT_GET_INTERFACE_LIST) {
simple_dialog(ESD_TYPE_ERROR, ESD_BTN_OK, "%s", err_str);
g_free(err_str);
gtk_combo_set_popdown_strings(GTK_COMBO(if_cb), NULL);
gtk_entry_set_text(GTK_ENTRY(GTK_COMBO(if_cb)->entry), "");
}
combo_list = build_capture_combo_list(if_list, TRUE);
if (combo_list != NULL)
gtk_combo_set_popdown_strings(GTK_COMBO(if_cb), combo_list);
free_capture_combo_list(combo_list);
free_interface_list(if_list);
}
/* User changed an interface entry of "Remote interface" dialog */
static void
capture_remote_adjust_sensitivity(GtkWidget *tb _U_, gpointer parent_w)
{
GtkWidget *auth_passwd_rb,
*username_lb, *username_te,
*passwd_lb, *passwd_te;
gboolean state;
auth_passwd_rb = (GtkWidget *)g_object_get_data(G_OBJECT(parent_w),
E_REMOTE_AUTH_PASSWD_KEY);
username_lb = (GtkWidget *)g_object_get_data(G_OBJECT(parent_w),
E_REMOTE_USERNAME_LB_KEY);
username_te = (GtkWidget *)g_object_get_data(G_OBJECT(parent_w),
E_REMOTE_USERNAME_TE_KEY);
passwd_lb = (GtkWidget *)g_object_get_data(G_OBJECT(parent_w), E_REMOTE_PASSWD_LB_KEY);
passwd_te = (GtkWidget *)g_object_get_data(G_OBJECT(parent_w), E_REMOTE_PASSWD_TE_KEY);
state = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(auth_passwd_rb));
gtk_widget_set_sensitive(GTK_WIDGET(username_lb), state);
gtk_widget_set_sensitive(GTK_WIDGET(username_te), state);
gtk_widget_set_sensitive(GTK_WIDGET(passwd_lb), state);
gtk_widget_set_sensitive(GTK_WIDGET(passwd_te), state);
}
/* user requested to destroy the dialog */
static void
capture_remote_destroy_cb(GtkWidget *win, gpointer user_data _U_)
{
GtkWidget *caller;
caller = g_object_get_data(G_OBJECT(win), E_CAP_REMOTE_CALLER_PTR_KEY);
g_object_set_data(G_OBJECT(caller), E_CAP_REMOTE_DIALOG_PTR_KEY, NULL);
}
/* user requested to accept remote interface options */
static void
capture_remote_ok_cb(GtkWidget *win _U_, GtkWidget *remote_w)
{
GtkWidget *host_te, *port_te, *auth_pwd_rb, *username_te, *passwd_te,
*auth_null_rb, *auth_passwd_rb;
if (remote_w == NULL)
return;
host_te = (GtkWidget *)g_object_get_data(G_OBJECT(remote_w), E_REMOTE_HOST_TE_KEY);
port_te = (GtkWidget *)g_object_get_data(G_OBJECT(remote_w), E_REMOTE_PORT_TE_KEY);
auth_pwd_rb = (GtkWidget *)g_object_get_data(G_OBJECT(remote_w),
E_REMOTE_AUTH_PASSWD_KEY);
username_te = (GtkWidget *)g_object_get_data(G_OBJECT(remote_w),
E_REMOTE_USERNAME_TE_KEY);
passwd_te = (GtkWidget *)g_object_get_data(G_OBJECT(remote_w), E_REMOTE_PASSWD_TE_KEY);
auth_null_rb = (GtkWidget *) g_object_get_data(G_OBJECT(remote_w), E_REMOTE_AUTH_NULL_KEY);
auth_passwd_rb = (GtkWidget *) g_object_get_data(G_OBJECT(remote_w), E_REMOTE_AUTH_PASSWD_KEY);
g_free(capture_opts->remote_host);
capture_opts->remote_host = g_strdup(gtk_entry_get_text(GTK_ENTRY(host_te)));
g_free(capture_opts->remote_port);
capture_opts->remote_port = g_strdup(gtk_entry_get_text(GTK_ENTRY(port_te)));
if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(auth_passwd_rb)))
capture_opts->auth_type = CAPTURE_AUTH_PWD;
else
capture_opts->auth_type = CAPTURE_AUTH_NULL;
g_free(capture_opts->auth_username);
capture_opts->auth_username =
g_strdup(gtk_entry_get_text(GTK_ENTRY(username_te)));
g_free(capture_opts->auth_password);
capture_opts->auth_password =
g_strdup(gtk_entry_get_text(GTK_ENTRY(passwd_te)));
capture_opts->src_type = CAPTURE_IFREMOTE;
window_destroy(GTK_WIDGET(remote_w));
update_interface_list();
}
/* Show remote capture interface parameters dialog */
static void
capture_remote_cb(GtkWidget *w _U_, gpointer d _U_)
{
GtkWidget *caller, *remote_w,
*main_vb, *host_tb,
*host_lb, *host_te, *port_lb, *port_te,
*auth_fr, *auth_vb,
*auth_null_rb, *auth_passwd_rb, *auth_passwd_tb,
*user_lb, *user_te, *passwd_lb, *passwd_te,
*bbox, *ok_bt, *cancel_bt;
gchar *title;
GtkTooltips *tooltips;
GSList *auth_group;
caller = gtk_widget_get_toplevel(w);
remote_w = g_object_get_data(G_OBJECT(caller), E_CAP_REMOTE_DIALOG_PTR_KEY);
if (remote_w != NULL)
{
reactivate_window(remote_w);
return;
}
title = create_user_window_title("Wireshark: Remote Interface");
remote_w = dlg_window_new(title);
g_object_set_data(G_OBJECT(remote_w), E_CAP_REMOTE_CALLER_PTR_KEY, caller);
g_object_set_data(G_OBJECT(caller), E_CAP_REMOTE_DIALOG_PTR_KEY, remote_w);
g_free(title);
tooltips = gtk_tooltips_new();
main_vb = gtk_vbox_new(FALSE, 0);
gtk_container_border_width(GTK_CONTAINER(main_vb), 5);
gtk_container_add(GTK_CONTAINER(remote_w), main_vb);
/* Host/port table */
host_tb = gtk_table_new(2, 2, FALSE);
gtk_table_set_row_spacings(GTK_TABLE(host_tb), 3);
gtk_table_set_col_spacings(GTK_TABLE(host_tb), 3);
gtk_box_pack_start(GTK_BOX(main_vb), host_tb, FALSE, FALSE, 0);
/* Host row */
host_lb = gtk_label_new("Host:");
gtk_table_attach_defaults(GTK_TABLE(host_tb), host_lb, 0, 1, 0, 1);
host_te = gtk_entry_new();
gtk_tooltips_set_tip(tooltips, host_te,
"Enter the hostname or host IP address to be used as a source "
"for remote capture.", NULL);
gtk_table_attach_defaults(GTK_TABLE(host_tb), host_te, 1, 2, 0, 1);
if (capture_opts->remote_host != NULL)
gtk_entry_set_text(GTK_ENTRY(host_te), capture_opts->remote_host);
/* Port row */
port_lb = gtk_label_new("Port:");
gtk_table_attach_defaults(GTK_TABLE(host_tb), port_lb, 0, 1, 1, 2);
port_te = gtk_entry_new();
gtk_tooltips_set_tip(tooltips, port_te,
"Enter the TCP port number used by RPCAP server at remote host "
"(leave it empty for default port number).", NULL);
gtk_table_attach_defaults(GTK_TABLE(host_tb), port_te, 1, 2, 1, 2);
if (capture_opts->remote_port != NULL)
gtk_entry_set_text(GTK_ENTRY(port_te), capture_opts->remote_port);
/* Authentication options frame */
auth_fr = gtk_frame_new("Authentication");
gtk_container_add(GTK_CONTAINER(main_vb), auth_fr);
auth_vb = gtk_vbox_new(FALSE, 3);
gtk_container_border_width(GTK_CONTAINER(auth_vb), 5);
gtk_container_add(GTK_CONTAINER(auth_fr), auth_vb);
auth_null_rb = gtk_radio_button_new_with_label(NULL,
"Null authentication");
gtk_box_pack_start(GTK_BOX(auth_vb), auth_null_rb, TRUE, TRUE, 0);
auth_group = gtk_radio_button_get_group(GTK_RADIO_BUTTON(auth_null_rb));
auth_passwd_rb = gtk_radio_button_new_with_label(auth_group,
"Password authentication");
gtk_box_pack_start(GTK_BOX(auth_vb), auth_passwd_rb, TRUE, TRUE, 0);
g_signal_connect(auth_passwd_rb, "toggled",
G_CALLBACK(capture_remote_adjust_sensitivity), remote_w);
auth_passwd_tb = gtk_table_new(2, 2, FALSE);
gtk_table_set_row_spacings(GTK_TABLE(auth_passwd_tb), 3);
gtk_table_set_col_spacings(GTK_TABLE(auth_passwd_tb), 3);
gtk_box_pack_start(GTK_BOX(auth_vb), auth_passwd_tb, FALSE, FALSE, 0);
user_lb = gtk_label_new("Username:");
gtk_table_attach_defaults(GTK_TABLE(auth_passwd_tb), user_lb, 0, 1, 0, 1);
user_te = gtk_entry_new();
gtk_table_attach_defaults(GTK_TABLE(auth_passwd_tb), user_te, 1, 2, 0, 1);
if (capture_opts->auth_username != NULL)
gtk_entry_set_text(GTK_ENTRY(user_te), capture_opts->auth_username);
passwd_lb = gtk_label_new("Password:");
gtk_table_attach_defaults(GTK_TABLE(auth_passwd_tb), passwd_lb, 0, 1, 1, 2);
passwd_te = gtk_entry_new();
gtk_entry_set_visibility(GTK_ENTRY(passwd_te), FALSE);
gtk_table_attach_defaults(GTK_TABLE(auth_passwd_tb), passwd_te, 1, 2, 1, 2);
if (capture_opts->auth_password != NULL)
gtk_entry_set_text(GTK_ENTRY(passwd_te), capture_opts->auth_password);
/* Button row: "Start" and "Cancel" buttons */
bbox = dlg_button_row_new(GTK_STOCK_OK, GTK_STOCK_CANCEL, NULL);
gtk_box_pack_start(GTK_BOX(main_vb), bbox, FALSE, FALSE, 5);
ok_bt = g_object_get_data(G_OBJECT(bbox), GTK_STOCK_OK);
g_signal_connect(ok_bt, "clicked", G_CALLBACK(capture_remote_ok_cb), remote_w);
gtk_tooltips_set_tip(tooltips, ok_bt,
"Accept remote host parameters and lookup "
"remote interfaces.", NULL);
cancel_bt = g_object_get_data(G_OBJECT(bbox), GTK_STOCK_CANCEL);
gtk_tooltips_set_tip(tooltips, cancel_bt,
"Cancel and exit dialog.", NULL);
window_set_cancel_button(remote_w, cancel_bt, window_cancel_button_cb);
gtk_widget_grab_default(ok_bt);
g_signal_connect(remote_w, "delete_event", G_CALLBACK(window_delete_event_cb), NULL);
g_signal_connect(remote_w, "destroy", G_CALLBACK(capture_remote_destroy_cb), NULL);
g_object_set_data(G_OBJECT(remote_w), E_REMOTE_HOST_TE_KEY, host_te);
g_object_set_data(G_OBJECT(remote_w), E_REMOTE_PORT_TE_KEY, port_te);
g_object_set_data(G_OBJECT(remote_w), E_REMOTE_AUTH_NULL_KEY, auth_null_rb);
g_object_set_data(G_OBJECT(remote_w), E_REMOTE_AUTH_PASSWD_KEY, auth_passwd_rb);
g_object_set_data(G_OBJECT(remote_w), E_REMOTE_USERNAME_LB_KEY, user_lb);
g_object_set_data(G_OBJECT(remote_w), E_REMOTE_USERNAME_TE_KEY, user_te);
g_object_set_data(G_OBJECT(remote_w), E_REMOTE_PASSWD_LB_KEY, passwd_lb);
g_object_set_data(G_OBJECT(remote_w), E_REMOTE_PASSWD_TE_KEY, passwd_te);
if (capture_opts->auth_type == CAPTURE_AUTH_PWD)
gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(auth_passwd_rb), TRUE);
else
gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(auth_null_rb), TRUE);
capture_remote_adjust_sensitivity(NULL, remote_w);
gtk_widget_show_all(remote_w);
window_present(remote_w);
}
#endif
/* show capture prepare (options) dialog */
void
capture_prep_cb(GtkWidget *w _U_, gpointer d _U_)
{
GtkWidget *main_vb,
*main_hb, *left_vb, *right_vb,
*capture_fr, *capture_vb,
*if_hb, *if_cb, *if_lb,
*if_ip_hb, *if_ip_lb, *if_ip_eb,
*linktype_hb, *linktype_lb, *linktype_om,
*snap_hb, *snap_cb, *snap_sb, *snap_lb,
*promisc_cb,
*filter_hb, *filter_bt, *filter_te, *filter_cm,
*file_fr, *file_vb,
*file_hb, *file_bt, *file_lb, *file_te,
*multi_tb, *multi_files_on_cb,
*ring_filesize_cb, *ring_filesize_sb, *ring_filesize_om,
*file_duration_cb, *file_duration_sb, *file_duration_om,
*ringbuffer_nbf_cb, *ringbuffer_nbf_sb, *ringbuffer_nbf_lb,
*stop_files_cb, *stop_files_sb, *stop_files_lb,
*limit_fr, *limit_vb, *limit_tb,
*stop_packets_cb, *stop_packets_sb, *stop_packets_lb,
*stop_filesize_cb, *stop_filesize_sb, *stop_filesize_om,
*stop_duration_cb, *stop_duration_sb, *stop_duration_om,
*display_fr, *display_vb,
*sync_cb, *auto_scroll_cb, *hide_info_cb,
*resolv_fr, *resolv_vb,
*m_resolv_cb, *n_resolv_cb, *t_resolv_cb,
*bbox, *ok_bt, *cancel_bt,
*help_bt;
#ifdef HAVE_AIRPCAP
GtkWidget *advanced_hb, *advanced_bt;
#endif
#ifdef HAVE_PCAP_REMOTE
GtkWidget *iftype_om, *nocap_rpcap_cb, *datatx_udp_cb;
#ifdef HAVE_PCAP_SETSAMPLING
GtkWidget *sampling_fr, *sampling_vb, *sampling_tb, *sampling_lb,
*samp_none_rb, *samp_count_rb, *samp_timer_rb,
*samp_count_sb, *samp_timer_sb;
GtkAdjustment *samp_count_adj, *samp_timer_adj;
GSList *samp_group;
#endif
#endif
GtkTooltips *tooltips;
GtkAdjustment *snap_adj, *ringbuffer_nbf_adj,
*stop_packets_adj, *stop_filesize_adj, *stop_duration_adj, *stop_files_adj, *ring_filesize_adj, *file_duration_adj;
GList *if_list, *combo_list, *cfilter_list;
int row;
int err;
gchar *err_str;
#ifdef _WIN32
GtkAdjustment *buffer_size_adj;
GtkWidget *buffer_size_lb, *buffer_size_sb;
#endif
guint32 value;
gchar *cap_title;
gchar *if_device;
#ifdef HAVE_AIRPCAP
GtkWidget *decryption_cm;
#endif
if (cap_open_w != NULL) {
/* There's already a "Capture Options" dialog box; reactivate it. */
reactivate_window(cap_open_w);
return;
}
#ifdef _WIN32
/* Is WPcap loaded? */
if (!has_wpcap) {
char *detailed_err;
detailed_err = cant_load_winpcap_err("Wireshark");
simple_dialog(ESD_TYPE_ERROR, ESD_BTN_OK, "%s", detailed_err);
g_free(detailed_err);
return;
}
#endif
#ifdef HAVE_PCAP_REMOTE
if (capture_opts->src_type == CAPTURE_IFREMOTE)
if_list = get_remote_interface_list(capture_opts->remote_host,
capture_opts->remote_port,
capture_opts->auth_type,
capture_opts->auth_username,
capture_opts->auth_password,
&err, &err_str);
else
if_list = get_interface_list(&err, &err_str);
#else
if_list = capture_interface_list(&err, &err_str);
#endif
if (if_list == NULL && err == CANT_GET_INTERFACE_LIST) {
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 = g_object_get_data(G_OBJECT(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);