int main(int argc, char *argv[]) { int optct, rcode; init(); /* call autoopts to process arguments */ optct = optionProcess(&tcpbridgeOptions, argc, argv); argc -= optct; argv += optct; post_args(argc, argv); /* init tcpedit context */ if (tcpedit_init(&tcpedit, pcap_datalink(options.pcap1)) < 0) { errx(-1, "Error initializing tcpedit: %s", tcpedit_geterr(tcpedit)); } /* parse the tcpedit args */ rcode = tcpedit_post_args(&tcpedit); if (rcode < 0) { errx(-1, "Unable to parse args: %s", tcpedit_geterr(tcpedit)); } else if (rcode == 1) { warnx("%s", tcpedit_geterr(tcpedit)); } if (tcpedit_validate(tcpedit) < 0) { errx(-1, "Unable to edit packets given options:\n%s", tcpedit_geterr(tcpedit)); } #ifdef ENABLE_VERBOSE if (options.verbose) { options.tcpdump = (tcpdump_t*)safe_malloc(sizeof(tcpdump_t)); tcpdump_open(options.tcpdump, options.pcap1); } #endif if (gettimeofday(&begin, NULL) < 0) err(-1, "gettimeofday() failed"); /* process packets */ do_bridge(&options, tcpedit); /* clean up after ourselves */ pcap_close(options.pcap1); if (options.unidir) { pcap_close(options.pcap2); } #ifdef ENABLE_VERBOSE tcpdump_close(options.tcpdump); #endif return 0; }
int main(int argc, char *argv[]) { int optct, rcode; pcap_t *dlt_pcap; #ifdef ENABLE_FRAGROUTE char ebuf[FRAGROUTE_ERRBUF_LEN]; #endif tcprewrite_init(); /* call autoopts to process arguments */ optct = optionProcess(&tcprewriteOptions, argc, argv); argc -= optct; argv += optct; /* parse the tcprewrite args */ post_args(argc, argv); /* init tcpedit context */ if (tcpedit_init(&tcpedit, pcap_datalink(options.pin)) < 0) { errx(-1, "Error initializing tcpedit: %s", tcpedit_geterr(tcpedit)); } /* parse the tcpedit args */ rcode = tcpedit_post_args(&tcpedit); if (rcode < 0) { errx(-1, "Unable to parse args: %s", tcpedit_geterr(tcpedit)); } else if (rcode == 1) { warnx("%s", tcpedit_geterr(tcpedit)); } if (tcpedit_validate(tcpedit) < 0) { errx(-1, "Unable to edit packets given options:\n%s", tcpedit_geterr(tcpedit)); } /* open up the output file */ options.outfile = safe_strdup(OPT_ARG(OUTFILE)); dbgx(1, "Rewriting DLT to %s", pcap_datalink_val_to_name(tcpedit_get_output_dlt(tcpedit))); if ((dlt_pcap = pcap_open_dead(tcpedit_get_output_dlt(tcpedit), 65535)) == NULL) err(-1, "Unable to open dead pcap handle."); dbgx(1, "DLT of dlt_pcap is %s", pcap_datalink_val_to_name(pcap_datalink(dlt_pcap))); #ifdef ENABLE_FRAGROUTE if (options.fragroute_args) { if ((options.frag_ctx = fragroute_init(65535, pcap_datalink(dlt_pcap), options.fragroute_args, ebuf)) == NULL) errx(-1, "%s", ebuf); } #endif #ifdef ENABLE_VERBOSE if (options.verbose) { tcpdump_open(&tcpdump, dlt_pcap); } #endif if ((options.pout = pcap_dump_open(dlt_pcap, options.outfile)) == NULL) errx(-1, "Unable to open output pcap file: %s", pcap_geterr(dlt_pcap)); pcap_close(dlt_pcap); /* rewrite packets */ if (rewrite_packets(tcpedit, options.pin, options.pout) != 0) errx(-1, "Error rewriting packets: %s", tcpedit_geterr(tcpedit)); /* clean up after ourselves */ pcap_dump_close(options.pout); pcap_close(options.pin); #ifdef ENABLE_VERBOSE tcpdump_close(&tcpdump); #endif #ifdef ENABLE_DMALLOC dmalloc_shutdown(); #endif return 0; }
int main(int argc, char *argv[]) { int i, optct = 0; int rcode; ctx = tcpreplay_init(); #ifdef TCPREPLAY optct = optionProcess(&tcpreplayOptions, argc, argv); #elif defined TCPREPLAY_EDIT optct = optionProcess(&tcpreplay_editOptions, argc, argv); #endif argc -= optct; argv += optct; rcode = tcpreplay_post_args(ctx, argc); if (rcode <= -2) { warnx("%s", tcpreplay_getwarn(ctx)); } else if (rcode == -1) { errx(-1, "Unable to parse args: %s", tcpreplay_geterr(ctx)); } #ifdef TCPREPLAY_EDIT /* init tcpedit context */ if (tcpedit_init(&tcpedit, sendpacket_get_dlt(ctx->intf1)) < 0) { errx(-1, "Error initializing tcpedit: %s", tcpedit_geterr(tcpedit)); } /* parse the tcpedit args */ rcode = tcpedit_post_args(tcpedit); if (rcode < 0) { errx(-1, "Unable to parse args: %s", tcpedit_geterr(tcpedit)); } else if (rcode == 1) { warnx("%s", tcpedit_geterr(tcpedit)); } if (tcpedit_validate(tcpedit) < 0) { errx(-1, "Unable to edit packets given options:\n%s", tcpedit_geterr(tcpedit)); } #endif if ((ctx->options->enable_file_cache || ctx->options->preload_pcap) && ! HAVE_OPT(QUIET)) { notice("File Cache is enabled"); } /* * Setup up the file cache, if required */ if (ctx->options->enable_file_cache || ctx->options->preload_pcap) { /* Initialise each of the file cache structures */ for (i = 0; i < argc; i++) { ctx->options->file_cache[i].index = i; ctx->options->file_cache[i].cached = FALSE; ctx->options->file_cache[i].packet_cache = NULL; } } for (i = 0; i < argc; i++) { tcpreplay_add_pcapfile(ctx, argv[i]); /* preload our pcap file? */ if (ctx->options->preload_pcap) { preload_pcap_file(ctx, i); } } /* init the signal handlers */ init_signal_handlers(); if (gettimeofday(&ctx->stats.start_time, NULL) < 0) errx(-1, "gettimeofday() failed: %s", strerror(errno)); /* main loop, when not looping forever */ if (ctx->options->loop > 0) { while (ctx->options->loop--) { /* limited loop */ if (ctx->options->dualfile) { /* process two files at a time for network taps */ for (i = 0; i < argc; i += 2) { tcpr_replay_index(ctx, i); } } else { /* process each pcap file in order */ for (i = 0; i < argc; i++) { /* reset cache markers for each iteration */ ctx->cache_byte = 0; ctx->cache_bit = 0; tcpr_replay_index(ctx, i); } } } } else { /* loop forever */ while (1) { if (ctx->options->dualfile) { /* process two files at a time for network taps */ for (i = 0; i < argc; i += 2) { tcpr_replay_index(ctx, i); } } else { /* process each pcap file in order */ for (i = 0; i < argc; i++) { /* reset cache markers for each iteration */ ctx->cache_byte = 0; ctx->cache_bit = 0; tcpr_replay_index(ctx, i); } } } } if (ctx->stats.bytes_sent > 0) { if (gettimeofday(&ctx->stats.end_time, NULL) < 0) errx(-1, "gettimeofday() failed: %s", strerror(errno)); packet_stats(&ctx->stats); printf("%s", sendpacket_getstat(ctx->intf1)); if (ctx->intf2 != NULL) printf("%s", sendpacket_getstat(ctx->intf2)); } tcpreplay_close(ctx); return 0; } /* main() */