diff options
author | Guy Harris <guy@alum.mit.edu> | 2002-01-03 22:03:24 +0000 |
---|---|---|
committer | Guy Harris <guy@alum.mit.edu> | 2002-01-03 22:03:24 +0000 |
commit | b1f4093d1a9b94a5eab7d78e59c1ea27ab388234 (patch) | |
tree | 04392a3df5637d3f8de4eb62c3270de49013dc5f /capture.c | |
parent | 98b2ecb30478f423a7d7157ff247003095a8a1bd (diff) | |
download | wireshark-b1f4093d1a9b94a5eab7d78e59c1ea27ab388234.tar.gz wireshark-b1f4093d1a9b94a5eab7d78e59c1ea27ab388234.tar.bz2 wireshark-b1f4093d1a9b94a5eab7d78e59c1ea27ab388234.zip |
Make the "go" member of the "loop_data" structure in Ethereal a
"gboolean", as it's a Boolean value, and move it to the beginning of the
structure in Tethereal, as it is in Ethereal.
From Graeme Hewson:
Check for "pcap_dispatch()" returning -1, meaning an error
occurred; if it does, stop capturing, and report the error.
If we get a signal in tethereal, stop the capture with a
"longjmp()", rather than by clearning the "go" flag;
"pcap_dispatch()", on many platforms, keeps reading rather than
returning a captured packet count of 0 if the system call to
read packets returns -1 with an errno of EINTR, so the
"pcap_dispatch()" won't be broken out of if the signal handler
returns.
Fix a typo in an error message.
svn path=/trunk/; revision=4471
Diffstat (limited to 'capture.c')
-rw-r--r-- | capture.c | 28 |
1 files changed, 26 insertions, 2 deletions
@@ -1,7 +1,7 @@ /* capture.c * Routines for packet capture windows * - * $Id: capture.c,v 1.163 2001/12/04 08:25:55 guy Exp $ + * $Id: capture.c,v 1.164 2002/01/03 22:03:24 guy Exp $ * * Ethereal - Network traffic analyzer * By Gerald Combs <gerald@ethereal.com> @@ -204,11 +204,12 @@ static float pct(gint, gint); static void stop_capture(int signo); typedef struct _loop_data { - gint go; /* TRUE as long as we're supposed to keep capturing */ + gboolean go; /* TRUE as long as we're supposed to keep capturing */ gint max; /* Number of packets we're supposed to capture - 0 means infinite */ int err; /* if non-zero, error seen while capturing */ gint linktype; gint sync_packets; + gboolean pcap_err; /* TRUE if error from pcap */ gboolean from_pipe; /* TRUE if we are capturing data from a pipe */ gboolean modified; /* TRUE if data in the pipe uses modified pcap headers */ gboolean byte_swapped; /* TRUE if data in the pipe is byte swapped */ @@ -1303,6 +1304,7 @@ capture(gboolean *stats_known, struct pcap_stat *stats) ld.max = cfile.count; ld.err = 0; /* no error seen yet */ ld.linktype = WTAP_ENCAP_UNKNOWN; + ld.pcap_err = FALSE; ld.from_pipe = FALSE; ld.sync_packets = 0; ld.counts.sctp = 0; @@ -1639,10 +1641,18 @@ capture(gboolean *stats_known, struct pcap_stat *stats) * it. */ inpkts = pcap_dispatch(pch, 1, capture_pcap_cb, (u_char *) &ld); + if (inpkts < 0) { + ld.pcap_err = TRUE; + ld.go = FALSE; + } } else inpkts = 0; #else inpkts = pcap_dispatch(pch, 1, capture_pcap_cb, (u_char *) &ld); + if (inpkts < 0) { + ld.pcap_err = TRUE; + ld.go = FALSE; + } #endif } if (inpkts > 0) @@ -1704,6 +1714,20 @@ capture(gboolean *stats_known, struct pcap_stat *stats) cnd_delete(cnd_stop_capturesize); cnd_delete(cnd_stop_timeout); + if (ld.pcap_err) { + snprintf(errmsg, sizeof(errmsg), "Error while capturing packets: %s", + pcap_geterr(pch)); + if (capture_child) { + /* Tell the parent, so that they can pop up the message; + we're going to exit, so if we try to pop it up, either + it won't pop up or it'll disappear as soon as we exit. */ + send_errmsg_to_parent(errmsg); + } else { + /* Just pop up the message ourselves. */ + simple_dialog(ESD_TYPE_WARN, NULL, "%s", errmsg); + } + } + if (ld.err != 0) { get_capture_file_io_error(errmsg, sizeof(errmsg), cfile.save_file, ld.err, FALSE); |