1998-09-16 02:39:15 +00:00
|
|
|
/* capture.c
|
|
|
|
* Routines for packet capture windows
|
|
|
|
*
|
1999-06-05 01:44:11 +00:00
|
|
|
* $Id: capture.c,v 1.24 1999/06/05 01:44:11 guy Exp $
|
1998-09-16 03:22:19 +00:00
|
|
|
*
|
1998-09-16 02:39:15 +00:00
|
|
|
* Ethereal - Network traffic analyzer
|
|
|
|
* By Gerald Combs <gerald@zing.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.
|
|
|
|
*/
|
|
|
|
|
1998-10-10 03:32:20 +00:00
|
|
|
|
1998-09-16 02:39:15 +00:00
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
# include "config.h"
|
|
|
|
#endif
|
|
|
|
|
1998-10-10 03:32:20 +00:00
|
|
|
#ifdef HAVE_SYS_TYPES_H
|
|
|
|
# include <sys/types.h>
|
|
|
|
#endif
|
|
|
|
|
1998-09-16 02:39:15 +00:00
|
|
|
#include <gtk/gtk.h>
|
|
|
|
#include <pcap.h>
|
|
|
|
|
1998-12-17 05:42:33 +00:00
|
|
|
#include <stdlib.h>
|
1999-04-06 16:24:50 +00:00
|
|
|
#include <stdio.h>
|
1998-09-16 02:39:15 +00:00
|
|
|
#include <string.h>
|
1998-10-13 07:03:37 +00:00
|
|
|
#include <unistd.h>
|
1998-12-29 04:05:38 +00:00
|
|
|
#include <time.h>
|
1998-09-16 02:39:15 +00:00
|
|
|
#include <sys/socket.h>
|
|
|
|
#include <sys/ioctl.h>
|
|
|
|
#include <net/if.h>
|
1999-05-11 18:51:10 +00:00
|
|
|
#include <signal.h>
|
|
|
|
#include <errno.h>
|
1998-09-16 02:39:15 +00:00
|
|
|
|
1998-10-10 03:32:20 +00:00
|
|
|
#ifdef NEED_SNPRINTF_H
|
1998-10-13 07:03:37 +00:00
|
|
|
# ifdef HAVE_STDARG_H
|
|
|
|
# include <stdarg.h>
|
|
|
|
# else
|
|
|
|
# include <varargs.h>
|
|
|
|
# endif
|
1998-10-10 03:32:20 +00:00
|
|
|
# include "snprintf.h"
|
|
|
|
#endif
|
|
|
|
|
1998-09-16 02:39:15 +00:00
|
|
|
#ifdef HAVE_SYS_SOCKIO_H
|
|
|
|
# include <sys/sockio.h>
|
|
|
|
#endif
|
|
|
|
|
1998-09-27 22:12:47 +00:00
|
|
|
#include "ethereal.h"
|
1998-09-16 02:39:15 +00:00
|
|
|
#include "packet.h"
|
|
|
|
#include "file.h"
|
1999-04-06 16:24:50 +00:00
|
|
|
#include "menu.h"
|
1998-09-16 02:39:15 +00:00
|
|
|
#include "capture.h"
|
|
|
|
#include "etypes.h"
|
|
|
|
#include "util.h"
|
1998-10-12 01:40:57 +00:00
|
|
|
#include "prefs.h"
|
1998-09-16 02:39:15 +00:00
|
|
|
|
|
|
|
extern capture_file cf;
|
|
|
|
extern GtkWidget *info_bar;
|
|
|
|
extern guint file_ctx;
|
|
|
|
|
1999-05-11 18:51:10 +00:00
|
|
|
extern gchar *ethereal_path;
|
|
|
|
extern gchar *medium_font;
|
|
|
|
extern gchar *bold_font;
|
|
|
|
extern int fork_mode;
|
|
|
|
extern int sync_pipe[];
|
|
|
|
extern int sync_mode;
|
|
|
|
extern int sigusr2_received;
|
|
|
|
extern int quit_after_cap;
|
|
|
|
|
1998-09-16 02:39:15 +00:00
|
|
|
/* File selection data keys */
|
1998-10-12 01:40:57 +00:00
|
|
|
#define E_CAP_PREP_FS_KEY "cap_prep_fs"
|
|
|
|
#define E_CAP_PREP_TE_KEY "cap_prep_te"
|
1998-09-16 02:39:15 +00:00
|
|
|
|
|
|
|
/* Capture callback data keys */
|
1998-10-12 01:40:57 +00:00
|
|
|
#define E_CAP_IFACE_KEY "cap_iface"
|
|
|
|
#define E_CAP_FILT_KEY "cap_filter"
|
|
|
|
#define E_CAP_COUNT_KEY "cap_count"
|
|
|
|
#define E_CAP_OPEN_KEY "cap_open"
|
|
|
|
#define E_CAP_SNAP_KEY "cap_snap"
|
|
|
|
|
|
|
|
/* Capture filter key */
|
|
|
|
#define E_CAP_FILT_TE_KEY "cap_filt_te"
|
1998-09-16 02:39:15 +00:00
|
|
|
|
|
|
|
GList *
|
|
|
|
get_interface_list() {
|
|
|
|
GList *il = NULL;
|
|
|
|
struct ifreq *ifr, *last;
|
|
|
|
struct ifconf ifc;
|
|
|
|
int sock = socket(AF_INET, SOCK_DGRAM, 0);
|
|
|
|
|
|
|
|
if (sock < 0)
|
|
|
|
{
|
|
|
|
simple_dialog(ESD_TYPE_WARN, NULL,
|
|
|
|
"Can't list interfaces: error opening socket.");
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Since we have to grab the interface list all at once, we'll make
|
|
|
|
plenty of room */
|
|
|
|
ifc.ifc_len = 1024 * sizeof(struct ifreq);
|
|
|
|
ifc.ifc_buf = malloc(ifc.ifc_len);
|
|
|
|
|
|
|
|
if (ioctl(sock, SIOCGIFCONF, &ifc) < 0 ||
|
|
|
|
ifc.ifc_len < sizeof(struct ifreq))
|
|
|
|
{
|
|
|
|
simple_dialog(ESD_TYPE_WARN, NULL,
|
|
|
|
"Can't list interfaces: ioctl error.");
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
ifr = (struct ifreq *) ifc.ifc_req;
|
|
|
|
last = (struct ifreq *) ((char *) ifr + ifc.ifc_len);
|
|
|
|
while (ifr < last)
|
|
|
|
{
|
|
|
|
/*
|
|
|
|
* What we want:
|
|
|
|
* - Interfaces that are up, and not loopback
|
|
|
|
* - IP interfaces (do we really need this?)
|
|
|
|
* - Anything that doesn't begin with "lo" (loopback again) or "dummy"
|
|
|
|
* - Anything that doesn't include a ":" (Solaris virtuals)
|
|
|
|
*/
|
|
|
|
if (! (ifr->ifr_flags & (IFF_UP | IFF_LOOPBACK)) &&
|
|
|
|
(ifr->ifr_addr.sa_family == AF_INET) &&
|
|
|
|
strncmp(ifr->ifr_name, "lo", 2) &&
|
|
|
|
strncmp(ifr->ifr_name, "dummy", 5) &&
|
|
|
|
! strchr(ifr->ifr_name, ':')) {
|
|
|
|
il = g_list_append(il, g_strdup(ifr->ifr_name));
|
|
|
|
}
|
1998-11-17 02:17:27 +00:00
|
|
|
#ifdef HAVE_SA_LEN
|
1998-09-16 02:39:15 +00:00
|
|
|
ifr = (struct ifreq *) ((char *) ifr + ifr->ifr_addr.sa_len + IFNAMSIZ);
|
|
|
|
#else
|
|
|
|
ifr = (struct ifreq *) ((char *) ifr + sizeof(struct ifreq));
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
free(ifc.ifc_buf);
|
|
|
|
return il;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
capture_prep_cb(GtkWidget *w, gpointer d) {
|
1999-04-06 16:24:50 +00:00
|
|
|
GtkWidget *cap_open_w, *if_cb, *if_lb,
|
1998-10-12 01:40:57 +00:00
|
|
|
*count_lb, *count_cb, *main_vb, *if_hb, *count_hb,
|
1999-04-06 16:24:50 +00:00
|
|
|
*filter_hb, *filter_bt, *filter_te, *caplen_hb,
|
|
|
|
*bbox, *ok_bt, *cancel_bt, *snap_lb,
|
1998-10-12 01:40:57 +00:00
|
|
|
*snap_sb;
|
1998-09-16 02:39:15 +00:00
|
|
|
GtkAdjustment *adj;
|
|
|
|
GList *if_list, *count_list = NULL;
|
|
|
|
gchar *count_item1 = "0 (Infinite)", count_item2[16];
|
|
|
|
|
|
|
|
cap_open_w = gtk_window_new(GTK_WINDOW_TOPLEVEL);
|
|
|
|
gtk_window_set_title(GTK_WINDOW(cap_open_w), "Ethereal: Capture Preferences");
|
|
|
|
|
|
|
|
/* Container for each row of widgets */
|
|
|
|
main_vb = gtk_vbox_new(FALSE, 3);
|
|
|
|
gtk_container_border_width(GTK_CONTAINER(main_vb), 5);
|
|
|
|
gtk_container_add(GTK_CONTAINER(cap_open_w), main_vb);
|
|
|
|
gtk_widget_show(main_vb);
|
|
|
|
|
1998-10-12 01:40:57 +00:00
|
|
|
/* Interface row */
|
|
|
|
if_hb = gtk_hbox_new(FALSE, 3);
|
|
|
|
gtk_container_add(GTK_CONTAINER(main_vb), if_hb);
|
|
|
|
gtk_widget_show(if_hb);
|
1998-09-16 02:39:15 +00:00
|
|
|
|
|
|
|
if_lb = gtk_label_new("Interface:");
|
1998-10-12 01:40:57 +00:00
|
|
|
gtk_box_pack_start(GTK_BOX(if_hb), if_lb, FALSE, FALSE, 0);
|
1998-09-16 02:39:15 +00:00
|
|
|
gtk_widget_show(if_lb);
|
|
|
|
|
|
|
|
if_list = get_interface_list();
|
1998-10-12 01:40:57 +00:00
|
|
|
|
1998-09-16 02:39:15 +00:00
|
|
|
if_cb = gtk_combo_new();
|
|
|
|
gtk_combo_set_popdown_strings(GTK_COMBO(if_cb), if_list);
|
|
|
|
if (cf.iface)
|
|
|
|
gtk_entry_set_text(GTK_ENTRY(GTK_COMBO(if_cb)->entry), cf.iface);
|
|
|
|
else if (if_list)
|
|
|
|
gtk_entry_set_text(GTK_ENTRY(GTK_COMBO(if_cb)->entry), if_list->data);
|
1998-10-12 01:40:57 +00:00
|
|
|
gtk_box_pack_start(GTK_BOX(if_hb), if_cb, FALSE, FALSE, 0);
|
1998-09-16 02:39:15 +00:00
|
|
|
gtk_widget_show(if_cb);
|
1998-10-12 01:40:57 +00:00
|
|
|
|
1998-09-16 02:39:15 +00:00
|
|
|
while (if_list) {
|
|
|
|
g_free(if_list->data);
|
|
|
|
if_list = g_list_remove_link(if_list, if_list);
|
|
|
|
}
|
|
|
|
|
1998-10-12 01:40:57 +00:00
|
|
|
/* Count row */
|
|
|
|
count_hb = gtk_hbox_new(FALSE, 3);
|
|
|
|
gtk_container_add(GTK_CONTAINER(main_vb), count_hb);
|
|
|
|
gtk_widget_show(count_hb);
|
|
|
|
|
|
|
|
count_lb = gtk_label_new("Count:");
|
|
|
|
gtk_box_pack_start(GTK_BOX(count_hb), count_lb, FALSE, FALSE, 0);
|
|
|
|
gtk_widget_show(count_lb);
|
|
|
|
|
1999-06-01 22:24:05 +00:00
|
|
|
count_list = g_list_append(count_list, count_item1);
|
1998-09-16 02:39:15 +00:00
|
|
|
if (cf.count) {
|
|
|
|
snprintf(count_item2, 15, "%d", cf.count);
|
|
|
|
count_list = g_list_append(count_list, count_item2);
|
|
|
|
}
|
1998-10-12 01:40:57 +00:00
|
|
|
|
1998-09-16 02:39:15 +00:00
|
|
|
count_cb = gtk_combo_new();
|
|
|
|
gtk_combo_set_popdown_strings(GTK_COMBO(count_cb), count_list);
|
1998-10-12 01:40:57 +00:00
|
|
|
gtk_box_pack_start(GTK_BOX(count_hb), count_cb, FALSE, FALSE, 0);
|
1998-09-16 02:39:15 +00:00
|
|
|
gtk_widget_show(count_cb);
|
1998-10-12 01:40:57 +00:00
|
|
|
|
1998-09-16 02:39:15 +00:00
|
|
|
while (count_list)
|
|
|
|
count_list = g_list_remove_link(count_list, count_list);
|
|
|
|
|
1998-10-12 01:40:57 +00:00
|
|
|
/* Filter row */
|
|
|
|
filter_hb = gtk_hbox_new(FALSE, 3);
|
|
|
|
gtk_container_add(GTK_CONTAINER(main_vb), filter_hb);
|
|
|
|
gtk_widget_show(filter_hb);
|
|
|
|
|
|
|
|
filter_bt = gtk_button_new_with_label("Filter:");
|
|
|
|
gtk_signal_connect(GTK_OBJECT(filter_bt), "clicked",
|
|
|
|
GTK_SIGNAL_FUNC(prefs_cb), (gpointer) E_PR_PG_FILTER);
|
|
|
|
gtk_box_pack_start(GTK_BOX(filter_hb), filter_bt, FALSE, TRUE, 0);
|
|
|
|
gtk_widget_show(filter_bt);
|
1998-09-16 02:39:15 +00:00
|
|
|
|
1998-10-12 01:40:57 +00:00
|
|
|
filter_te = gtk_entry_new();
|
|
|
|
if (cf.cfilter) gtk_entry_set_text(GTK_ENTRY(filter_te), cf.cfilter);
|
|
|
|
gtk_object_set_data(GTK_OBJECT(filter_bt), E_FILT_TE_PTR_KEY, filter_te);
|
|
|
|
gtk_box_pack_start(GTK_BOX(filter_hb), filter_te, TRUE, TRUE, 0);
|
|
|
|
gtk_widget_show(filter_te);
|
1998-09-16 02:39:15 +00:00
|
|
|
|
1998-10-12 01:40:57 +00:00
|
|
|
/* Misc row: Capture file checkbox and snap spinbutton */
|
|
|
|
caplen_hb = gtk_hbox_new(FALSE, 3);
|
|
|
|
gtk_container_add(GTK_CONTAINER(main_vb), caplen_hb);
|
|
|
|
gtk_widget_show(caplen_hb);
|
|
|
|
|
1998-09-16 02:39:15 +00:00
|
|
|
snap_lb = gtk_label_new("Capture length");
|
|
|
|
gtk_misc_set_alignment(GTK_MISC(snap_lb), 0, 0.5);
|
1998-10-12 01:40:57 +00:00
|
|
|
gtk_box_pack_start(GTK_BOX(caplen_hb), snap_lb, FALSE, FALSE, 6);
|
1998-09-16 02:39:15 +00:00
|
|
|
gtk_widget_show(snap_lb);
|
|
|
|
|
1999-02-11 07:11:45 +00:00
|
|
|
adj = (GtkAdjustment *) gtk_adjustment_new((float) cf.snap,
|
|
|
|
MIN_PACKET_SIZE, MAX_PACKET_SIZE, 1.0, 10.0, 0.0);
|
1998-09-16 02:39:15 +00:00
|
|
|
snap_sb = gtk_spin_button_new (adj, 0, 0);
|
|
|
|
gtk_spin_button_set_wrap (GTK_SPIN_BUTTON (snap_sb), TRUE);
|
|
|
|
gtk_widget_set_usize (snap_sb, 80, 0);
|
1998-10-12 01:40:57 +00:00
|
|
|
gtk_box_pack_start (GTK_BOX(caplen_hb), snap_sb, FALSE, FALSE, 3);
|
1998-09-16 02:39:15 +00:00
|
|
|
gtk_widget_show(snap_sb);
|
|
|
|
|
|
|
|
/* Button row: OK and cancel buttons */
|
|
|
|
bbox = gtk_hbutton_box_new();
|
|
|
|
gtk_button_box_set_layout (GTK_BUTTON_BOX (bbox), GTK_BUTTONBOX_END);
|
1998-10-12 01:40:57 +00:00
|
|
|
gtk_button_box_set_spacing(GTK_BUTTON_BOX(bbox), 5);
|
1998-09-16 02:39:15 +00:00
|
|
|
gtk_container_add(GTK_CONTAINER(main_vb), bbox);
|
|
|
|
gtk_widget_show(bbox);
|
1998-10-12 01:40:57 +00:00
|
|
|
|
1998-09-16 02:39:15 +00:00
|
|
|
ok_bt = gtk_button_new_with_label ("OK");
|
|
|
|
gtk_signal_connect_object(GTK_OBJECT(ok_bt), "clicked",
|
|
|
|
GTK_SIGNAL_FUNC(capture_prep_ok_cb), GTK_OBJECT(cap_open_w));
|
1998-10-12 01:40:57 +00:00
|
|
|
GTK_WIDGET_SET_FLAGS(ok_bt, GTK_CAN_DEFAULT);
|
|
|
|
gtk_box_pack_start (GTK_BOX (bbox), ok_bt, TRUE, TRUE, 0);
|
|
|
|
gtk_widget_grab_default(ok_bt);
|
1998-09-16 02:39:15 +00:00
|
|
|
gtk_widget_show(ok_bt);
|
|
|
|
|
|
|
|
cancel_bt = gtk_button_new_with_label ("Cancel");
|
|
|
|
gtk_signal_connect_object(GTK_OBJECT(cancel_bt), "clicked",
|
|
|
|
GTK_SIGNAL_FUNC(capture_prep_close_cb), GTK_OBJECT(cap_open_w));
|
1998-10-28 21:38:11 +00:00
|
|
|
GTK_WIDGET_SET_FLAGS(cancel_bt, GTK_CAN_DEFAULT);
|
1998-10-12 01:40:57 +00:00
|
|
|
gtk_box_pack_start (GTK_BOX (bbox), cancel_bt, TRUE, TRUE, 0);
|
1998-09-16 02:39:15 +00:00
|
|
|
gtk_widget_show(cancel_bt);
|
|
|
|
|
1998-12-22 05:52:51 +00:00
|
|
|
/* Attach pointers to needed widgets to the capture prefs window/object */
|
1998-10-12 01:40:57 +00:00
|
|
|
gtk_object_set_data(GTK_OBJECT(cap_open_w), E_CAP_IFACE_KEY, if_cb);
|
|
|
|
gtk_object_set_data(GTK_OBJECT(cap_open_w), E_CAP_FILT_KEY, filter_te);
|
|
|
|
gtk_object_set_data(GTK_OBJECT(cap_open_w), E_CAP_COUNT_KEY, count_cb);
|
|
|
|
gtk_object_set_data(GTK_OBJECT(cap_open_w), E_CAP_SNAP_KEY, snap_sb);
|
1998-12-22 07:07:11 +00:00
|
|
|
|
1998-09-16 02:39:15 +00:00
|
|
|
gtk_widget_show(cap_open_w);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
capture_prep_file_cb(GtkWidget *w, gpointer te) {
|
|
|
|
GtkWidget *fs;
|
|
|
|
|
|
|
|
fs = gtk_file_selection_new ("Ethereal: Open Save File");
|
|
|
|
|
1998-10-12 01:40:57 +00:00
|
|
|
gtk_object_set_data(GTK_OBJECT(w), E_CAP_PREP_FS_KEY, fs);
|
|
|
|
gtk_object_set_data(GTK_OBJECT(w), E_CAP_PREP_TE_KEY, (GtkWidget *) te);
|
1998-09-16 02:39:15 +00:00
|
|
|
|
|
|
|
gtk_signal_connect (GTK_OBJECT (GTK_FILE_SELECTION(fs)->ok_button),
|
|
|
|
"clicked", (GtkSignalFunc) cap_prep_fs_ok_cb, w);
|
|
|
|
|
|
|
|
/* Connect the cancel_button to destroy the widget */
|
|
|
|
gtk_signal_connect (GTK_OBJECT (GTK_FILE_SELECTION(fs)->cancel_button),
|
|
|
|
"clicked", (GtkSignalFunc) cap_prep_fs_cancel_cb, w);
|
|
|
|
|
|
|
|
gtk_widget_show(fs);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
cap_prep_fs_ok_cb(GtkWidget *w, gpointer data) {
|
|
|
|
GtkWidget *fs, *te;
|
|
|
|
|
1998-10-12 01:40:57 +00:00
|
|
|
fs = (GtkWidget *) gtk_object_get_data(GTK_OBJECT(data), E_CAP_PREP_FS_KEY);
|
|
|
|
te = (GtkWidget *) gtk_object_get_data(GTK_OBJECT(data), E_CAP_PREP_TE_KEY);
|
1998-09-16 02:39:15 +00:00
|
|
|
|
|
|
|
gtk_entry_set_text(GTK_ENTRY(te),
|
|
|
|
gtk_file_selection_get_filename (GTK_FILE_SELECTION(fs)));
|
|
|
|
cap_prep_fs_cancel_cb(w, data);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
cap_prep_fs_cancel_cb(GtkWidget *w, gpointer data) {
|
|
|
|
GtkWidget *fs;
|
|
|
|
|
1998-10-12 01:40:57 +00:00
|
|
|
fs = (GtkWidget *) gtk_object_get_data(GTK_OBJECT(data), E_CAP_PREP_FS_KEY);
|
1998-09-16 02:39:15 +00:00
|
|
|
|
|
|
|
gtk_widget_destroy(fs);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
capture_prep_ok_cb(GtkWidget *w, gpointer data) {
|
1999-04-06 16:24:50 +00:00
|
|
|
GtkWidget *if_cb, *filter_te, *count_cb, *snap_sb;
|
1998-09-16 02:39:15 +00:00
|
|
|
|
1999-04-06 16:24:50 +00:00
|
|
|
gchar *filter_text;
|
1998-12-22 07:07:11 +00:00
|
|
|
#ifdef GTK_HAVE_FEATURES_1_1_0
|
|
|
|
data = w;
|
|
|
|
#endif
|
1998-10-12 01:40:57 +00:00
|
|
|
if_cb = (GtkWidget *) gtk_object_get_data(GTK_OBJECT(data), E_CAP_IFACE_KEY);
|
|
|
|
filter_te = (GtkWidget *) gtk_object_get_data(GTK_OBJECT(data), E_CAP_FILT_KEY);
|
|
|
|
count_cb = (GtkWidget *) gtk_object_get_data(GTK_OBJECT(data), E_CAP_COUNT_KEY);
|
|
|
|
snap_sb = (GtkWidget *) gtk_object_get_data(GTK_OBJECT(data), E_CAP_SNAP_KEY);
|
1998-09-16 02:39:15 +00:00
|
|
|
|
|
|
|
if (cf.iface) g_free(cf.iface);
|
|
|
|
cf.iface =
|
|
|
|
g_strdup(gtk_entry_get_text(GTK_ENTRY(GTK_COMBO(if_cb)->entry)));
|
1999-04-06 16:24:50 +00:00
|
|
|
|
|
|
|
filter_text = gtk_entry_get_text(GTK_ENTRY(filter_te));
|
1998-10-12 01:40:57 +00:00
|
|
|
if (cf.cfilter) g_free(cf.cfilter);
|
1999-04-06 16:24:50 +00:00
|
|
|
if (filter_text && filter_text[0]) {
|
|
|
|
cf.cfilter = g_strdup(gtk_entry_get_text(GTK_ENTRY(filter_te)));
|
|
|
|
}
|
1999-06-05 01:44:11 +00:00
|
|
|
cf.count = atoi(gtk_entry_get_text(GTK_ENTRY(GTK_COMBO(count_cb)->entry)));
|
1998-09-16 02:39:15 +00:00
|
|
|
cf.snap = gtk_spin_button_get_value_as_int(GTK_SPIN_BUTTON(snap_sb));
|
|
|
|
if (cf.snap < 1)
|
1999-02-11 06:17:30 +00:00
|
|
|
cf.snap = MAX_PACKET_SIZE;
|
|
|
|
else if (cf.snap < MIN_PACKET_SIZE)
|
|
|
|
cf.snap = MIN_PACKET_SIZE;
|
1998-09-16 02:39:15 +00:00
|
|
|
|
|
|
|
gtk_widget_destroy(GTK_WIDGET(data));
|
1999-04-06 16:24:50 +00:00
|
|
|
|
|
|
|
/* Choose a random name for the capture buffer */
|
|
|
|
if (cf.save_file && !cf.user_saved) {
|
|
|
|
unlink(cf.save_file); /* silently ignore error */
|
|
|
|
g_free(cf.save_file);
|
|
|
|
}
|
|
|
|
cf.save_file = tempnam(NULL, "ether");
|
|
|
|
cf.user_saved = 0;
|
1998-09-16 02:39:15 +00:00
|
|
|
|
1999-05-11 18:51:10 +00:00
|
|
|
if( fork_mode ){ /* use fork() for capture */
|
|
|
|
int fork_child;
|
|
|
|
char ssnap[24];
|
|
|
|
char scount[24]; /* need a constant for len of numbers */
|
|
|
|
|
|
|
|
sprintf(ssnap,"%d",cf.snap); /* in liu of itoa */
|
|
|
|
sprintf(scount,"%d",cf.count);
|
|
|
|
signal(SIGCHLD, SIG_IGN);
|
|
|
|
if (sync_mode) pipe(sync_pipe);
|
|
|
|
if((fork_child = fork()) == 0){
|
|
|
|
/* args: -k -- capture
|
|
|
|
* -i interface specification
|
|
|
|
* -w file to write
|
|
|
|
* -c count to capture
|
|
|
|
* -Q quit after capture (forces -k)
|
|
|
|
* -s snaplen
|
|
|
|
* -S sync mode
|
|
|
|
* -m / -b fonts
|
|
|
|
* -f "filter expression"
|
|
|
|
*/
|
|
|
|
if (sync_mode) {
|
|
|
|
close(1);
|
|
|
|
dup(sync_pipe[1]);
|
|
|
|
close(sync_pipe[0]);
|
|
|
|
execl(ethereal_path,"ethereal","-k","-Q","-i",cf.iface,"-w",cf.save_file,
|
|
|
|
"-c", scount, "-s", ssnap, "-S",
|
|
|
|
"-m", medium_font, "-b", bold_font,
|
|
|
|
(cf.cfilter == NULL)? 0 : "-f", (cf.cfilter == NULL)? 0 : cf.cfilter,
|
|
|
|
0);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
execl(ethereal_path,"ethereal","-k","-Q","-i",cf.iface,"-w",cf.save_file,
|
|
|
|
"-c", scount, "-s", ssnap,
|
|
|
|
"-m", medium_font, "-b", bold_font,
|
|
|
|
(cf.cfilter == NULL)? 0 : "-f", (cf.cfilter == NULL)? 0 : cf.cfilter,
|
|
|
|
0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
cf.filename = cf.save_file;
|
|
|
|
if (sync_mode) {
|
|
|
|
close(sync_pipe[1]);
|
|
|
|
while (!sigusr2_received) {
|
|
|
|
struct timeval timeout = {1,0};
|
|
|
|
select(0, NULL, NULL, NULL, &timeout);
|
|
|
|
if (kill(fork_child, 0) == -1 && errno == ESRCH)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (sigusr2_received)
|
|
|
|
tail_cap_file(cf.save_file, &cf);
|
|
|
|
sigusr2_received = FALSE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
capture();
|
1998-09-16 02:39:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
capture_prep_close_cb(GtkWidget *w, gpointer win) {
|
|
|
|
|
1998-12-22 07:07:11 +00:00
|
|
|
#ifdef GTK_HAVE_FEATURES_1_1_0
|
|
|
|
win = w;
|
|
|
|
#endif
|
1998-09-16 02:39:15 +00:00
|
|
|
gtk_grab_remove(GTK_WIDGET(win));
|
|
|
|
gtk_widget_destroy(GTK_WIDGET(win));
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
1999-04-06 16:24:50 +00:00
|
|
|
capture(void) {
|
1998-09-29 21:39:29 +00:00
|
|
|
GtkWidget *cap_w, *main_vb, *count_lb, *tcp_lb, *udp_lb,
|
|
|
|
*ospf_lb, *other_lb, *stop_bt;
|
1998-09-16 02:39:15 +00:00
|
|
|
pcap_t *pch;
|
|
|
|
gchar err_str[PCAP_ERRBUF_SIZE], label_str[32];
|
|
|
|
loop_data ld;
|
|
|
|
bpf_u_int32 netnum, netmask;
|
|
|
|
time_t upd_time, cur_time;
|
|
|
|
|
1999-02-09 00:35:38 +00:00
|
|
|
ld.go = TRUE;
|
|
|
|
ld.counts.total = 0;
|
|
|
|
ld.max = cf.count;
|
|
|
|
ld.linktype = DLT_NULL;
|
1999-05-11 18:51:10 +00:00
|
|
|
ld.signal_sent = 0;
|
|
|
|
ld.sync_time = 0;
|
1999-02-09 00:35:38 +00:00
|
|
|
ld.counts.tcp = 0;
|
|
|
|
ld.counts.udp = 0;
|
|
|
|
ld.counts.ospf = 0;
|
|
|
|
ld.counts.other = 0;
|
|
|
|
ld.pdh = NULL;
|
1998-09-16 02:39:15 +00:00
|
|
|
|
|
|
|
close_cap_file(&cf, info_bar, file_ctx);
|
|
|
|
|
|
|
|
pch = pcap_open_live(cf.iface, cf.snap, 1, 250, err_str);
|
|
|
|
|
|
|
|
if (pch) {
|
1999-04-06 16:24:50 +00:00
|
|
|
ld.pdh = pcap_dump_open(pch, cf.save_file);
|
|
|
|
|
|
|
|
if (ld.pdh == NULL) { /* We have an error */
|
|
|
|
snprintf(err_str, PCAP_ERRBUF_SIZE, "Error trying to save capture to "
|
|
|
|
"file:\n%s", pcap_geterr(pch));
|
|
|
|
simple_dialog(ESD_TYPE_WARN, NULL, err_str);
|
|
|
|
pcap_close(pch);
|
|
|
|
return;
|
1998-09-16 02:39:15 +00:00
|
|
|
}
|
1999-05-11 18:51:10 +00:00
|
|
|
|
1999-02-09 00:35:38 +00:00
|
|
|
ld.linktype = pcap_datalink(pch);
|
1998-09-16 02:39:15 +00:00
|
|
|
|
1998-10-12 01:40:57 +00:00
|
|
|
if (cf.cfilter) {
|
1998-09-16 02:39:15 +00:00
|
|
|
if (pcap_lookupnet (cf.iface, &netnum, &netmask, err_str) < 0) {
|
|
|
|
simple_dialog(ESD_TYPE_WARN, NULL,
|
|
|
|
"Can't use filter: Couldn't obtain netmask info.");
|
|
|
|
return;
|
1998-10-12 01:40:57 +00:00
|
|
|
} else if (pcap_compile(pch, &cf.fcode, cf.cfilter, 1, netmask) < 0) {
|
1998-09-16 02:39:15 +00:00
|
|
|
simple_dialog(ESD_TYPE_WARN, NULL, "Unable to parse filter string.");
|
|
|
|
return;
|
|
|
|
} else if (pcap_setfilter(pch, &cf.fcode) < 0) {
|
|
|
|
simple_dialog(ESD_TYPE_WARN, NULL, "Can't install filter.");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
cap_w = gtk_window_new(GTK_WINDOW_TOPLEVEL);
|
|
|
|
gtk_window_set_title(GTK_WINDOW(cap_w), "Ethereal: Capture / Playback");
|
|
|
|
|
|
|
|
/* Container for capture display widgets */
|
|
|
|
main_vb = gtk_vbox_new(FALSE, 1);
|
|
|
|
gtk_container_border_width(GTK_CONTAINER(main_vb), 5);
|
|
|
|
gtk_container_add(GTK_CONTAINER(cap_w), main_vb);
|
|
|
|
gtk_widget_show(main_vb);
|
|
|
|
|
|
|
|
count_lb = gtk_label_new("Count: 0");
|
|
|
|
gtk_box_pack_start(GTK_BOX(main_vb), count_lb, FALSE, FALSE, 3);
|
|
|
|
gtk_widget_show(count_lb);
|
|
|
|
|
|
|
|
tcp_lb = gtk_label_new("TCP: 0 (0.0%)");
|
|
|
|
gtk_box_pack_start(GTK_BOX(main_vb), tcp_lb, FALSE, FALSE, 3);
|
|
|
|
gtk_widget_show(tcp_lb);
|
|
|
|
|
|
|
|
udp_lb = gtk_label_new("UDP: 0 (0.0%)");
|
|
|
|
gtk_box_pack_start(GTK_BOX(main_vb), udp_lb, FALSE, FALSE, 3);
|
|
|
|
gtk_widget_show(udp_lb);
|
|
|
|
|
1998-09-29 21:39:29 +00:00
|
|
|
ospf_lb = gtk_label_new("OSPF: 0 (0.0%)");
|
|
|
|
gtk_box_pack_start(GTK_BOX(main_vb), ospf_lb, FALSE, FALSE, 3);
|
|
|
|
gtk_widget_show(ospf_lb);
|
|
|
|
|
1998-09-16 02:39:15 +00:00
|
|
|
other_lb = gtk_label_new("Other: 0 (0.0%)");
|
|
|
|
gtk_box_pack_start(GTK_BOX(main_vb), other_lb, FALSE, FALSE, 3);
|
|
|
|
gtk_widget_show(other_lb);
|
|
|
|
|
|
|
|
stop_bt = gtk_button_new_with_label ("Stop");
|
|
|
|
gtk_signal_connect(GTK_OBJECT(stop_bt), "clicked",
|
|
|
|
GTK_SIGNAL_FUNC(capture_stop_cb), (gpointer) &ld);
|
|
|
|
gtk_box_pack_end(GTK_BOX(main_vb), stop_bt, FALSE, FALSE, 3);
|
|
|
|
GTK_WIDGET_SET_FLAGS(stop_bt, GTK_CAN_DEFAULT);
|
|
|
|
gtk_widget_grab_default(stop_bt);
|
|
|
|
GTK_WIDGET_SET_FLAGS(stop_bt, GTK_CAN_DEFAULT);
|
|
|
|
gtk_widget_grab_default(stop_bt);
|
|
|
|
gtk_widget_show(stop_bt);
|
|
|
|
|
|
|
|
gtk_widget_show(cap_w);
|
|
|
|
gtk_grab_add(cap_w);
|
|
|
|
|
|
|
|
upd_time = time(NULL);
|
|
|
|
while (ld.go) {
|
|
|
|
while (gtk_events_pending()) gtk_main_iteration();
|
|
|
|
pcap_dispatch(pch, 1, capture_pcap_cb, (u_char *) &ld);
|
1998-09-29 21:39:29 +00:00
|
|
|
|
1998-09-16 02:39:15 +00:00
|
|
|
/* Only update once a second so as not to overload slow displays */
|
|
|
|
cur_time = time(NULL);
|
|
|
|
if (cur_time > upd_time) {
|
1998-09-29 21:39:29 +00:00
|
|
|
|
1998-09-16 02:39:15 +00:00
|
|
|
upd_time = cur_time;
|
1998-09-29 21:39:29 +00:00
|
|
|
|
1999-02-09 00:35:38 +00:00
|
|
|
sprintf(label_str, "Count: %d", ld.counts.total);
|
1998-09-16 02:39:15 +00:00
|
|
|
gtk_label_set(GTK_LABEL(count_lb), label_str);
|
1998-09-29 21:39:29 +00:00
|
|
|
|
1999-02-09 00:35:38 +00:00
|
|
|
sprintf(label_str, "TCP: %d (%.1f%%)", ld.counts.tcp,
|
|
|
|
pct(ld.counts.tcp, ld.counts.total));
|
1998-09-16 02:39:15 +00:00
|
|
|
gtk_label_set(GTK_LABEL(tcp_lb), label_str);
|
1998-09-29 21:39:29 +00:00
|
|
|
|
1999-02-09 00:35:38 +00:00
|
|
|
sprintf(label_str, "UDP: %d (%.1f%%)", ld.counts.udp,
|
|
|
|
pct(ld.counts.udp, ld.counts.total));
|
1998-09-16 02:39:15 +00:00
|
|
|
gtk_label_set(GTK_LABEL(udp_lb), label_str);
|
1998-09-29 21:39:29 +00:00
|
|
|
|
1999-02-09 00:35:38 +00:00
|
|
|
sprintf(label_str, "OSPF: %d (%.1f%%)", ld.counts.ospf,
|
|
|
|
pct(ld.counts.ospf, ld.counts.total));
|
1998-09-29 21:39:29 +00:00
|
|
|
gtk_label_set(GTK_LABEL(ospf_lb), label_str);
|
|
|
|
|
1999-02-09 00:35:38 +00:00
|
|
|
sprintf(label_str, "Other: %d (%.1f%%)", ld.counts.other,
|
|
|
|
pct(ld.counts.other, ld.counts.total));
|
1998-09-16 02:39:15 +00:00
|
|
|
gtk_label_set(GTK_LABEL(other_lb), label_str);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (ld.pdh) pcap_dump_close(ld.pdh);
|
|
|
|
pcap_close(pch);
|
|
|
|
|
|
|
|
gtk_grab_remove(GTK_WIDGET(cap_w));
|
|
|
|
gtk_widget_destroy(GTK_WIDGET(cap_w));
|
|
|
|
} else {
|
|
|
|
while (gtk_events_pending()) gtk_main_iteration();
|
|
|
|
simple_dialog(ESD_TYPE_WARN, NULL,
|
|
|
|
"The capture session could not be initiated. Please\n"
|
|
|
|
"check to make sure you have sufficient permissions, and\n"
|
|
|
|
"that you have the proper interface specified.");
|
|
|
|
}
|
|
|
|
|
1999-05-11 18:51:10 +00:00
|
|
|
if( quit_after_cap ){
|
|
|
|
/* DON'T unlink the save file. Presumably someone wants it. */
|
|
|
|
gtk_exit(0);
|
|
|
|
}
|
|
|
|
|
1999-04-06 16:24:50 +00:00
|
|
|
if (cf.save_file) load_cap_file(cf.save_file, &cf);
|
|
|
|
#ifdef USE_ITEM
|
|
|
|
set_menu_sensitivity("/File/Save", TRUE);
|
|
|
|
set_menu_sensitivity("/File/Save as", FALSE);
|
|
|
|
#else
|
|
|
|
set_menu_sensitivity("<Main>/File/Save", TRUE);
|
|
|
|
set_menu_sensitivity("<Main>/File/Save as", FALSE);
|
|
|
|
#endif
|
1998-09-16 02:39:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
float
|
|
|
|
pct(gint num, gint denom) {
|
|
|
|
if (denom) {
|
|
|
|
return (float) num * 100.0 / (float) denom;
|
|
|
|
} else {
|
|
|
|
return 0.0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
capture_stop_cb(GtkWidget *w, gpointer data) {
|
|
|
|
loop_data *ld = (loop_data *) data;
|
|
|
|
|
|
|
|
ld->go = FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
capture_pcap_cb(u_char *user, const struct pcap_pkthdr *phdr,
|
|
|
|
const u_char *pd) {
|
|
|
|
|
|
|
|
loop_data *ld = (loop_data *) user;
|
1999-05-11 18:51:10 +00:00
|
|
|
time_t *sync_time= &ld->sync_time, cur_time;
|
1998-09-16 02:39:15 +00:00
|
|
|
|
1999-02-09 00:35:38 +00:00
|
|
|
if ((++ld->counts.total >= ld->max) && (ld->max > 0))
|
1998-09-29 21:39:29 +00:00
|
|
|
{
|
|
|
|
ld->go = FALSE;
|
|
|
|
}
|
1998-09-16 02:39:15 +00:00
|
|
|
/* Currently, pcap_dumper_t is a FILE *. Let's hope that doesn't change. */
|
|
|
|
if (ld->pdh) pcap_dump((u_char *) ld->pdh, phdr, pd);
|
|
|
|
|
1999-05-11 18:51:10 +00:00
|
|
|
cur_time = time(NULL);
|
|
|
|
if (cur_time > *sync_time) {
|
|
|
|
/* sync every seconds */
|
|
|
|
*sync_time = cur_time;
|
|
|
|
fflush((FILE *)ld->pdh);
|
|
|
|
if (sync_mode)
|
|
|
|
write(1, "D", 1);
|
|
|
|
}
|
|
|
|
|
1999-02-09 00:35:38 +00:00
|
|
|
switch (ld->linktype) {
|
|
|
|
case DLT_EN10MB :
|
|
|
|
capture_eth(pd, phdr->caplen, &ld->counts);
|
|
|
|
break;
|
|
|
|
case DLT_FDDI :
|
|
|
|
capture_fddi(pd, phdr->caplen, &ld->counts);
|
|
|
|
break;
|
|
|
|
case DLT_IEEE802 :
|
|
|
|
capture_tr(pd, phdr->caplen, &ld->counts);
|
|
|
|
break;
|
|
|
|
case DLT_NULL :
|
|
|
|
capture_null(pd, phdr->caplen, &ld->counts);
|
|
|
|
break;
|
|
|
|
case DLT_PPP :
|
|
|
|
capture_ppp(pd, phdr->caplen, &ld->counts);
|
|
|
|
break;
|
|
|
|
case DLT_RAW :
|
|
|
|
capture_raw(pd, phdr->caplen, &ld->counts);
|
|
|
|
break;
|
1998-09-16 02:39:15 +00:00
|
|
|
}
|
1999-05-11 18:51:10 +00:00
|
|
|
|
|
|
|
if (sync_mode && !ld->signal_sent) {
|
|
|
|
/* will trigger the father to open the cap file which contains
|
|
|
|
at least one complete packet */
|
|
|
|
fflush((FILE *)ld->pdh);
|
|
|
|
kill(getppid(), SIGUSR2);
|
|
|
|
ld->signal_sent = 1;
|
|
|
|
}
|
|
|
|
|
1998-09-16 02:39:15 +00:00
|
|
|
}
|