summaryrefslogtreecommitdiff
path: root/dumpcap.c
diff options
context:
space:
mode:
authorRoland Knall <roland.knall@br-automation.com>2016-01-04 18:32:39 +0100
committerAnders Broman <a.broman58@gmail.com>2016-07-30 21:15:39 +0000
commitc611eded2272ac79997fb3ce11f2339dc32b53cb (patch)
tree48d73f9ed21c55448ae77fae24020cf4763da2c7 /dumpcap.c
parentc2ac9c5c0316a27f54830fae0b70cf7825c6d99c (diff)
downloadwireshark-c611eded2272ac79997fb3ce11f2339dc32b53cb.tar.gz
extcap: Use stderr to print error message
This patch reads out the stderr messages from an extcap utility and displays it to an user. It was tested on Qt but not on GTK, but should work their as well. On Mac OS/X and Windows the child_watch does not behave as it was intended. Therefore in extcap_cleanup, the callbacks are called manually, if and only if, they have not been called already. The reason why it displays two error messages is, that by the time the first one is being displayed, glib has not returned from the spawned process on Linux yet. So there is no way to add the stderr correctly, and putting a handler to stderr into interface_opts will lead to memory errors, cause then the code tries to access memory outside of its protection. Bug: 11892 Change-Id: I2db60dd480fed3e01428b91a705057e4f088bd15 Reviewed-on: https://code.wireshark.org/review/12954 Reviewed-by: Roland Knall <rknall@gmail.com> Petri-Dish: Roland Knall <rknall@gmail.com> Tested-by: Petri Dish Buildbot <buildbot-no-reply@wireshark.org> Reviewed-by: Dario Lombardo <lomato@gmail.com> Reviewed-by: Anders Broman <a.broman58@gmail.com>
Diffstat (limited to 'dumpcap.c')
-rw-r--r--dumpcap.c25
1 files changed, 21 insertions, 4 deletions
diff --git a/dumpcap.c b/dumpcap.c
index 3d736ebfc0..935e52d9ca 100644
--- a/dumpcap.c
+++ b/dumpcap.c
@@ -1466,12 +1466,14 @@ cap_pipe_open_live(char *pipename,
#else /* _WIN32 */
char *pncopy, *pos;
wchar_t *err_str;
- interface_options interface_opts;
#ifdef HAVE_EXTCAP
char* extcap_pipe_name;
- gboolean extcap_pipe;
#endif
#endif
+#ifdef HAVE_EXTCAP
+ gboolean extcap_pipe = FALSE;
+#endif
+ interface_options interface_opts;
ssize_t b;
int fd = -1, sel_ret;
size_t bytes_read;
@@ -1498,7 +1500,15 @@ cap_pipe_open_live(char *pipename,
return;
}
} else {
+
+ interface_opts = g_array_index(global_capture_opts.ifaces, interface_options, 0);
+
#ifndef _WIN32
+#ifdef HAVE_EXTCAP
+ if ( g_strrstr(interface_opts.name, EXTCAP_PIPE_PREFIX) != NULL )
+ extcap_pipe = TRUE;
+#endif
+
if (ws_stat64(pipename, &pipe_stat) < 0) {
if (errno == ENOENT || errno == ENOTDIR)
pcap_opts->cap_pipe_err = PIPNEXIST;
@@ -1585,6 +1595,7 @@ cap_pipe_open_live(char *pipename,
}
return;
}
+
#else /* _WIN32 */
#define PIPE_STR "\\pipe\\"
/* Under Windows, named pipes _must_ have the form
@@ -1606,8 +1617,6 @@ cap_pipe_open_live(char *pipename,
pcap_opts->cap_pipe_err = PIPNEXIST;
return;
}
-
- interface_opts = g_array_index(global_capture_opts.ifaces, interface_options, 0);
#ifdef HAVE_EXTCAP
extcap_pipe_name = g_strconcat("\\\\.\\pipe\\", EXTCAP_PIPE_PREFIX, NULL);
extcap_pipe = strstr(interface_opts.name, extcap_pipe_name) ? TRUE : FALSE;
@@ -1678,6 +1687,10 @@ cap_pipe_open_live(char *pipename,
b = cap_pipe_read(fd, ((char *)&magic)+bytes_read,
sizeof magic-bytes_read,
pcap_opts->from_cap_socket);
+ /* jump messaging, if extcap had an error, stderr will provide the correct message */
+ if (extcap_pipe && b <= 0)
+ goto error;
+
if (b <= 0) {
if (b == 0)
g_snprintf(errmsg, errmsgl, "End of file on pipe magic during open.");
@@ -1704,6 +1717,10 @@ cap_pipe_open_live(char *pipename,
/* We don't have to worry about cap_pipe_read_mtx here */
g_async_queue_push(pcap_opts->cap_pipe_pending_q, pcap_opts->cap_pipe_buf);
g_async_queue_pop(pcap_opts->cap_pipe_done_q);
+ /* jump messaging, if extcap had an error, stderr will provide the correct message */
+ if (pcap_opts->cap_pipe_bytes_read <= 0 && extcap_pipe)
+ goto error;
+
if (pcap_opts->cap_pipe_bytes_read <= 0) {
if (pcap_opts->cap_pipe_bytes_read == 0)
g_snprintf(errmsg, errmsgl, "End of file on pipe magic during open.");