head 1.2; access; symbols; locks; strict; comment @ * @; 1.2 date 2008.04.22.05.05.04; author wessels; state Exp; branches; next 1.1; 1.1 date 2008.04.21.23.39.06; author wessels; state Exp; branches; next ; desc @@ 1.2 log @add progname @ text @#include #include #include #include #include #include #include #include #include #include /* * Remove duplicated packets from a pcap file */ char *progname = NULL; int is_bogus(struct pcap_pkthdr *thishdr, const u_char *thisdata); void usage(void) { fprintf(stderr, "usage: %s pcapfiles ...\n", progname); exit(1); } int main(int argc, char *argv[]) { pcap_t *in = NULL; pcap_dumper_t *out = NULL; char errbuf[PCAP_ERRBUF_SIZE + 1]; struct pcap_pkthdr hdr; const u_char *data; int i; int nbogus = 0; int dryrun = 0; progname = argv[0]; while ((i = getopt(argc, argv, "n")) != -1) { switch (i) { case 'n': dryrun = 1; break; case '?': default: usage(); } } argc -= optind; argv += optind; if (argc < 1) usage(); for (i = 0; i < argc; i++) { in = pcap_open_offline(argv[i], errbuf); if (NULL == in) { fprintf(stderr, "%s: %s", argv[i], errbuf); exit(1); } while ((data = pcap_next(in, &hdr))) { if (is_bogus(&hdr, data)) { nbogus++; if (dryrun) warnx("found bogus packet of caplen=%d, len=%d, at %10lld.%06lld", hdr.caplen, hdr.len, (long long int) hdr.ts.tv_sec, (long long int) hdr.ts.tv_usec); else continue; } if (!out) { out = pcap_dump_open(in, "-"); if (NULL == out) { perror("stdout"); exit(1); } } pcap_dump((void *)out, &hdr, data); } pcap_close(in); } if (out) pcap_dump_close(out); fprintf(stderr, "%s: Removed %d bad packets\n", progname, nbogus); exit(0); } int is_bogus(struct pcap_pkthdr *thishdr, const u_char *thisdata) { if (thishdr->caplen > 65535) return 1; if (thishdr->len > 65535) return 1; return 0; } @ 1.1 log @Initial revision @ text @d16 1 d22 1 a22 1 fprintf(stderr, "usage: tcpdump-remove-bogus pcapfiles ...\n"); d38 1 d85 1 a85 1 fprintf(stderr, "Removed %d bad packets\n", nbogus); @