Skip to content

Commit

Permalink
Added -o <file_offset> option to start tcpdump resuming log rotation
Browse files Browse the repository at this point in the history
from a given index
  • Loading branch information
7AC committed Nov 11, 2011
1 parent 8b6ba58 commit 9cbafc8
Showing 1 changed file with 16 additions and 5 deletions.
21 changes: 16 additions & 5 deletions tcpdump.c
Original file line number Diff line number Diff line change
Expand Up @@ -604,6 +604,7 @@ main(int argc, char **argv)
register int cnt, op, i;
bpf_u_int32 localnet, netmask;
register char *cp, *infile, *cmdbuf, *device, *RFileName, *WFileName;
int WFileNameOffset;
pcap_handler callback;
int type;
struct bpf_program fcode;
Expand Down Expand Up @@ -640,6 +641,7 @@ main(int argc, char **argv)
infile = NULL;
RFileName = NULL;
WFileName = NULL;
WFileNameOffset = 0;
if ((cp = strrchr(argv[0], '/')) != NULL)
program_name = cp + 1;
else
Expand All @@ -653,7 +655,7 @@ main(int argc, char **argv)
#endif

while (
(op = getopt(argc, argv, "aAb" B_FLAG "c:C:d" D_FLAG "eE:fF:G:hHi:" I_FLAG j_FLAG J_FLAG "KlLm:M:nNOpqr:Rs:StT:u" U_FLAG "vw:W:xXy:Yz:Z:")) != -1)
(op = getopt(argc, argv, "aAb" B_FLAG "c:C:d" D_FLAG "eE:fF:G:hHi:" I_FLAG j_FLAG J_FLAG "KlLm:M:nNo:Opqr:Rs:StT:u" U_FLAG "vw:W:xXy:Yz:Z:")) != -1)
switch (op) {

case 'a':
Expand Down Expand Up @@ -867,6 +869,12 @@ main(int argc, char **argv)
++Nflag;
break;

case 'o':
WFileNameOffset = atoi(optarg);
if (WFileNameOffset < 0)
error("invalid output file offset %s", optarg);
break;

case 'O':
Oflag = 0;
break;
Expand Down Expand Up @@ -1298,10 +1306,13 @@ main(int argc, char **argv)
error("malloc of dumpinfo.CurrentFileName");

/* We do not need numbering for dumpfiles if Cflag isn't set. */
if (Cflag != 0)
MakeFilename(dumpinfo.CurrentFileName, WFileName, 0, WflagChars);
if (Cflag != 0) {
MakeFilename(dumpinfo.CurrentFileName, WFileName, WFileNameOffset, WflagChars);
/* Offset the count too so rotated names are continuous */
Cflag_count = WFileNameOffset;
}
else
MakeFilename(dumpinfo.CurrentFileName, WFileName, 0, 0);
MakeFilename(dumpinfo.CurrentFileName, WFileName, WFileNameOffset, 0);

p = pcap_dump_open(pd, dumpinfo.CurrentFileName);
if (p == NULL)
Expand Down Expand Up @@ -1902,7 +1913,7 @@ usage(void)
(void)fprintf(stderr,
"\t\t[ -C file_size ] [ -E algo:secret ] [ -F file ] [ -G seconds ]\n");
(void)fprintf(stderr,
"\t\t[ -i interface ]" j_FLAG_USAGE " [ -M secret ]\n");
"\t\t[ -i interface ]" j_FLAG_USAGE " [ -M secret ] [ -o file_offset ]\n");
(void)fprintf(stderr,
"\t\t[ -r file ] [ -s snaplen ] [ -T type ] [ -w file ]\n");
(void)fprintf(stderr,
Expand Down

0 comments on commit 9cbafc8

Please sign in to comment.