示例#1
0
/**
 * same as tcpedit_set_encoder_plugin_byid() except we take the DLT_<name>
 * as a string to select it
 */
int
tcpedit_set_encoder_dltplugin_byname(tcpedit_t *tcpedit, const char *name)
{
    tcpeditdlt_plugin_t *plugin;
    tcpeditdlt_t *ctx;

    assert(tcpedit);

    ctx = tcpedit->dlt_ctx;
    assert(ctx);

    if (ctx->encoder) {
        tcpedit_seterr(tcpedit, "You have already selected a DLT encoder: %s", ctx->encoder->name);
        return TCPEDIT_ERROR;
    }

    plugin = tcpedit_dlt_getplugin_byname(ctx, name);
    if (plugin == NULL) {
        tcpedit_seterr(tcpedit, "No output DLT plugin available for: %s", name);
        return TCPEDIT_ERROR;
    }

    ctx->encoder = plugin;

    /* init the encoder plugin if it's not the decoder plugin too */
    if (ctx->encoder->dlt != ctx->decoder->dlt) {
        if (ctx->encoder->plugin_init(ctx) != TCPEDIT_OK) {
            /* plugin should generate the error */
            return TCPEDIT_ERROR;
        }
    }

    return TCPEDIT_OK;
}
示例#2
0
/**
 * \brief Call this to parse AutoOpts arguments for the DLT encoder plugin
 *
 * Was previously part of tcpedit_dlt_init(), but moved into it's own function
 * to allow a full programtic API.  Basically, if you're not using this function
 * you'll need to roll your own!
 * Returns 0 on success, -1 on error
 */
int 
tcpedit_dlt_post_args(tcpedit_t *tcpedit)
{
    tcpeditdlt_t *ctx;
    const char *dst_dlt_name = NULL;
    int rcode;
    
    assert(tcpedit);
    ctx = tcpedit->dlt_ctx;
    assert(ctx);
    
    /* Select the encoder plugin */
    dst_dlt_name = OPT_ARG(DLT) ? OPT_ARG(DLT) : ctx->decoder->name;
    if ((ctx->encoder = tcpedit_dlt_getplugin_byname(ctx, dst_dlt_name)) == NULL) {
        tcpedit_seterr(tcpedit, "No output DLT plugin available for: %s", dst_dlt_name);
        return TCPEDIT_ERROR;
    }
    
    /* Figure out if we're skipping braodcast & multicast */
    if (HAVE_OPT(SKIPL2BROADCAST))
        ctx->skip_broadcast = 1;

    /* init encoder plugin if it's not the decoder plugin */
    if (ctx->encoder->dlt != ctx->decoder->dlt) {
        if ((rcode = ctx->encoder->plugin_init(ctx)) != TCPEDIT_OK) {
            /* plugin should generate the error */
            return TCPEDIT_ERROR;
        }
    }

    /* parse the DLT specific options */
    if ((rcode = tcpedit_dlt_parse_opts(ctx)) != TCPEDIT_OK) {
        /* parser should generate the error */
        return TCPEDIT_ERROR;
    }

    /* we're OK */
    return tcpedit_dlt_post_init(ctx);
}