Make the "-Z" argument to dumpcap take an argument that's the file

descriptor to use as the sync pipe.  For now, always pass 1, so the sync
pipe is the standard output of dumpcap.

svn path=/trunk/; revision=23025
This commit is contained in:
Guy Harris 2007-09-29 01:36:03 +00:00
parent 6d065e2eb2
commit 322d44d416
2 changed files with 14 additions and 7 deletions

View File

@ -354,6 +354,7 @@ sync_pipe_start(capture_options *capture_opts) {
/* dumpcap should be running in capture child mode (hidden feature) */
#ifndef DEBUG_CHILD
argv = sync_pipe_add_arg(argv, &argc, "-Z");
argv = sync_pipe_add_arg(argv, &argc, "1");
#endif
#ifdef _WIN32
@ -804,6 +805,7 @@ sync_interface_list_open(gchar **msg) {
/* dumpcap should be running in capture child mode (hidden feature) */
#ifndef DEBUG_CHILD
argv = sync_pipe_add_arg(argv, &argc, "-Z");
argv = sync_pipe_add_arg(argv, &argc, "1");
#endif
return sync_pipe_run_command(argv, msg);
@ -843,6 +845,7 @@ sync_linktype_list_open(gchar *ifname, gchar **msg) {
/* dumpcap should be running in capture child mode (hidden feature) */
#ifndef DEBUG_CHILD
argv = sync_pipe_add_arg(argv, &argc, "-Z");
argv = sync_pipe_add_arg(argv, &argc, "1");
#endif
return sync_pipe_run_command(argv, msg);
@ -880,6 +883,7 @@ sync_interface_stats_open(int *read_fd, int *fork_child, gchar **msg) {
/* dumpcap should be running in capture child mode (hidden feature) */
#ifndef DEBUG_CHILD
argv = sync_pipe_add_arg(argv, &argc, "-Z");
argv = sync_pipe_add_arg(argv, &argc, "1");
#endif
return sync_pipe_open_command(argv, read_fd, fork_child, msg);

View File

@ -85,6 +85,8 @@ void exit_main(int err) __attribute__ ((noreturn));
void exit_main(int err);
#endif
/* Sync pipe file descriptor. */
static int sync_pipe_fd;
static void
print_usage(gboolean print_ver) {
@ -253,7 +255,7 @@ main(int argc, char *argv[])
gboolean print_statistics = FALSE;
int status, run_once_args = 0;
#define OPTSTRING_INIT "a:b:c:Df:hi:LMpSs:vw:y:Z"
#define OPTSTRING_INIT "a:b:c:Df:hi:LMpSs:vw:y:Z:"
#ifdef _WIN32
#define OPTSTRING_WIN32 "B:"
@ -362,9 +364,10 @@ main(int argc, char *argv[])
/*** hidden option: Wireshark child mode (using binary output messages) ***/
case 'Z':
capture_child = TRUE;
sync_pipe_fd = get_positive_int(optarg, "sync pipe file descriptor");
#ifdef _WIN32
/* set output pipe to binary mode, to avoid ugly text conversions */
_setmode(1, O_BINARY);
_setmode(sync_pipe_fd, O_BINARY);
#endif
break;
@ -554,7 +557,7 @@ report_packet_count(int packet_count)
if(capture_child) {
g_snprintf(tmp, sizeof(tmp), "%d", packet_count);
g_log(LOG_DOMAIN_CAPTURE_CHILD, G_LOG_LEVEL_DEBUG, "Packets: %s", tmp);
pipe_write_block(1, SP_PACKET_COUNT, tmp);
pipe_write_block(sync_pipe_fd, SP_PACKET_COUNT, tmp);
} else {
count += packet_count;
fprintf(stderr, "\rPackets: %u ", count);
@ -568,7 +571,7 @@ report_new_capture_file(const char *filename)
{
if(capture_child) {
g_log(LOG_DOMAIN_CAPTURE_CHILD, G_LOG_LEVEL_DEBUG, "File: %s", filename);
pipe_write_block(1, SP_FILE, filename);
pipe_write_block(sync_pipe_fd, SP_FILE, filename);
} else {
fprintf(stderr, "File: %s\n", filename);
/* stderr could be line buffered */
@ -581,7 +584,7 @@ report_cfilter_error(const char *cfilter, const char *errmsg)
{
if (capture_child) {
g_log(LOG_DOMAIN_CAPTURE_CHILD, G_LOG_LEVEL_DEBUG, "Capture filter error: %s", errmsg);
pipe_write_block(1, SP_BAD_FILTER, errmsg);
pipe_write_block(sync_pipe_fd, SP_BAD_FILTER, errmsg);
} else {
fprintf(stderr,
"Invalid capture filter: \"%s\"!\n"
@ -600,7 +603,7 @@ report_capture_error(const char *error_msg, const char *secondary_error_msg)
"Primary Error: %s", error_msg);
g_log(LOG_DOMAIN_CAPTURE_CHILD, G_LOG_LEVEL_DEBUG,
"Secondary Error: %s", secondary_error_msg);
sync_pipe_errmsg_to_parent(1, error_msg, secondary_error_msg);
sync_pipe_errmsg_to_parent(sync_pipe_fd, error_msg, secondary_error_msg);
} else {
fprintf(stderr, "%s\n%s\n", error_msg, secondary_error_msg);
}
@ -615,7 +618,7 @@ report_packet_drops(int drops)
if(capture_child) {
g_log(LOG_DOMAIN_CAPTURE_CHILD, G_LOG_LEVEL_DEBUG, "Packets dropped: %s", tmp);
pipe_write_block(1, SP_DROPS, tmp);
pipe_write_block(sync_pipe_fd, SP_DROPS, tmp);
} else {
fprintf(stderr, "Packets dropped: %s\n", tmp);
/* stderr could be line buffered */