Frame numbers are unsigned.
[obnox/wireshark/wip.git] / capture.c
index b5c443ebcc5c5152d2476ad4bd8d0db679f10876..74ee00f8e09e074abd4e798877a0f31b473776e3 100644 (file)
--- a/capture.c
+++ b/capture.c
@@ -1,7 +1,7 @@
 /* capture.c
  * Routines for packet capture windows
  *
- * $Id: capture.c,v 1.200 2002/12/31 21:06:48 guy Exp $
+ * $Id: capture.c,v 1.207 2003/05/15 13:33:53 deniel Exp $
  *
  * Ethereal - Network traffic analyzer
  * By Gerald Combs <gerald@ethereal.com>
 #include "packet-chdlc.h"
 #include "packet-prism.h"
 #include "packet-ipfc.h"
+#include "packet-arcnet.h"
 
-#ifdef WIN32
+#ifdef _WIN32
 #include "capture-wpcap.h"
 #endif
 
@@ -448,7 +449,6 @@ do_capture(const char *save_file)
     /* Keep a copy for later evaluation by _cwait() */
     child_process = fork_child;
 #else
-    signal(SIGCHLD, SIG_IGN);
     if (pipe(sync_pipe) < 0) {
       /* Couldn't create the pipe between parent and child. */
       error = errno;
@@ -1368,6 +1368,7 @@ capture(gboolean *stats_known, struct pcap_stat *stats)
   int         err, inpkts;
   condition  *cnd_stop_capturesize = NULL;
   condition  *cnd_stop_timeout = NULL;
+  condition  *cnd_ring_timeout = NULL;
   unsigned int i;
   static const char capstart_msg = SP_CAPSTART;
   char        errmsg[4096+1];
@@ -1487,8 +1488,8 @@ capture(gboolean *stats_known, struct pcap_stat *stats)
        "The capture session could not be initiated (%s).\n"
        "Please check that you have the proper interface specified.\n"
        "\n"
-       "Note that the driver Ethereal uses for packet capture on Windows\n"
-       "doesn't support capturing on PPP/WAN interfaces in Windows NT/2000/XP/.NET Server.\n",
+       "Note that the driver Ethereal uses for packet capture on Windows doesn't\n"
+       "support capturing on PPP/WAN interfaces in Windows NT/2000/XP/.NET Server.\n",
        open_err_str);
     goto error;
 #else
@@ -1757,6 +1758,10 @@ capture(gboolean *stats_known, struct pcap_stat *stats)
     cnd_stop_timeout =
         cnd_new(CND_CLASS_TIMEOUT,(gint32)capture_opts.autostop_duration);
 
+  if (capture_opts.ringbuffer_on && capture_opts.has_ring_duration)
+    cnd_ring_timeout =
+       cnd_new(CND_CLASS_TIMEOUT, capture_opts.ringbuffer_duration);
+
   while (ld.go) {
     while (gtk_events_pending()) gtk_main_iteration();
 
@@ -1861,6 +1866,9 @@ capture(gboolean *stats_known, struct pcap_stat *stats)
           if (ringbuf_switch_file(&cfile, &ld.pdh, &ld.err)) {
             /* File switch succeeded: reset the condition */
             cnd_reset(cnd_stop_capturesize);
+           if (cnd_ring_timeout) {
+             cnd_reset(cnd_ring_timeout);
+           }
           } else {
             /* File switch failed: stop here */
             ld.go = FALSE;
@@ -1918,8 +1926,18 @@ capture(gboolean *stats_known, struct pcap_stat *stats)
       if (cnd_stop_timeout != NULL && cnd_eval(cnd_stop_timeout)) {
         /* The specified capture time has elapsed; stop the capture. */
         ld.go = FALSE;
+      } else if (cnd_ring_timeout != NULL && cnd_eval(cnd_ring_timeout)) {
+       /* time elasped for this ring file, swith to the next */
+       if (ringbuf_switch_file(&cfile, &ld.pdh, &ld.err)) {
+         /* File switch succeeded: reset the condition */
+         cnd_reset(cnd_ring_timeout);
+       } else {
+         /* File switch failed: stop here */
+         ld.go = FALSE;
+       }
       }
     }
+
   } /* while (ld.go) */
 
   /* delete stop conditions */
@@ -1927,6 +1945,8 @@ capture(gboolean *stats_known, struct pcap_stat *stats)
     cnd_delete(cnd_stop_capturesize);
   if (cnd_stop_timeout != NULL)
     cnd_delete(cnd_stop_timeout);
+  if (cnd_ring_timeout != NULL)
+    cnd_delete(cnd_ring_timeout);
 
   if (ld.pcap_err) {
     snprintf(errmsg, sizeof(errmsg), "Error while capturing packets: %s",
@@ -1996,7 +2016,7 @@ capture(gboolean *stats_known, struct pcap_stat *stats)
     pcap_close(pch);
   }
 
-#ifdef WIN32
+#ifdef _WIN32
   /* Shut down windows sockets */
   WSACleanup();
 #endif
@@ -2023,7 +2043,7 @@ error:
   cfile.save_file = NULL;
   popup_errmsg(errmsg);
 
-#ifndef WIN32
+#ifndef _WIN32
   if (ld.from_pipe) {
     if (pipe_fd >= 0)
       close(pipe_fd);
@@ -2245,12 +2265,18 @@ capture_pcap_cb(guchar *user, const struct pcap_pkthdr *phdr,
     case WTAP_ENCAP_LOCALTALK:
       capture_llap(&ld->counts);
       break;
-    case WTAP_ENCAP_ATM_SNIFFER:
+    case WTAP_ENCAP_ATM_PDUS:
       capture_atm(&pseudo_header, pd, whdr.caplen, &ld->counts);
       break;
     case WTAP_ENCAP_IP_OVER_FC:
       capture_ipfc(pd, whdr.caplen, &ld->counts);
       break;
+    case WTAP_ENCAP_ARCNET:
+      capture_arcnet(pd, whdr.caplen, &ld->counts, FALSE, TRUE);
+      break;
+    case WTAP_ENCAP_ARCNET_LINUX:
+      capture_arcnet(pd, whdr.caplen, &ld->counts, TRUE, FALSE);
+      break;
     /* XXX - some ATM drivers on FreeBSD might prepend a 4-byte ATM
        pseudo-header to DLT_ATM_RFC1483, with LLC header following;
        we might have to implement that at some point. */