-/* Size of buffer to hold decimal representation of
- signed/unsigned 64-bit int */
-#define SP_DECISIZE 20
-
-/*
- * Indications sent out on the sync pipe.
- */
-#define SP_FILE 'F' /* the name of the recently opened file */
-#define SP_ERROR_MSG 'E' /* error message */
-#define SP_PACKET_COUNT 'P' /* count of packets captured since last message */
-#define SP_DROPS 'D' /* count of packets dropped in capture */
-#define SP_QUIT 'Q' /* capture quit message (from parent to child) */
-
-
-/* write a message to the recipient pipe in the standard format
- (3 digit message length (excluding length and indicator field),
- 1 byte message indicator and the rest is the message) */
-static void
-pipe_write_block(int pipe, char indicator, int len, const char *msg)
-{
- char lenbuf[3+1+1]; /* 3 digit len + indicator + zero terminator */
- int ret;
-
- /*g_warning("write %d enter", pipe);*/
-
- g_assert(len < 1000);
- g_assert(indicator < '0' || indicator > '9');
-
- /* write header (3 digit len + indicator) */
- g_snprintf(lenbuf, 5, "%03u%c", len, indicator);
-
- ret = write(pipe, lenbuf, strlen(lenbuf));
- if(ret == -1) {
- return;
- }
-
- /* write value (if we have one) */
- if(len) {
- /*g_warning("write %d indicator: %c value len: %u msg: %s", pipe, indicator, len, msg);*/
- ret = write(pipe, msg, len);
- if(ret == -1) {
- return;
- }
- } else {
- /*g_warning("write %d indicator: %c no value", pipe, indicator);*/
- }
-
- /*g_warning("write %d leave", pipe);*/
-}
-
-
-/* read a message from the sending pipe in the standard format
- (3 digit message length (excluding length and indicator field),
- 1 byte message indicator and the rest is the message) */
-static int
-pipe_read_block(int pipe, char *indicator, int len, char *msg) {
- int required;
- int newly;
- char header[4];
- int offset;
-
-
- /* read header (3 digit len and indicator) */
- required = 4;
- offset = 0;
- while(required) {
- newly = read(pipe, &header[offset], required);
- if (newly == 0) {
- /* EOF */
- /*g_warning("read %d header empty (capture closed)", pipe);*/
- return newly;
- }
- if (newly < 0) {
- /* error */
- /*g_warning("read %d header error: %s", pipe, strerror(errno));*/
- return newly;
- }
-
- required -= newly;
- offset += newly;
- }
-
- /* convert header values */
- *indicator = header[3];
- required = atoi(header);
-
- /* only indicator with no value? */
- if(required == 0) {
- /*g_warning("read %d indicator: %c empty value", pipe, *indicator);*/
- return 4;
- }
-
- g_assert(required <= len);
- len = required;
-
- /* read value */
- offset = 0;
- while(required) {
- newly = read(pipe, &msg[offset], required);
- if (newly == -1) {
- /* error */
- /*g_warning("read %d value error, indicator: %u", pipe, *indicator);*/
- return newly;
- }
-
- required -= newly;
- offset += newly;
- }
-
- /*g_warning("read %d ok indicator: %c len: %u msg: %s", pipe, *indicator, len, msg);*/
- return len + 4;
-}
-
-void
-sync_pipe_packet_count_to_parent(int packet_count)
-{
- char tmp[SP_DECISIZE+1+1];
-
- g_snprintf(tmp, sizeof(tmp), "%d", packet_count);
-
- g_log(LOG_DOMAIN_CAPTURE_CHILD, G_LOG_LEVEL_DEBUG, "sync_pipe_packet_count_to_parent: %s", tmp);
-
- pipe_write_block(1, SP_PACKET_COUNT, strlen(tmp)+1, tmp);
-}
-
-void
-sync_pipe_filename_to_parent(const char *filename)
-{
- g_log(LOG_DOMAIN_CAPTURE_CHILD, G_LOG_LEVEL_DEBUG, "sync_pipe_filename_to_parent: %s", filename);
-
- pipe_write_block(1, SP_FILE, strlen(filename)+1, filename);
-}
-
-void
-sync_pipe_errmsg_to_parent(const char *errmsg)
-{
- g_log(LOG_DOMAIN_CAPTURE_CHILD, G_LOG_LEVEL_DEBUG, "sync_pipe_errmsg_to_parent: %s", errmsg);
-
- pipe_write_block(1, SP_ERROR_MSG, strlen(errmsg)+1, errmsg);
-}
-
-void
-sync_pipe_drops_to_parent(int drops)
-{
- char tmp[SP_DECISIZE+1+1];
-
-
- g_snprintf(tmp, sizeof(tmp), "%d", drops);
-
- g_log(LOG_DOMAIN_CAPTURE_CHILD, G_LOG_LEVEL_DEBUG, "sync_pipe_drops_to_parent: %s", tmp);
-
- pipe_write_block(1, SP_DROPS, strlen(tmp)+1, tmp);
-}
-
-
-#ifdef _WIN32
-
-static void
-signal_pipe_capquit_to_child(capture_options *capture_opts)
-{