Ethereal->Wireshark
[obnox/wireshark/wip.git] / dumpcap.c
index 1a764a514feffb20cfa962d72c9f2a65dbf32d42..e358f84432ca06ee0239bc1dac718f7e143532c8 100644 (file)
--- a/dumpcap.c
+++ b/dumpcap.c
@@ -2,8 +2,8 @@
  *
  * $Id$
  *
- * Ethereal - Network traffic analyzer
- * By Gerald Combs <gerald@ethereal.com>
+ * Wireshark - Network traffic analyzer
+ * By Gerald Combs <gerald@wireshark.org>
  * Copyright 1998 Gerald Combs
  *
  * This program is free software; you can redistribute it and/or
 #include <netdb.h>
 #endif
 
-#ifdef _WIN32 /* Needed for console I/O */
-#include <conio.h>
-#endif
-
 #include "ringbuffer.h"
 #include "clopts_common.h"
 #include "cmdarg_err.h"
 
 #ifdef _WIN32
 #include "capture-wpcap.h"
-#include "capture_wpcap_packet.h"
 #endif
 
+#include "sync_pipe.h"
+
 #include "capture.h"
 #include "capture_loop.h"
 #include "capture_sync.h"
 #include "file_util.h"
 
 
+/*#define DEBUG_DUMPCAP*/
 
-GString *comp_info_str, *runtime_info_str;
-gchar       *ethereal_path = NULL;
+gboolean capture_child = FALSE; /* FALSE: standalone call, TRUE: this is an Ethereal capture child */
 
-#ifdef _WIN32
-static gboolean has_console = TRUE;    /* TRUE if app has console */
-static void create_console(void);
-static void destroy_console(void);
-#endif
 static void
 console_log_handler(const char *log_domain, GLogLevelFlags log_level,
                    const char *message, gpointer user_data _U_);
 
+/* capture related options */
 capture_options global_capture_opts;
 capture_options *capture_opts = &global_capture_opts;
 
+#if __GNUC__ >= 2
+void exit_main(int err) __attribute__ ((noreturn));
+#else
+void exit_main(int err);
+#endif
 
 
 static void
@@ -92,9 +90,6 @@ print_usage(gboolean print_ver) {
 
   FILE *output;
 
-#ifdef _WIN32
-  create_console();
-#endif
 
   if (print_ver) {
     output = stdout;
@@ -106,17 +101,19 @@ print_usage(gboolean print_ver) {
   } else {
     output = stderr;
   }
-  fprintf(output, "\nUsage: dumpcap [option] ...\n");
+  fprintf(output, "\nUsage: dumpcap [options] ...\n");
   fprintf(output, "\n");
   fprintf(output, "Capture interface:\n");
-  fprintf(output, "  -i <interface>           name of interface (def: first none loopback)\n");
-  fprintf(output, "  -f <capture filter>      packet filter in libpcap format\n");
+  fprintf(output, "  -i <interface>           name or idx of interface (def: first none loopback)\n");
+  fprintf(output, "  -f <capture filter>      packet filter in libpcap filter syntax\n");
   fprintf(output, "  -s <snaplen>             packet snapshot length (def: 65535)\n");
   fprintf(output, "  -p                       don't capture in promiscuous mode\n");
 #ifdef _WIN32
   fprintf(output, "  -B <buffer size>         size of kernel buffer (def: 1MB)\n");
 #endif
   fprintf(output, "  -y <link type>           link layer type (def: first appropriate)\n");
+  fprintf(output, "  -D                       print list of interfaces and exit\n");
+  fprintf(output, "  -L                       print list of link-layer types of iface and exit\n");
   fprintf(output, "\n");
   fprintf(output, "Stop conditions:\n");
   fprintf(output, "  -c <packet count>        stop after n packets (def: infinite)\n");
@@ -133,7 +130,6 @@ print_usage(gboolean print_ver) {
   fprintf(output, "Miscellaneous:\n");
   fprintf(output, "  -v                       print version information and exit\n");
   fprintf(output, "  -h                       display this help and exit\n");
-  fprintf(output, "  -L                       print list of link-layer types of iface and exit\n");
   fprintf(output, "\n");
   fprintf(output, "Example: dumpcap -i eth0 -a duration:60 -w output.pcap\n");
   fprintf(output, "\"Capture network packets from interface eth0 until 60s passed into output.pcap\"\n");
@@ -142,86 +138,86 @@ print_usage(gboolean print_ver) {
 }
 
 static void
-show_version(void)
+show_version(GString *comp_info_str, GString *runtime_info_str)
 {
-#ifdef _WIN32
-  create_console();
-#endif
 
   printf(
         "Dumpcap " VERSION "%s\n"
         "\n"
-        "(C) 1998-2005 Gerald Combs <gerald@ethereal.com>\n"
-        "See http://www.ethereal.com for more information.\n"
-        "\n"
         "%s\n"
-        "\n"
-        "%s\n",
-        svnversion, comp_info_str->str, runtime_info_str->str);
+        "%s\n"
+        "%s\n"
+        "See http://www.ethereal.com for more information.\n",
+        svnversion, get_copyright_info() ,comp_info_str->str, runtime_info_str->str);
 }
 
 /*
  * Report an error in command-line arguments.
- * Creates a console on Windows.
- * XXX - pop this up in a window of some sort on UNIX+X11 if the controlling
- * terminal isn't the standard error?
  */
 void
 cmdarg_err(const char *fmt, ...)
 {
   va_list ap;
 
-#ifdef _WIN32
-  create_console();
-#endif
-  va_start(ap, fmt);
-  fprintf(stderr, "dumpcap: ");
-  vfprintf(stderr, fmt, ap);
-  fprintf(stderr, "\n");
-  va_end(ap);
+  if(capture_child) {
+    /* XXX - convert to g_log */
+  } else {
+    va_start(ap, fmt);
+    fprintf(stderr, "dumpcap: ");
+    vfprintf(stderr, fmt, ap);
+    fprintf(stderr, "\n");
+    va_end(ap);
+  }
 }
 
 /*
  * Report additional information for an error in command-line arguments.
- * Creates a console on Windows.
- * XXX - pop this up in a window of some sort on UNIX+X11 if the controlling
- * terminal isn't the standard error?
  */
 void
 cmdarg_err_cont(const char *fmt, ...)
 {
   va_list ap;
 
-#ifdef _WIN32
-  create_console();
-#endif
-  va_start(ap, fmt);
-  vfprintf(stderr, fmt, ap);
-  fprintf(stderr, "\n");
-  va_end(ap);
+  if(capture_child) {
+    /* XXX - convert to g_log */
+  } else {
+    va_start(ap, fmt);
+    vfprintf(stderr, fmt, ap);
+    fprintf(stderr, "\n");
+    va_end(ap);
+  }
 }
 
 
 #ifdef _WIN32
 BOOL WINAPI ConsoleCtrlHandlerRoutine(DWORD dwCtrlType)
 {
-    /*printf("Event: %u", dwCtrlType);*/
+    g_log(LOG_DOMAIN_CAPTURE_CHILD, G_LOG_LEVEL_INFO,
+        "Console: Ctrl+C");
+    g_log(LOG_DOMAIN_CAPTURE_CHILD, G_LOG_LEVEL_DEBUG,
+        "Console: Ctrl+C CtrlType: %u", dwCtrlType);
+
     capture_loop_stop();
 
     return TRUE;
 }
 #endif
 
-void
-exit_main(int err) {
+void exit_main(int status)
+{
 #ifdef _WIN32
   /* Shutdown windows sockets */
   WSACleanup();
 
-  destroy_console();
+  /* can be helpful for debugging */
+#ifdef DEBUG_DUMPCAP
+  printf("Press any key\n");
+  _getch();
 #endif
 
-  exit(err);
+#endif /* _WIN32 */
+
+  exit(status);
 }
 
 
@@ -232,28 +228,24 @@ main(int argc, char *argv[])
   int                  opt;
   extern char         *optarg;
   gboolean             arg_error = FALSE;
+  GString             *comp_info_str;
+  GString             *runtime_info_str;
 
 #ifdef _WIN32
   WSADATA              wsaData;
 #endif  /* _WIN32 */
 
-  int                  err;
   gboolean             start_capture = TRUE;
-  GList               *if_list;
-  if_info_t           *if_info;
-  GList               *lt_list, *lt_entry;
-  data_link_info_t    *data_link_info;
-  gchar                err_str[PCAP_ERRBUF_SIZE];
-  gchar               *cant_get_if_list_errstr;
   gboolean             stats_known;
   struct pcap_stat     stats;
   GLogLevelFlags       log_flags;
   gboolean             list_link_layer_types = FALSE;
+  int                  status;
 
-#define OPTSTRING_INIT "a:b:c:f:Hhi:Lps:vW:w:y:"
+#define OPTSTRING_INIT "a:b:c:Df:hi:Lps:vw:y:Z"
 
 #ifdef _WIN32
-#define OPTSTRING_WIN32 "B:Z:"
+#define OPTSTRING_WIN32 "B:"
 #else
 #define OPTSTRING_WIN32 ""
 #endif  /* _WIN32 */
@@ -261,19 +253,18 @@ main(int argc, char *argv[])
   char optstring[sizeof(OPTSTRING_INIT) + sizeof(OPTSTRING_WIN32) - 1] =
     OPTSTRING_INIT OPTSTRING_WIN32;
 
-  /*** create the compile and runtime version strings ***/
 #ifdef _WIN32
   /* Load wpcap if possible. Do this before collecting the run-time version information */
   load_wpcap();
 
   /* ... and also load the packet.dll from wpcap */
-  wpcap_packet_load();
+  /* XXX - currently not required, may change later. */
+  /*wpcap_packet_load();*/
 
   /* Start windows sockets */
   WSAStartup( MAKEWORD( 1, 1 ), &wsaData );
 
-
-  
+  /* Set handler for Ctrl+C key */
   SetConsoleCtrlHandler(&ConsoleCtrlHandlerRoutine, TRUE);
 #endif  /* _WIN32 */
 
@@ -286,19 +277,8 @@ main(int argc, char *argv[])
   runtime_info_str = g_string_new("Running ");
   get_runtime_version_info(runtime_info_str);
 
-  ethereal_path = argv[0];
-
-  /* Arrange that if we have no console window, and a GLib message logging
-     routine is called to log a message, we pop up a console window.
-
-     We do that by inserting our own handler for all messages logged
-     to the default domain; that handler pops up a console if necessary,
-     and then calls the default handler. */
-
-  /* We might want to have component specific log levels later ... */
-
-  /* the default_log_handler will use stdout, which makes trouble with the */
-  /* capture child, as it uses stdout for it's sync_pipe */
+  /* the default_log_handler will use stdout, which makes trouble in */
+  /* capture child mode, as it uses stdout for it's sync_pipe */
   /* so do the filtering in the console_log_handler and not here */
   log_flags = 
                    G_LOG_LEVEL_ERROR|
@@ -323,10 +303,15 @@ main(int argc, char *argv[])
             console_log_handler, NULL /* user_data */);
 
   /* Set the initial values in the capture_opts. This might be overwritten 
-     by preference settings and then again by the command line parameters. */
+     by the command line parameters. */
   capture_opts_init(capture_opts, NULL);
 
-  capture_opts->snaplen             = MIN_PACKET_SIZE;
+  /* Default to capturing the entire packet. */
+  capture_opts->snaplen             = WTAP_MAX_PACKET_SIZE;
+
+  /* We always save to a file - if no file was specified, we save to a
+     temporary file. */
+  capture_opts->saving_to_file      = TRUE;
   capture_opts->has_ring_num_files  = TRUE;
 
   /* Now get our args */
@@ -337,40 +322,47 @@ main(int argc, char *argv[])
         exit_main(0);
         break;
       case 'v':        /* Show version and exit */
-        show_version();
+        show_version(comp_info_str, runtime_info_str);
         exit_main(0);
         break;
       /*** capture option specific ***/
       case 'a':        /* autostop criteria */
       case 'b':        /* Ringbuffer option */
-      case 'c':        /* Capture xxx packets */
+      case 'c':        /* Capture x packets */
       case 'f':        /* capture filter */
-      case 'H':        /* Hide capture info dialog box */
-      case 'i':        /* Use interface xxx */
+      case 'i':        /* Use interface x */
       case 'p':        /* Don't capture in promiscuous mode */
       case 's':        /* Set the snapshot (capture) length */
-      case 'w':        /* Write to capture file xxx */
+      case 'w':        /* Write to capture file x */
       case 'y':        /* Set the pcap data link type */
 #ifdef _WIN32
       case 'B':        /* Buffer size */
-      /* Hidden option supporting Sync mode */
-      case 'Z':        /* Write to pipe FD XXX */
 #endif /* _WIN32 */
-        capture_opts_add_opt(capture_opts, opt, optarg, &start_capture);
+        status = capture_opts_add_opt(capture_opts, opt, optarg, &start_capture);
+        if(status != 0) {
+            exit_main(status);
+        }
         break;
-      /* This is a hidden option supporting Sync mode, so we don't set
-       * the error flags for the user in the non-libpcap case.
-       */
-      case 'W':        /* Write to capture file FD xxx */
-        capture_opts_add_opt(capture_opts, opt, optarg, &start_capture);
-       break;
+      /*** hidden option: Ethereal child mode (using binary output messages) ***/
+      case 'Z':
+          capture_child = TRUE;
+#ifdef _WIN32
+          /* set output pipe to binary mode, to avoid ugly text conversions */
+                 _setmode(1, O_BINARY);
+#endif
+          break;
 
       /*** all non capture option specific ***/
+      case 'D':        /* Print a list of capture devices and exit */
+        status = capture_opts_list_interfaces();
+        exit_main(status);
+        break;
       case 'L':        /* Print list of link-layer types and exit */
         list_link_layer_types = TRUE;
         break;
       default:
       case '?':        /* Bad flag - print usage message */
+        cmdarg_err("Invalid Option: %s", argv[optind-1]);
         arg_error = TRUE;
         break;
     }
@@ -379,7 +371,7 @@ main(int argc, char *argv[])
   argv += optind;
   if (argc >= 1) {
       /* user specified file name as regular command-line argument */
-      /* XXX - use it as the capture file name (or somthing else)? */
+      /* XXX - use it as the capture file name (or something else)? */
     argc--;
     argv++;
   }
@@ -425,146 +417,35 @@ main(int argc, char *argv[])
     }
   }
 
-/* Did the user specify an interface to use? */
-if (capture_opts->iface == NULL) {
-    /* No - pick the first one from the list of interfaces. */
-    if_list = get_interface_list(&err, err_str);
-    if (if_list == NULL) {
-      switch (err) {
-
-      case CANT_GET_INTERFACE_LIST:
-          cant_get_if_list_errstr = cant_get_if_list_error_message(err_str);
-          cmdarg_err("%s", cant_get_if_list_errstr);
-          g_free(cant_get_if_list_errstr);
-          break;
-
-      case NO_INTERFACES_FOUND:
-          cmdarg_err("There are no interfaces on which a capture can be done");
-          break;
-      }
-      exit_main(2);
-    }
-    if_info = if_list->data;   /* first interface */
-    capture_opts->iface = g_strdup(if_info->name);
-    free_interface_list(if_list);
+  if (capture_opts_trim_iface(capture_opts, NULL) == FALSE) {
+       cmdarg_err("No capture interfaces available (maybe lack of privileges?).");
+    exit_main(1);
   }
 
+  /* Let the user know what interface was chosen. */
+  /* get_interface_descriptive_name() is not available! */
+  g_log(LOG_DOMAIN_CAPTURE_CHILD, G_LOG_LEVEL_DEBUG, "Interface: %s\n", capture_opts->iface);
+
   if (list_link_layer_types) {
-    /* Get the list of link-layer types for the capture device. */
-    lt_list = get_pcap_linktype_list(capture_opts->iface, err_str);
-    if (lt_list == NULL) {
-      if (err_str[0] != '\0') {
-       cmdarg_err("The list of data link types for the capture device could not be obtained (%s)."
-         "Please check to make sure you have sufficient permissions, and that\n"
-         "you have the proper interface or pipe specified.\n", err_str);
-      } else
-       cmdarg_err("The capture device has no data link types.");
-      exit_main(2);
-    }
-    g_warning("Data link types (use option -y to set):");
-    for (lt_entry = lt_list; lt_entry != NULL;
-         lt_entry = g_list_next(lt_entry)) {
-      data_link_info = lt_entry->data;
-      g_warning("  %s", data_link_info->name);
-      if (data_link_info->description != NULL)
-       g_warning(" (%s)", data_link_info->description);
-      else
-       g_warning(" (not supported)");
-      putchar('\n');
-    }
-    free_pcap_linktype_list(lt_list);
-    exit_main(0);
+    status = capture_opts_list_link_layer_types(capture_opts);
+    exit_main(status);
   }
 
-  capture_opts_trim(capture_opts, MIN_PACKET_SIZE);
+  capture_opts_trim_snaplen(capture_opts, MIN_PACKET_SIZE);
+  capture_opts_trim_ring_num_files(capture_opts);
 
   /* Now start the capture. */
 
-  /* XXX - hand the stats to the parent process */
   if(capture_loop_start(capture_opts, &stats_known, &stats) == TRUE) {
       /* capture ok */
-      err = 0;
+      exit_main(0);
   } else {
       /* capture failed */
-      err = 1;
-  }
-
-  /* the capture is done; there's nothing more for us to do. */
-  exit_main(err);
-}
-
-#ifdef _WIN32
-
-/* We build this as a GUI subsystem application on Win32, so
-   "WinMain()", not "main()", gets called.
-
-   Hack shamelessly stolen from the Win32 port of the GIMP. */
-#ifdef __GNUC__
-#define _stdcall  __attribute__((stdcall))
-#endif
-
-int _stdcall
-WinMain (struct HINSTANCE__ *hInstance,
-        struct HINSTANCE__ *hPrevInstance,
-        char               *lpszCmdLine,
-        int                 nCmdShow)
-{
-  has_console = FALSE;
-  return main (__argc, __argv);
-}
-
-/*
- * If this application has no console window to which its standard output
- * would go, create one.
- */
-void
-create_console(void)
-{
-  if (!has_console) {
-    /* We have no console to which to print the version string, so
-       create one and make it the standard input, output, and error. */
-    if (!AllocConsole())
-      return;   /* couldn't create console */
-    eth_freopen("CONIN$", "r", stdin);
-    eth_freopen("CONOUT$", "w", stdout);
-    eth_freopen("CONOUT$", "w", stderr);
-
-    /* Well, we have a console now. */
-    has_console = TRUE;
-
-    /* Now register "destroy_console()" as a routine to be called just
-       before the application exits, so that we can destroy the console
-       after the user has typed a key (so that the console doesn't just
-       disappear out from under them, giving the user no chance to see
-       the message(s) we put in there). */
-    atexit(destroy_console);
-
-    SetConsoleTitle("Dumpcap Console");
-  }
-}
-
-static void
-destroy_console(void)
-{
-  if (has_console) {
-    printf("\n\nPress any key to exit\n");
-    _getch();
-    FreeConsole();
+      exit_main(1);
   }
 }
-#endif /* _WIN32 */
-
 
-/* This routine should not be necessary, at least as I read the GLib
-   source code, as it looks as if GLib is, on Win32, *supposed* to
-   create a console window into which to display its output.
 
-   That doesn't happen, however.  I suspect there's something completely
-   broken about that code in GLib-for-Win32, and that it may be related
-   to the breakage that forces us to just call "printf()" on the message
-   rather than passing the message on to "g_log_default_handler()"
-   (which is the routine that does the aforementioned non-functional
-   console window creation). */
 static void
 console_log_handler(const char *log_domain, GLogLevelFlags log_level,
                    const char *message, gpointer user_data _U_)
@@ -575,227 +456,171 @@ console_log_handler(const char *log_domain, GLogLevelFlags log_level,
 
 
   /* ignore log message, if log_level isn't interesting */
-  if( !(log_level & G_LOG_LEVEL_MASK & ~G_LOG_LEVEL_DEBUG /*prefs.console_log_level*/)) {
+  if( !(log_level & G_LOG_LEVEL_MASK & ~(G_LOG_LEVEL_DEBUG|G_LOG_LEVEL_INFO))) {
+#ifndef DEBUG_DUMPCAP
     return;
+#endif
   }
 
   /* create a "timestamp" */
   time(&curr);
   today = localtime(&curr);    
 
-#ifdef _WIN32
-/*  if (prefs.gui_console_open != console_open_never) {*/
-    create_console();
-/*  }*/
-  if (has_console) {
-    /* For some unknown reason, the above doesn't appear to actually cause
-       anything to be sent to the standard output, so we'll just splat the
-       message out directly, just to make sure it gets out. */
-#endif
-    switch(log_level & G_LOG_LEVEL_MASK) {
-    case G_LOG_LEVEL_ERROR:
-        level = "Err ";
-        break;
-    case G_LOG_LEVEL_CRITICAL:
-        level = "Crit";
-        break;
-    case G_LOG_LEVEL_WARNING:
-        level = "Warn";
-        break;
-    case G_LOG_LEVEL_MESSAGE:
-        level = "Msg ";
-        break;
-    case G_LOG_LEVEL_INFO:
-        level = "Info";
-        break;
-    case G_LOG_LEVEL_DEBUG:
-        level = "Dbg ";
-        break;
-    default:
-        fprintf(stderr, "unknown log_level %u\n", log_level);
-        level = NULL;
-        g_assert_not_reached();
-    }
+  switch(log_level & G_LOG_LEVEL_MASK) {
+  case G_LOG_LEVEL_ERROR:
+    level = "Err ";
+    break;
+  case G_LOG_LEVEL_CRITICAL:
+    level = "Crit";
+    break;
+  case G_LOG_LEVEL_WARNING:
+    level = "Warn";
+    break;
+  case G_LOG_LEVEL_MESSAGE:
+    level = "Msg ";
+    break;
+  case G_LOG_LEVEL_INFO:
+    level = "Info";
+    break;
+  case G_LOG_LEVEL_DEBUG:
+    level = "Dbg ";
+    break;
+  default:
+    fprintf(stderr, "unknown log_level %u\n", log_level);
+    level = NULL;
+    g_assert_not_reached();
+  }
 
-    /* don't use printf (stdout), as the capture child uses stdout for it's sync_pipe */
+  /* don't use printf (stdout), in child mode we're using stdout for the sync_pipe */
+  if(log_level & G_LOG_LEVEL_MESSAGE) {
+    /* normal user messages without additional infos */
+    fprintf(stderr, "%s\n", message);
+    fflush(stderr);
+  } else {
+    /* info/debug messages with additional infos */
     fprintf(stderr, "%02u:%02u:%02u %8s %s %s\n",
             today->tm_hour, today->tm_min, today->tm_sec,
             log_domain != NULL ? log_domain : "",
             level, message);
-#ifdef _WIN32
-  } else {
-    g_log_default_handler(log_domain, log_level, message, user_data);
+    fflush(stderr);
   }
-#endif
 }
 
+
 /****************************************************************************************************************/
-/* sync_pipe "dummies" */
+/* indication report routines */
 
-static void
-pipe_write_block(int pipe, char indicator, int len, const char *msg)
-{
-}
 
 void
-sync_pipe_packet_count_to_parent(int packet_count)
+report_packet_count(int packet_count)
 {
     char tmp[SP_DECISIZE+1+1];
+    static int count = 0;
 
-    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);
+    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);
+    } else {
+        count += packet_count;
+        fprintf(stderr, "\rPackets: %u ", count);
+        /* stderr could be line buffered */
+        fflush(stderr);
+    }
 }
 
 void
-sync_pipe_filename_to_parent(const char *filename)
+report_new_capture_file(const char *filename)
 {
-    g_log(LOG_DOMAIN_CAPTURE_CHILD, G_LOG_LEVEL_INFO, "File: %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);
+    g_log(LOG_DOMAIN_CAPTURE_CHILD, G_LOG_LEVEL_DEBUG, "File: %s", filename);
 
-    pipe_write_block(1, SP_ERROR_MSG, strlen(errmsg)+1, errmsg);
+    if(capture_child) {
+        pipe_write_block(1, SP_FILE, filename);
+    }
 }
 
 void
-sync_pipe_drops_to_parent(int drops)
+report_cfilter_error(const char *cfilter _U_, const char *errmsg)
 {
-    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);
+    g_log(LOG_DOMAIN_CAPTURE_CHILD, G_LOG_LEVEL_DEBUG, "Capture filter error: %s", errmsg);
 
-    pipe_write_block(1, SP_DROPS, strlen(tmp)+1, tmp);
+    if (capture_child) {
+        pipe_write_block(1, SP_BAD_FILTER, errmsg);
+    }
 }
 
-
-
-/****************************************************************************************************************/
-/* simple_dialog "dummies" */
-
-
-static gpointer *
-display_simple_dialog(gint type, gint btn_mask, char *message)
+void
+report_capture_error(const char *error_msg, const char *secondary_error_msg)
 {
-    printf("%s", message);
 
-    return NULL;
-}
+    g_log(LOG_DOMAIN_CAPTURE_CHILD, G_LOG_LEVEL_DEBUG, 
+        "Primary Error: %s", error_msg);
+    g_log(LOG_DOMAIN_CAPTURE_CHILD, G_LOG_LEVEL_DEBUG, 
+        "Secondary Error: %s", secondary_error_msg);
 
-char *simple_dialog_primary_start(void)
-{
-    return "";
+    if(capture_child) {
+       sync_pipe_errmsg_to_parent(error_msg, secondary_error_msg);
+    }
 }
 
-char *simple_dialog_primary_end(void)
+void
+report_packet_drops(int drops)
 {
-    return "";
-}
-
-/* Simple dialog function - Displays a dialog box with the supplied message
- * text.
- *
- * Args:
- * type       : One of ESD_TYPE_*.
- * btn_mask   : The value passed in determines which buttons are displayed.
- * msg_format : Sprintf-style format of the text displayed in the dialog.
- * ...        : Argument list for msg_format
- */
+    char tmp[SP_DECISIZE+1+1];
 
-gpointer
-vsimple_dialog(ESD_TYPE_E type, gint btn_mask, const gchar *msg_format, va_list ap)
-{
-  gchar             *vmessage;
-  gchar             *message;
-  gpointer          *win;
-#if GTK_MAJOR_VERSION >= 2
-  GdkWindowState state = 0;
-#endif
 
-  /* Format the message. */
-  vmessage = g_strdup_vprintf(msg_format, ap);
+    g_snprintf(tmp, sizeof(tmp), "%d", drops);
+    g_log(LOG_DOMAIN_CAPTURE_CHILD, G_LOG_LEVEL_DEBUG, "Packets dropped: %s", tmp);
 
-#if GTK_MAJOR_VERSION >= 2
-  /* convert character encoding from locale to UTF8 (using iconv) */
-  message = g_locale_to_utf8(vmessage, -1, NULL, NULL, NULL);
-  g_free(vmessage);
-#else
-  message = vmessage;
-#endif
+    if(capture_child) {
+        pipe_write_block(1, SP_DROPS, tmp);
+    }
+}
 
-  win = display_simple_dialog(type, btn_mask, message);
 
-  g_free(message);
+/****************************************************************************************************************/
+/* signal_pipe handling */
 
-  return win;
-}
 
-gpointer
-simple_dialog(ESD_TYPE_E type, gint btn_mask, const gchar *msg_format, ...)
+#ifdef _WIN32
+gboolean
+signal_pipe_check_running(void)
 {
-  va_list ap;
-  gpointer ret;
+    /* any news from our parent (stdin)? -> just stop the capture */
+    HANDLE handle;
+    DWORD avail = 0;
+    gboolean result;
 
-  va_start(ap, msg_format);
-  ret = vsimple_dialog(type, btn_mask, msg_format, ap);
-  va_end(ap);
-  return ret;
-}
 
-char *
-simple_dialog_format_message(const char *msg)
-{
-    char *str;
+    /* if we are running standalone, no check required */
+    if(!capture_child) {
+        return TRUE;
+    }
 
-    if (msg) {
-#if GTK_MAJOR_VERSION < 2
-       str = g_strdup(msg);
-#else
-       str = xml_escape(msg);
-#endif
+    handle = (HANDLE) GetStdHandle(STD_INPUT_HANDLE);
+    result = PeekNamedPipe(handle, NULL, 0, NULL, &avail, NULL);
+
+    if(!result || avail > 0) {
+        /* peek failed or some bytes really available */
+        /* (if not piping from stdin this would fail) */
+        g_log(LOG_DOMAIN_CAPTURE_CHILD, G_LOG_LEVEL_INFO,
+            "Signal pipe: Stop capture");
+        g_log(LOG_DOMAIN_CAPTURE_CHILD, G_LOG_LEVEL_DEBUG,
+            "Signal pipe: handle: %x result: %u avail: %u", handle, result, avail);
+        return FALSE;
     } else {
-       str = NULL;
+        /* pipe ok and no bytes available */
+        return TRUE;
     }
-    return str;
 }
+#endif
 
-/****************************************************************************************************************/
-/* link "dummies" */
-
-
-const char *netsnmp_get_version() { return ""; }
-
-gboolean dfilter_compile(const gchar *text, dfilter_t **dfp) { return NULL; }
-
-void dfilter_free(dfilter_t *df) {}
 
+/****************************************************************************************************************/
+/* Stub functions */
 
-/*
- * Find out whether a hostname resolves to an ip or ipv6 address
- * Return "ip6" if it is IPv6, "ip" otherwise (including the case
- * that we don't know)
- */
-const char* host_ip_af(const char *host
-#ifndef HAVE_GETHOSTBYNAME2
-_U_
-#endif
-)
-{
-#ifdef HAVE_GETHOSTBYNAME2
-       struct hostent *h;
-       return (h = gethostbyname2(host, AF_INET6)) && h->h_addrtype == AF_INET6 ? "ip6" : "ip";
-#else
-       return "ip";
-#endif
-}
 
+const char *netsnmp_get_version(void) { return ""; }