summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMartin Mathieson <martin.r.mathieson@googlemail.com>2012-10-03 18:03:01 +0000
committerMartin Mathieson <martin.r.mathieson@googlemail.com>2012-10-03 18:03:01 +0000
commitafbf3cd59672be92968f0a65f8743765009ef348 (patch)
treea3c6a98f0e569add7d51cd1681cf6ea3d36b7a11
parent218aaf05e3a91dfd3f454b736183809fa1f2e5f1 (diff)
downloadwireshark-afbf3cd59672be92968f0a65f8743765009ef348.tar.gz
Add a command-line option to control how large the reordering list can
become. The default is now 0 (infinite). svn path=/trunk/; revision=45293
-rw-r--r--doc/reordercap.pod11
-rw-r--r--reordercap.c64
2 files changed, 62 insertions, 13 deletions
diff --git a/doc/reordercap.pod b/doc/reordercap.pod
index cf8ee40a96..ad94b7cb12 100644
--- a/doc/reordercap.pod
+++ b/doc/reordercap.pod
@@ -6,6 +6,7 @@ reordercap - Reorder input file by timestamp into output file
=head1 SYNOPSIS
B<reorder>
+S<[ B<-l> E<lt>I<maximum reorder list length>E<gt> ]>
E<lt>I<infile>E<gt> E<lt>I<outfile>E<gt>
=head1 DESCRIPTION
@@ -16,11 +17,13 @@ timestamp.
This functionality may be useful when capture files have been created by
combining frames from more than one well-synchronised source, but the
-frames are still not in strict order.
+frames have not been combined in strict time order.
-It does this by maintaining an ordered list of information about frames it
-has read - at the moment the list has an arbitrary, fixed maximum length
-of 3000 frames.
+It does this by maintaining an ordered (by timestamp) list of information about
+frames it has read. The default is to let this list grow infinitely, but there
+is a command-line option to place a limit upon it. Using a smaller limit will
+allow for the reordering to complete more quickly, at the risk of not completely
+sorting the capture.
B<Reordercap> writes the output capture file in the same format as the input
capture file.
diff --git a/reordercap.c b/reordercap.c
index c206e31e84..9f8ab13940 100644
--- a/reordercap.c
+++ b/reordercap.c
@@ -23,18 +23,38 @@
*
*/
+#include "config.h"
+
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
+#include <glib.h>
+
+#ifdef HAVE_UNISTD_H
+#include <unistd.h>
+#endif
#include "wtap.h"
+#ifndef HAVE_GETOPT
+#include "wsutil/wsgetopt.h"
+#endif
/* Show command-line usage */
-/* TODO: add reoder list length as an optional param? */
static void usage(void)
{
- printf("usage: reordercap <infile> <outfile>\n");
+ fprintf(stderr, "Reordercap %s"
+#ifdef SVNVERSION
+ " (" SVNVERSION " from " SVNPATH ")"
+#endif
+ "\n", VERSION);
+ fprintf(stderr, "Reorder timestamps of input file frames into output file.\n");
+ fprintf(stderr, "See http://www.wireshark.org for more information.\n");
+ fprintf(stderr, "\n");
+ fprintf(stderr, "Usage: reordercap [options] <infile> <outfile>\n");
+ fprintf(stderr, "\n");
+ fprintf(stderr, "Options:\n");
+ fprintf(stderr, " -l <list length> maximum reordering list length (default is infinite).\n");
}
/* Remember where this frame was in the file */
@@ -49,8 +69,9 @@ typedef struct FrameRecord_t {
struct FrameRecord_t *next;
} FrameRecord_t;
-/* This is pretty big, but I don't mind waiting a few seconds */
-#define MAX_REORDER_LIST_LENGTH 3000
+/* By default let the whole capture be completely sorted. */
+/* Would be very slow with a large file very out of order, but this is unlikely */
+static unsigned int g_MAX_LIST_LENGTH=0;
static unsigned int g_FrameRecordCount;
/* This is the list of frames, sorted by time. Later frames at the front, earlier
@@ -79,7 +100,7 @@ static void ReorderListDebugPrint(void)
printf(" (head)");
}
if (tmp == g_FrameListTail) {
- printf(" (tail)\n");
+ printf(" (tail)");
}
printf("\n");
@@ -127,7 +148,13 @@ static gboolean ReorderListEmpty(void)
/* Is the reorder list full? */
static gboolean ReorderListFull(void)
{
- return (g_FrameRecordCount >= MAX_REORDER_LIST_LENGTH);
+ if (g_MAX_LIST_LENGTH <= 0) {
+ /* Zero means don't limit the length */
+ return FALSE;
+ }
+ else {
+ return (g_FrameRecordCount >= g_MAX_LIST_LENGTH);
+ }
}
/* Add a new frame to the reorder list */
@@ -287,12 +314,31 @@ int main(int argc, char *argv[])
const struct wtap_pkthdr *phdr;
guint32 read_count = 0;
+ int opt;
+ char *p;
+ int file_count;
+
/* 1st arg is infile, 2nd arg is outfile */
char *infile;
char *outfile;
- if (argc == 3) {
- infile = argv[1];
- outfile = argv[2];
+
+ /* Process the options first */
+ while ((opt = getopt(argc, argv, "l:")) != -1) {
+ switch (opt) {
+ case 'l':
+ g_MAX_LIST_LENGTH = strtol(optarg, &p, 10);
+ //get_positive_int(optarg, "maximum list length");
+ break;
+ case '?':
+ usage();
+ exit(1);
+ }
+ }
+
+ file_count = argc - optind;
+ if (file_count == 2) {
+ infile = argv[optind];
+ outfile = argv[optind+1];
}
else {
usage();