"pcap-dump-trunc.c".
Don't make the variables "dump_and_trunc()" manipulates external or even
static; fill in a structure with their values and pass a pointer to that
structure to "dump_and_trunc()". "dump_and_trunc()" will update the
"pcap_dumper_t" pointer in that structure if it rotates capture files,
so that the next call to "dump_and_trunc()" will supply the updated
pointer (the previous code was just opening a new capture, but not
updating the variable passed to "dump_and_trunc()").
Instead of duplicating an old version of the "pcap_dump()" code (a
version that didn't write out time stamps as 32-bit seconds and
microsecond values on platforms where the fields in a "struct timeval"
are 64-bit) in "dump_and_trunc()", just call "pcap_dump()" from
"dump_and_trunc()".
# WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
# MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
#
-# @(#) $Header: /tcpdump/master/tcpdump/Makefile.in,v 1.256 2001-10-01 01:12:00 mcr Exp $ (LBL)
+# @(#) $Header: /tcpdump/master/tcpdump/Makefile.in,v 1.257 2001-10-03 07:35:42 guy Exp $ (LBL)
#
# Various configurable paths (remember to edit Makefile.in, not Makefile)
@rm -f $@
$(CC) $(CFLAGS) -c $(srcdir)/$*.c
-CSRC = addrtoname.c gmt2local.c machdep.c parsenfsfh.c pcap-dump-trunc.c \
+CSRC = addrtoname.c gmt2local.c machdep.c parsenfsfh.c \
print-802_11.c print-ah.c print-arcnet.c print-arp.c \
print-ascii.c print-atalk.c print-atm.c print-bgp.c \
print-bootp.c print-bxxp.c print-cdp.c print-chdlc.c \
* WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
*
- * @(#) $Header: /tcpdump/master/tcpdump/interface.h,v 1.172 2001-10-01 01:12:00 mcr Exp $ (LBL)
+ * @(#) $Header: /tcpdump/master/tcpdump/interface.h,v 1.173 2001-10-03 07:35:42 guy Exp $ (LBL)
*/
#ifndef tcpdump_interface_h
#endif
#endif
-extern char *program_name; /*used to generate self-identifying messages */
-
-extern char *WFileName;
+extern char *program_name; /* used to generate self-identifying messages */
extern int32_t thiszone; /* seconds offset from gmt to local time */
#include <pcap.h>
-extern void dump_and_trunc(u_char *, const struct pcap_pkthdr *,
- const u_char *);
extern void ascii_print_with_offset(const u_char *, u_int, u_int);
extern void ascii_print(const u_char *, u_int);
extern void hex_print_with_offset(const u_char *, u_int, u_int);
struct bpf_program;
extern void bpf_dump(struct bpf_program *, int);
-
-extern pcap_t *pd;
-
#endif
+++ /dev/null
-/*
- * Copyright (c) 2001
- *
- * License: BSD
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- *
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in
- * the documentation and/or other materials provided with the
- * distribution.
- * 3. The names of the authors may not be used to endorse or promote
- * products derived from this software without specific prior
- * written permission.
- *
- * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
- * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
- * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
- *
- */
-
-#ifdef HAVE_CONFIG_H
-#include "config.h"
-#endif
-
-#include <stdio.h>
-#include <pcap.h>
-#include <unistd.h>
-#include <stdlib.h>
-#include <string.h>
-
-#include "interface.h"
-
-static void reverse(char *s);
-static void swebitoa(unsigned int n, char s[]);
-
-static void reverse (char s[])
-{
- int i, j, c;
-
- for (i = 0, j = strlen(s) - 1; i < j; i++, j--) {
- c = s[i];
- s[i] = s[j];
- s[j] = c;
- }
-}
-
-
-static void swebitoa (unsigned int n, char s[])
-{
- unsigned int i;
-
- i = 0;
- do {
- s[i++] = n % 10 + '0';
- } while ((n /= 10) > 0);
-
- s[i] = '\0';
- reverse(s);
-}
-
-void
-dump_and_trunc(u_char *user, const struct pcap_pkthdr *h, const u_char *sp)
-{
- extern char *WFileName;
- register FILE *f;
- static uint cnt = 2;
- char *name;
- extern pcap_t *pd;
- extern long int Cflag;
-
- f = (FILE *)user;
-
- if (Cflag && ftell(f) > Cflag) {
- name = (char *) malloc(strlen(WFileName) + 4);
- strcpy(name, WFileName);
- swebitoa(cnt, name + strlen(WFileName));
- cnt++;
- pcap_dump_close((pcap_dumper_t *) f);
- f = (FILE *) pcap_dump_open(pd, name);
- free(name);
- }
-
- /* XXX we should check the return status */
- (void)fwrite((char *)h, sizeof(*h), 1, f);
- (void)fwrite((char *)sp, h->caplen, 1, f);
-}
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED
* WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
+ *
+ * Support for splitting captures into multiple files with a maximum
+ * file size:
+ *
+ * Copyright (c) 2001
*/
#ifndef lint
"@(#) Copyright (c) 1988, 1989, 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1997, 2000\n\
The Regents of the University of California. All rights reserved.\n";
static const char rcsid[] =
- "@(#) $Header: /tcpdump/master/tcpdump/tcpdump.c,v 1.167 2001-10-01 01:12:01 mcr Exp $ (LBL)";
+ "@(#) $Header: /tcpdump/master/tcpdump/tcpdump.c,v 1.168 2001-10-03 07:35:44 guy Exp $ (LBL)";
#endif
/*
int infoprint;
char *program_name;
-char *WFileName;
int32_t thiszone; /* seconds offset from gmt to local time */
static RETSIGTYPE cleanup(int);
static void usage(void) __attribute__((noreturn));
-extern void dump_and_trunc(u_char *user, const struct pcap_pkthdr *h, const u_char *sp);
+static void dump_and_trunc(u_char *, const struct pcap_pkthdr *, const u_char *);
#ifdef SIGINFO
RETSIGTYPE requestinfo(int);
/* NOTREACHED */
}
-pcap_t *pd;
+static pcap_t *pd;
extern int optind;
extern int opterr;
extern char *optarg;
+struct dump_info {
+ char *WFileName;
+ pcap_t *pd;
+ pcap_dumper_t *p;
+};
+
int
main(int argc, char **argv)
{
register int cnt, op, i;
bpf_u_int32 localnet, netmask;
- register char *cp, *infile, *cmdbuf, *device, *RFileName;
- extern char *WFileName;
+ register char *cp, *infile, *cmdbuf, *device, *RFileName, *WFileName;
pcap_handler printer;
struct bpf_program fcode;
RETSIGTYPE (*oldhandler)(int);
+ struct dump_info info;
u_char *pcap_userdata;
char ebuf[PCAP_ERRBUF_SIZE];
if (p == NULL)
error("%s", pcap_geterr(pd));
printer = dump_and_trunc;
- pcap_userdata = (u_char *)p;
+ info.WFileName = WFileName;
+ info.pd = pd;
+ info.p = p;
+ pcap_userdata = (u_char *)&info;
} else {
printer = lookup_printer(pcap_datalink(pd));
pcap_userdata = 0;
(void)setsignal(SIGINFO, requestinfo);
#endif
}
-
if (RFileName == NULL) {
(void)fprintf(stderr, "%s: listening on %s\n",
program_name, device);
infoprint = 0;
}
+static void
+reverse(char *s)
+{
+ int i, j, c;
+
+ for (i = 0, j = strlen(s) - 1; i < j; i++, j--) {
+ c = s[i];
+ s[i] = s[j];
+ s[j] = c;
+ }
+}
+
+
+static void
+swebitoa(unsigned int n, char *s)
+{
+ unsigned int i;
+
+ i = 0;
+ do {
+ s[i++] = n % 10 + '0';
+ } while ((n /= 10) > 0);
+
+ s[i] = '\0';
+ reverse(s);
+}
+
+static void
+dump_and_trunc(u_char *user, const struct pcap_pkthdr *h, const u_char *sp)
+{
+ struct dump_info *info;
+ static uint cnt = 2;
+ char *name;
+
+ info = (struct dump_info *)user;
+
+ /*
+ * XXX - this won't prevent capture files from getting
+ * larger than Cflag - the last packet written to the
+ * file could put it over Cflag.
+ */
+ if (Cflag && ftell((FILE *)info->p) > Cflag) {
+ name = (char *) malloc(strlen(info->WFileName) + 4);
+ strcpy(name, info->WFileName);
+ swebitoa(cnt, name + strlen(info->WFileName));
+ cnt++;
+ pcap_dump_close(info->p);
+ info->p = pcap_dump_open(info->pd, name);
+ free(name);
+ }
+
+ pcap_dump((u_char *)info->p, h, sp);
+}
+
/* Like default_print() but data need not be aligned */
void
default_print_unaligned(register const u_char *cp, register u_int length)