libtcpedit

The basic idea behind libtcpedit (or just tcpedit for short) is to move all the packet editing functionality previously in tcpreplay (2.x), tcprewrite (3.x) and tcpbrige into a single library with a simple API. Eventually, tcpedit will be packaged along with tcpreplay so that other projects can use it.

Go here for information about libtcpedit's design.

API Example

Below is (most of) the main() function from tcprewrite which uses libtcpedit to modify packets. Hopefully it illustrates just how easy it is to add the power of libtcpedit to any program.

#include "tcprewrite.h"
#include "tcprewrite_opts.h"
#include "tcpedit/tcpedit.h"
#include "tcpedit/parse_args.h"

tcprewrite_opt_t options;
tcpedit_t tcpedit;
int main(int argc, char *argv[])
{
    int optct, rcode;
    tcpedit_t *tcpedit_ptr;
    
    /* call autoopts to process arguments specific to tcprewrite */
    optct = optionProcess(&tcprewriteOptions, argc, argv);
    argc -= optct;
    argv += optct;

    /* parse the tcprewrite args */
    post_args(argc, argv);
  
    /* init our tcpedit context */
    tcpedit_ptr = &tcpedit;
    if (tcpedit_init(&tcpedit, options.pin, NULL) < 0) {
        errx(1, "Error initializing tcpedit: %s", tcpedit_geterr(&tcpedit));
    }
    
  
    /* parse the libtcpedit args */
    rcode = tcpedit_post_args(&tcpedit_ptr);
    if (rcode < 0) {
        errx(1, "Unable to parse args: %s", tcpedit_geterr(&tcpedit));
    } else if (rcode == 1) {
        warnx("%s", tcpedit_geterr(&tcpedit));
    }

    /* validate the options given the DLT type(s) of the input pcap(s) */    
    if (tcpedit_validate(&tcpedit, pcap_datalink(options.pin), 
            HAVE_OPT(DLT) ? OPT_VALUE_DLT : pcap_datalink(options.pin)) < 0) {
        errx(1, "Unable to edit packets given options/DLT types:\n%s",
                tcpedit_geterr(&tcpedit));
    }

    /* rewrite all the packets */
    if (rewrite_packets(&tcpedit, options.pin, options.pout) != 0)
        errx(1, "Error rewriting packets: %s", tcpedit_geterr(&tcpedit));


    /* close the in/output pcap filehandles */
    pcap_dump_close(options.pout);
    pcap_close(options.pin);


    return 0;
}

Error: Failed to load processor TagIt
No macro or processor named 'TagIt' found