argv = sync_pipe_add_arg(argv, &argc, "-i");
if (interface_opts->extcap_fifo != NULL)
+ {
+#ifdef _WIN32
+ char *pipe = g_strdup_printf("%s%" G_GUINTPTR_FORMAT, EXTCAP_PIPE_PREFIX, interface_opts->extcap_pipe_h);
+ argv = sync_pipe_add_arg(argv, &argc, pipe);
+ g_free(pipe);
+#else
argv = sync_pipe_add_arg(argv, &argc, interface_opts->extcap_fifo);
+#endif
+ }
else
argv = sync_pipe_add_arg(argv, &argc, interface_opts->name);
#else
si.dwFlags = STARTF_USESTDHANDLES|STARTF_USESHOWWINDOW;
si.wShowWindow = SW_HIDE; /* this hides the console window */
- if(interface_opts->extcap_pipe_h != INVALID_HANDLE_VALUE)
- si.hStdInput = interface_opts->extcap_pipe_h;
- else
- si.hStdInput = GetStdHandle(STD_INPUT_HANDLE);
-
+ si.hStdInput = GetStdHandle(STD_INPUT_HANDLE);
si.hStdOutput = GetStdHandle(STD_OUTPUT_HANDLE);
si.hStdError = sync_pipe_write;
/*si.hStdError = (HANDLE) _get_osfhandle(2);*/
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;
}
#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 */