aboutsummaryrefslogtreecommitdiffstats
path: root/dumpcap.c
diff options
context:
space:
mode:
Diffstat (limited to 'dumpcap.c')
-rw-r--r--dumpcap.c94
1 files changed, 50 insertions, 44 deletions
diff --git a/dumpcap.c b/dumpcap.c
index fa20b402b8..367a71ff8f 100644
--- a/dumpcap.c
+++ b/dumpcap.c
@@ -1561,7 +1561,7 @@ cap_pipe_open_live(char *pipename,
struct sockaddr_un sa;
#else /* _WIN32 */
char *pncopy, *pos;
- char* extcap_pipe_name;
+ guintptr extcap_pipe_handle;
#endif
gboolean extcap_pipe = FALSE;
ssize_t b;
@@ -1682,57 +1682,63 @@ cap_pipe_open_live(char *pipename,
}
#else /* _WIN32 */
-#define PIPE_STR "\\pipe\\"
- /* Under Windows, named pipes _must_ have the form
- * "\\<server>\pipe\<pipename>". <server> may be "." for localhost.
- */
- pncopy = g_strdup(pipename);
- if ( (pos=strstr(pncopy, "\\\\")) == pncopy) {
- pos = strchr(pncopy + 3, '\\');
- if (pos && g_ascii_strncasecmp(pos, PIPE_STR, strlen(PIPE_STR)) != 0)
- pos = NULL;
+ if (sscanf(pipename, EXTCAP_PIPE_PREFIX "%" G_GUINTPTR_FORMAT, &extcap_pipe_handle) == 1)
+ {
+ /* The client is already connected to extcap pipe.
+ * We have inherited the handle from parent process.
+ */
+ extcap_pipe = TRUE;
+ pcap_src->cap_pipe_h = (HANDLE)extcap_pipe_handle;
}
+ else
+ {
+#define PIPE_STR "\\pipe\\"
+ /* Under Windows, named pipes _must_ have the form
+ * "\\<server>\pipe\<pipename>". <server> may be "." for localhost.
+ */
+ pncopy = g_strdup(pipename);
+ if ((pos = strstr(pncopy, "\\\\")) == pncopy) {
+ pos = strchr(pncopy + 3, '\\');
+ if (pos && g_ascii_strncasecmp(pos, PIPE_STR, strlen(PIPE_STR)) != 0)
+ pos = NULL;
+ }
- g_free(pncopy);
+ g_free(pncopy);
- if (!pos) {
- g_snprintf(errmsg, (gulong)errmsgl,
- "The capture session could not be initiated because\n"
- "\"%s\" is neither an interface nor a pipe.", pipename);
- pcap_src->cap_pipe_err = PIPNEXIST;
- return;
- }
- extcap_pipe_name = g_strconcat("\\\\.\\pipe\\", EXTCAP_PIPE_PREFIX, NULL);
- extcap_pipe = strstr(pipename, extcap_pipe_name) ? TRUE : FALSE;
- g_free(extcap_pipe_name);
+ if (!pos) {
+ g_snprintf(errmsg, (gulong)errmsgl,
+ "The capture session could not be initiated because\n"
+ "\"%s\" is neither an interface nor a pipe.", pipename);
+ pcap_src->cap_pipe_err = PIPNEXIST;
+ return;
+ }
- /* Wait for the pipe to appear */
- while (1) {
- if(extcap_pipe)
- pcap_src->cap_pipe_h = GetStdHandle(STD_INPUT_HANDLE);
- else
+
+ /* Wait for the pipe to appear */
+ while (1) {
pcap_src->cap_pipe_h = CreateFile(utf_8to16(pipename), GENERIC_READ, 0, NULL,
- OPEN_EXISTING, 0, NULL);
+ OPEN_EXISTING, 0, NULL);
- if (pcap_src->cap_pipe_h != INVALID_HANDLE_VALUE)
- break;
+ if (pcap_src->cap_pipe_h != INVALID_HANDLE_VALUE)
+ break;
- if (GetLastError() != ERROR_PIPE_BUSY) {
- g_snprintf(errmsg, (gulong)errmsgl,
- "The capture session on \"%s\" could not be started "
- "due to error on pipe open: %s.",
- pipename, win32strerror(GetLastError()));
- pcap_src->cap_pipe_err = PIPERR;
- return;
- }
+ if (GetLastError() != ERROR_PIPE_BUSY) {
+ g_snprintf(errmsg, (gulong)errmsgl,
+ "The capture session on \"%s\" could not be started "
+ "due to error on pipe open: %s.",
+ pipename, win32strerror(GetLastError()));
+ pcap_src->cap_pipe_err = PIPERR;
+ return;
+ }
- if (!WaitNamedPipe(utf_8to16(pipename), 30 * 1000)) {
- g_snprintf(errmsg, (gulong)errmsgl,
- "The capture session on \"%s\" timed out during "
- "pipe open: %s.",
- pipename, win32strerror(GetLastError()));
- pcap_src->cap_pipe_err = PIPERR;
- return;
+ if (!WaitNamedPipe(utf_8to16(pipename), 30 * 1000)) {
+ g_snprintf(errmsg, (gulong)errmsgl,
+ "The capture session on \"%s\" timed out during "
+ "pipe open: %s.",
+ pipename, win32strerror(GetLastError()));
+ pcap_src->cap_pipe_err = PIPERR;
+ return;
+ }
}
}
#endif /* _WIN32 */