wiki:replayapi

Tcpreplay 4.0 API

Overview

The API being developed in Tcpreplay 4.0 is intended to cover the tcpreplay & tcpprep functionality. In the future, I plan to include tcprewrite functionality (via tcpedit) within tcpreplay.

The main goal of the API is to allow developers to create GUI's for tcpreplay. Hence, the API will be thread-safe and provide the necessary API calls to allow GUI developers to pause/restart and cancel processing. You will also be able to grab run-time statistics for generating status bars.

API Basics

/* initialize context */
ctx = tcpreplay_init();

/* call various tcpreplay_set_* methods to configure context */
tcpreplay_set_interface(ctx, intf1, "eth0");
tcpreplay_set_speed_mode(ctx, speed_topspeed);
tcpreplay_add_pcap(ctx, "myfile.pcap");
tcpreplay_add_pcap(ctx, "myother.pcap");

/* in main thread */
tcpreplay_replay(ctx, -1); // run all pcaps, blocks until done

tcpreplay_stats_t *stats = tcpreplay_get_stats(ctx);
/* print the stats one final time */

tcpreplay_close(ctx); // free our memory

/* in management thread, print the stats every 10 seconds */
while (tcpreplay_is_running(ctx)) {
    tcpreplay_stats_t *stats = tcpreplay_get_stats(ctx);
    /* print the stats */
    sleep(10);
}

If your management thread is for a GUI, perhaps you'd like to add a pause button:

void
toggle_pause(tcpreplay_t *ctx)
{
   if (! tcpreplay_is_running(ctx))
       return;

   if (tcpreplay_is_suspended(ctx))
       tcpreplay_restart(ctx);
   else
       tcpreplay_suspend(ctx);

}

API

trunk/src/tcpreplay_api.h

Last modified 8 years ago Last modified on 09/09/09 17:36:56