当前位置: 首页>>代码示例>>C++>>正文


C++ SCCalloc函数代码示例

本文整理汇总了C++中SCCalloc函数的典型用法代码示例。如果您正苦于以下问题:C++ SCCalloc函数的具体用法?C++ SCCalloc怎么用?C++ SCCalloc使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了SCCalloc函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: LogFileNewCtx

static OutputCtx *JsonMSSqlLogInitCtx(ConfNode *cn) {
    static char default_11g_log_filename[] = "mssql.json";
    LogFileCtx *file_ctx = LogFileNewCtx();
    if (!file_ctx) {
        SCLogError(SC_ERR_MSSQL_LOG_GENERIC, "could not create new file_ctx");
        return NULL;
    }

    if (SCConfLogOpenGeneric(cn, file_ctx, default_11g_log_filename)) {
        LogFileFreeCtx(file_ctx);
        return NULL;
    }

    LogMSSqlFileCtx *mssqllog_ctx = SCCalloc(sizeof(*mssqllog_ctx), 1);
    if (unlikely(!mssqllog_ctx )) {
        LogFileFreeCtx(file_ctx);
        return NULL;
    }

    mssqllog_ctx->file_ctx = file_ctx;
    OutputCtx *octx = SCCalloc(1, sizeof(*octx));
    if (unlikely(!octx)) {
        LogFileFreeCtx(file_ctx);
        SCFree(mssqllog_ctx);
        return NULL;
    }

    octx->data = mssqllog_ctx;
    octx->DeInit = LogMSSqlLogDeinitCtx;

    SCLogDebug("mssql json log output initialized");

    AppLayerParserRegisterLogger(IPPROTO_TCP, ALPROTO_MSSQL);
    return octx;
}
开发者ID:coanor,项目名称:suricata,代码行数:35,代码来源:output-json-mssql.c

示例2: SCLogError

static OutputCtx *JsonDropLogInitCtxSub(ConfNode *conf, OutputCtx *parent_ctx)
{
    if (OutputDropLoggerEnable() != 0) {
        SCLogError(SC_ERR_CONF_YAML_ERROR, "only one 'drop' logger "
            "can be enabled");
        return NULL;
    }

    AlertJsonThread *ajt = parent_ctx->data;

    JsonDropOutputCtx *drop_ctx = SCCalloc(1, sizeof(*drop_ctx));
    if (drop_ctx == NULL)
        return NULL;

    OutputCtx *output_ctx = SCCalloc(1, sizeof(OutputCtx));
    if (unlikely(output_ctx == NULL)) {
        JsonDropOutputCtxFree(drop_ctx);
        return NULL;
    }

    if (conf) {
        const char *extended = ConfNodeLookupChildValue(conf, "alerts");
        if (extended != NULL) {
            if (ConfValIsTrue(extended)) {
                drop_ctx->flags = LOG_DROP_ALERTS;
            }
        }
    }

    drop_ctx->file_ctx = ajt->file_ctx;

    output_ctx->data = drop_ctx;
    output_ctx->DeInit = JsonDropLogDeInitCtxSub;
    return output_ctx;
}
开发者ID:MikeGiancola,项目名称:suricata,代码行数:35,代码来源:output-json-drop.c

示例3: SCCalloc

static OutputCtx *OutputNFSLogInitSub(ConfNode *conf,
    OutputCtx *parent_ctx)
{
    AlertJsonThread *ajt = parent_ctx->data;

    LogNFSFileCtx *nfslog_ctx = SCCalloc(1, sizeof(*nfslog_ctx));
    if (unlikely(nfslog_ctx == NULL)) {
        return NULL;
    }
    nfslog_ctx->file_ctx = ajt->file_ctx;

    OutputCtx *output_ctx = SCCalloc(1, sizeof(*output_ctx));
    if (unlikely(output_ctx == NULL)) {
        SCFree(nfslog_ctx);
        return NULL;
    }
    output_ctx->data = nfslog_ctx;
    output_ctx->DeInit = OutputNFSLogDeInitCtxSub;

    SCLogDebug("NFS log sub-module initialized.");

    AppLayerParserRegisterLogger(IPPROTO_TCP, ALPROTO_NFS);
    AppLayerParserRegisterLogger(IPPROTO_UDP, ALPROTO_NFS);

    return output_ctx;
}
开发者ID:norg,项目名称:suricata,代码行数:26,代码来源:output-json-nfs.c

示例4: OutputIKEv2LogInitSub

static OutputInitResult OutputIKEv2LogInitSub(ConfNode *conf,
    OutputCtx *parent_ctx)
{
    OutputInitResult result = { NULL, false };
    OutputJsonCtx *ajt = parent_ctx->data;

    LogIKEv2FileCtx *ikev2log_ctx = SCCalloc(1, sizeof(*ikev2log_ctx));
    if (unlikely(ikev2log_ctx == NULL)) {
        return result;
    }
    ikev2log_ctx->file_ctx = ajt->file_ctx;
    ikev2log_ctx->cfg = ajt->cfg;

    OutputCtx *output_ctx = SCCalloc(1, sizeof(*output_ctx));
    if (unlikely(output_ctx == NULL)) {
        SCFree(ikev2log_ctx);
        return result;
    }
    output_ctx->data = ikev2log_ctx;
    output_ctx->DeInit = OutputIKEv2LogDeInitCtxSub;

    SCLogDebug("IKEv2 log sub-module initialized.");

    AppLayerParserRegisterLogger(IPPROTO_UDP, ALPROTO_IKEV2);

    result.ctx = output_ctx;
    result.ok = true;
    return result;
}
开发者ID:bmeeks8,项目名称:suricata,代码行数:29,代码来源:output-json-ikev2.c

示例5: LogFileNewCtx

static OutputCtx *InitCtx(ConfNode *conf, AppProto proto, const char *dft_name) {
	LogFileCtx *ctx = LogFileNewCtx();
	if (ctx == NULL) {
		SCLogError(SC_ERR_JONS_LOG_GENERIC, "couldn't create new file_ctx");
		return NULL;
	}
	
	if (SCConfLogOpenGeneric(conf, ctx, dft_name) < 0) {
		LogFileFreeCtx(ctx);
		return NULL;
	}

	DBJsonLogCtx *jctx = SCCalloc(sizeof(*jctx) , 1);
	if (unlikely(jctx == NULL)) {
		LogFileFreeCtx(ctx);
		return NULL;
	}

	jctx->ctx = ctx;
	OutputCtx *octx = SCCalloc(1, sizeof(*octx));
	if (unlikely(octx == NULL)) {
		LogFileFreeCtx(ctx);
		SCFree(jctx);
		return NULL;
	}

	octx->data = jctx;
	octx->DeInit = DeinitCtx;
	SCLogDebug("log output initialized");

	AppLayerParserRegisterLogger(IPPROTO_TCP, proto);
	return octx;
}
开发者ID:coanor,项目名称:suricata,代码行数:33,代码来源:output-json-db.c

示例6: JsonDropLogInitCtx

static OutputInitResult JsonDropLogInitCtx(ConfNode *conf)
{
    OutputInitResult result = { NULL, false };
    if (OutputDropLoggerEnable() != 0) {
        SCLogError(SC_ERR_CONF_YAML_ERROR, "only one 'drop' logger "
            "can be enabled");
        return result;
    }

    JsonDropOutputCtx *drop_ctx = SCCalloc(1, sizeof(*drop_ctx));
    if (drop_ctx == NULL)
        return result;

    drop_ctx->file_ctx = LogFileNewCtx();
    if (drop_ctx->file_ctx == NULL) {
        JsonDropOutputCtxFree(drop_ctx);
        return result;
    }

    if (SCConfLogOpenGeneric(conf, drop_ctx->file_ctx, DEFAULT_LOG_FILENAME, 1) < 0) {
        JsonDropOutputCtxFree(drop_ctx);
        return result;
    }

    OutputCtx *output_ctx = SCCalloc(1, sizeof(OutputCtx));
    if (unlikely(output_ctx == NULL)) {
        JsonDropOutputCtxFree(drop_ctx);
        return result;
    }

    if (conf) {
        const char *extended = ConfNodeLookupChildValue(conf, "alerts");
        if (extended != NULL) {
            if (ConfValIsTrue(extended)) {
                drop_ctx->flags = LOG_DROP_ALERTS;
            }
        }
        extended = ConfNodeLookupChildValue(conf, "flows");
        if (extended != NULL) {
            if (strcasecmp(extended, "start") == 0) {
                g_droplog_flows_start = 1;
            } else if (strcasecmp(extended, "all") == 0) {
                g_droplog_flows_start = 0;
            } else {
                SCLogWarning(SC_ERR_CONF_YAML_ERROR, "valid options for "
                        "'flow' are 'start' and 'all'");
            }
        }
    }

    output_ctx->data = drop_ctx;
    output_ctx->DeInit = JsonDropLogDeInitCtx;

    result.ctx = output_ctx;
    result.ok = true;
    return result;
}
开发者ID:bmeeks8,项目名称:suricata,代码行数:57,代码来源:output-json-drop.c

示例7: SetupEngineForPacketHeader

/** \internal
 */
static int
SetupEngineForPacketHeader(SigGroupHead *sgh, int sm_type,
        PrefilterPacketHeaderHashCtx *hctx,
        _Bool (*Compare)(PrefilterPacketHeaderValue v, void *),
        void (*Match)(DetectEngineThreadCtx *det_ctx, Packet *p, const void *pectx))
{
    Signature *s = NULL;
    uint32_t sig = 0;
    uint32_t sig_offset = 0;

    PrefilterPacketHeaderCtx *ctx = SCCalloc(1, sizeof(PrefilterPacketHeaderCtx));
    if (ctx == NULL)
        return -1;

    ctx->v1 = hctx->v1;
    ctx->type = hctx->type;
    ctx->value = hctx->value;

    ctx->sigs_cnt = hctx->cnt;
    ctx->sigs_array = SCCalloc(ctx->sigs_cnt, sizeof(SigIntId));
    if (ctx->sigs_array == NULL) {
        SCFree(ctx);
        return -1;
    }

    for (sig = 0; sig < sgh->sig_cnt; sig++) {
        s = sgh->match_array[sig];
        if (s == NULL)
            continue;
        if (s->prefilter_sm == NULL || s->prefilter_sm->type != sm_type)
            continue;

        uint16_t type = 0;
        uint16_t value = 0;
        GetExtraMatch(s, &type, &value);

        if (Compare(ctx->v1, s->prefilter_sm->ctx) &&
            ctx->type == type && ctx->value == value)
        {
            SCLogDebug("appending sid %u on %u", s->id, sig_offset);
            ctx->sigs_array[sig_offset] = s->num;
            sig_offset++;

            s->flags |= SIG_FLAG_PREFILTER;
        }
    }

    SCLogDebug("%s: ctx %p extra type %u extra value %u, sig cnt %u",
            sigmatch_table[sm_type].name, ctx, ctx->type, ctx->value,
            ctx->sigs_cnt);
    PrefilterAppendEngine(sgh, Match, ctx, PrefilterPacketHeaderFree,
            sigmatch_table[sm_type].name);
    return 0;
}
开发者ID:P1sec,项目名称:suricata,代码行数:56,代码来源:detect-engine-prefilter-common.c

示例8: SCLogError

/** \brief Create a new tls log LogFileCtx.
 *  \param conf Pointer to ConfNode containing this loggers configuration.
 *  \return NULL if failure, LogFileCtx* to the file_ctx if succesful
 * */
static OutputCtx *LogTlsLogInitCtx(ConfNode *conf)
{
    if (OutputTlsLoggerEnable() != 0) {
        SCLogError(SC_ERR_CONF_YAML_ERROR, "only one 'tls' logger "
            "can be enabled");
        return NULL;
    }

    LogFileCtx* file_ctx = LogFileNewCtx();

    if (file_ctx == NULL) {
        SCLogError(SC_ERR_TLS_LOG_GENERIC, "LogTlsLogInitCtx: Couldn't "
        "create new file_ctx");
        return NULL;
    }

    if (SCConfLogOpenGeneric(conf, file_ctx, DEFAULT_LOG_FILENAME, 1) < 0) {
        goto filectx_error;
    }

    LogTlsFileCtx *tlslog_ctx = SCCalloc(1, sizeof(LogTlsFileCtx));
    if (unlikely(tlslog_ctx == NULL))
        goto filectx_error;
    tlslog_ctx->file_ctx = file_ctx;

    const char *extended = ConfNodeLookupChildValue(conf, "extended");
    if (extended == NULL) {
        tlslog_ctx->flags |= LOG_TLS_DEFAULT;
    } else {
        if (ConfValIsTrue(extended)) {
            tlslog_ctx->flags |= LOG_TLS_EXTENDED;
        }
    }

    OutputCtx *output_ctx = SCCalloc(1, sizeof(OutputCtx));
    if (unlikely(output_ctx == NULL))
        goto tlslog_error;
    output_ctx->data = tlslog_ctx;
    output_ctx->DeInit = LogTlsLogDeInitCtx;

    SCLogDebug("TLS log output initialized");

    /* enable the logger for the app layer */
    AppLayerParserRegisterLogger(IPPROTO_TCP, ALPROTO_TLS);

    return output_ctx;

tlslog_error:
    SCFree(tlslog_ctx);
filectx_error:
    LogFileFreeCtx(file_ctx);
    return NULL;
}
开发者ID:Jambha,项目名称:suricata,代码行数:57,代码来源:log-tlslog.c

示例9: SetupEngineForPacketHeaderPrefilterPacketU8HashCtx

/** \internal
 *  \brief turn values into a u8 hash map
 *  \todo improve error handling
 *  \todo deduplicate sigs arrays
 */
static int
SetupEngineForPacketHeaderPrefilterPacketU8HashCtx(SigGroupHead *sgh, int sm_type,
        uint32_t *counts,
        void (*Set)(PrefilterPacketHeaderValue *v, void *),
        _Bool (*Compare)(PrefilterPacketHeaderValue v, void *),
        void (*Match)(DetectEngineThreadCtx *det_ctx, Packet *p, const void *pectx))
{
    Signature *s = NULL;
    uint32_t sig = 0;
    uint32_t cnt = 0;

    PrefilterPacketU8HashCtx *ctx = SCCalloc(1, sizeof(PrefilterPacketU8HashCtx));
    if (ctx == NULL)
        return -1;

    int i;
    for (i = 0; i < 256; i++) {
        if (counts[i] == 0)
            continue;
        ctx->array[i] = SCCalloc(1, sizeof(SigsArray));
        BUG_ON(ctx->array[i] == NULL);

        ctx->array[i]->cnt = counts[i];
        ctx->array[i]->sigs = SCCalloc(ctx->array[i]->cnt, sizeof(SigIntId));
        BUG_ON(ctx->array[i]->sigs == NULL);
    }

    for (sig = 0; sig < sgh->sig_cnt; sig++) {
        s = sgh->match_array[sig];
        if (s == NULL)
            continue;
        if (s->prefilter_sm == NULL || s->prefilter_sm->type != sm_type)
            continue;

        PrefilterPacketHeaderValue v;
        memset(&v, 0, sizeof(v));
        Set(&v, s->prefilter_sm->ctx);

        ApplyToU8Hash(ctx, v, s);
        s->flags |= SIG_FLAG_PREFILTER;
        cnt++;
    }

    if (cnt) {
        PrefilterAppendEngine(sgh, Match, ctx,
                PrefilterPacketU8HashCtxFree,
                sigmatch_table[sm_type].name);
    } else {
        PrefilterPacketU8HashCtxFree(ctx);
    }
    return 0;
}
开发者ID:P1sec,项目名称:suricata,代码行数:57,代码来源:detect-engine-prefilter-common.c

示例10: NFQParseAndRegisterQueues

/**
 *  \brief Parses and adds Netfilter queue(s).
 *
 *  \param string with the queue number or range
 *
 *  \retval 0 on success.
 *  \retval -1 on failure.
 */
int NFQParseAndRegisterQueues(const char *queues)
{
    uint16_t queue_start = 0;
    uint16_t queue_end = 0;
    uint16_t num_queues = 1;    // if argument is correct, at least one queue will be created

    // Either "id" or "start:end" format (e.g., "12" or "0:5")
    int count = sscanf(queues, "%hu:%hu", &queue_start, &queue_end);

    if (count < 1) {
        SCLogError(SC_ERR_INVALID_ARGUMENT, "specified queue(s) argument '%s' is not "
                                            "valid (allowed queue numbers are 0-65535)", queues);
        return -1;
    }

    // Do we have a range?
    if (count == 2) {
        // Sanity check
        if (queue_start > queue_end) {
            SCLogError(SC_ERR_INVALID_ARGUMENT, "start queue's number %d is greater than "
                                            "ending number %d", queue_start, queue_end);
            return -1;
        }

        num_queues = queue_end - queue_start + 1; // +1 due to inclusive range
    }

    g_nfq_t = (NFQThreadVars *)SCCalloc(num_queues, sizeof(NFQThreadVars));

    if (g_nfq_t == NULL) {
        SCLogError(SC_ERR_MEM_ALLOC, "Unable to allocate NFQThreadVars");
        exit(EXIT_FAILURE);
    }

    g_nfq_q = (NFQQueueVars *)SCCalloc(num_queues, sizeof(NFQQueueVars));

    if (g_nfq_q == NULL) {
        SCLogError(SC_ERR_MEM_ALLOC, "Unable to allocate NFQQueueVars");
        SCFree(g_nfq_t);
        exit(EXIT_FAILURE);
    }

    do {
        if (NFQRegisterQueue(queue_start) != 0) {
            return -1;
        }
    } while (++queue_start <= queue_end);

    return 0;
}
开发者ID:vpiserchia,项目名称:suricata,代码行数:58,代码来源:source-nfq.c

示例11: OutputFlowLogInitSub

static OutputInitResult OutputFlowLogInitSub(ConfNode *conf, OutputCtx *parent_ctx)
{
    OutputInitResult result = { NULL, false };
    OutputJsonCtx *ojc = parent_ctx->data;

    LogJsonFileCtx *flow_ctx = SCMalloc(sizeof(LogJsonFileCtx));
    if (unlikely(flow_ctx == NULL))
        return result;

    OutputCtx *output_ctx = SCCalloc(1, sizeof(OutputCtx));
    if (unlikely(output_ctx == NULL)) {
        SCFree(flow_ctx);
        return result;
    }

    flow_ctx->file_ctx = ojc->file_ctx;
    flow_ctx->cfg = ojc->cfg;

    output_ctx->data = flow_ctx;
    output_ctx->DeInit = OutputFlowLogDeinitSub;

    result.ctx = output_ctx;
    result.ok = true;
    return result;
}
开发者ID:glongo,项目名称:suricata,代码行数:25,代码来源:output-json-flow.c

示例12: OutputFlowLogInit

static OutputInitResult OutputFlowLogInit(ConfNode *conf)
{
    OutputInitResult result = { NULL, false };
    LogFileCtx *file_ctx = LogFileNewCtx();
    if(file_ctx == NULL) {
        SCLogError(SC_ERR_FLOW_LOG_GENERIC, "couldn't create new file_ctx");
        return result;
    }

    if (SCConfLogOpenGeneric(conf, file_ctx, DEFAULT_LOG_FILENAME, 1) < 0) {
        LogFileFreeCtx(file_ctx);
        return result;
    }

    LogJsonFileCtx *flow_ctx = SCMalloc(sizeof(LogJsonFileCtx));
    if (unlikely(flow_ctx == NULL)) {
        LogFileFreeCtx(file_ctx);
        return result;
    }

    OutputCtx *output_ctx = SCCalloc(1, sizeof(OutputCtx));
    if (unlikely(output_ctx == NULL)) {
        LogFileFreeCtx(file_ctx);
        SCFree(flow_ctx);
        return result;
    }

    flow_ctx->file_ctx = file_ctx;
    output_ctx->data = flow_ctx;
    output_ctx->DeInit = OutputFlowLogDeinit;

    result.ctx = output_ctx;
    result.ok = true;
    return result;
}
开发者ID:glongo,项目名称:suricata,代码行数:35,代码来源:output-json-flow.c

示例13: SCMalloc

OutputCtx *OutputHttpLogInitSub(ConfNode *conf, OutputCtx *parent_ctx)
{
    AlertJsonThread *ajt = parent_ctx->data;

    LogHttpFileCtx *http_ctx = SCMalloc(sizeof(LogHttpFileCtx));
    if (unlikely(http_ctx == NULL))
        return NULL;

    OutputCtx *output_ctx = SCCalloc(1, sizeof(OutputCtx));
    if (unlikely(output_ctx == NULL)) {
        SCFree(http_ctx);
        return NULL;
    }

    http_ctx->file_ctx = ajt->file_ctx;
    http_ctx->flags = LOG_HTTP_DEFAULT;

    if (conf) {
        const char *extended = ConfNodeLookupChildValue(conf, "extended");

        if (extended != NULL) {
            if (ConfValIsTrue(extended)) {
                http_ctx->flags = LOG_HTTP_EXTENDED;
            }
        }
    }
    output_ctx->data = http_ctx;
    output_ctx->DeInit = NULL;

    /* enable the logger for the app layer */
    AppLayerParserRegisterLogger(IPPROTO_TCP, ALPROTO_HTTP);

    return output_ctx;
}
开发者ID:coanor,项目名称:suricata,代码行数:34,代码来源:output-json-http.c

示例14: PktVarAddKeyValue

/**
 *  \brief add a key-value pktvar to the pkt
 *  \retval r 0 ok, -1 error
 */
int PktVarAddKeyValue(Packet *p, uint8_t *key, uint16_t ksize, uint8_t *value, uint16_t size)
{
    PktVar *pv = SCCalloc(1, sizeof(PktVar));
    if (unlikely(pv == NULL))
        return -1;

    pv->key = key;
    pv->key_len = ksize;
    pv->value = value;
    pv->value_len = size;

    PktVar *tpv = p->pktvar;
    if (p->pktvar == NULL)
        p->pktvar = pv;
    else {
        while(tpv) {
            if (tpv->next == NULL) {
                tpv->next = pv;
                return 0;
            }
            tpv = tpv->next;
        }
    }
    return 0;
}
开发者ID:bmeeks8,项目名称:suricata,代码行数:29,代码来源:pkt-var.c

示例15: SCCalloc

/**
 * \brief Create a new LogFileCtx for "fast" output style.
 * \param conf The configuration node for this output.
 * \return A LogFileCtx pointer on success, NULL on failure.
 */
static OutputCtx *JsonAlertLogInitCtxSub(ConfNode *conf, OutputCtx *parent_ctx)
{
    AlertJsonThread *ajt = parent_ctx->data;

    OutputCtx *output_ctx = SCCalloc(1, sizeof(OutputCtx));
    if (unlikely(output_ctx == NULL))
        return NULL;

    if (conf) {
        const char *payload = ConfNodeLookupChildValue(conf, "payload");
        const char *packet  = ConfNodeLookupChildValue(conf, "packet");
        const char *payload_printable = ConfNodeLookupChildValue(conf, "payload-printable");

        if (payload_printable != NULL) {
            if (ConfValIsTrue(payload_printable)) {
                ajt->file_ctx->flags |= LOG_JSON_PAYLOAD;
            }
        }
        if (payload != NULL) {
            if (ConfValIsTrue(payload)) {
                ajt->file_ctx->flags |= LOG_JSON_PAYLOAD_BASE64;
            }
        }
        if (packet != NULL) {
            if (ConfValIsTrue(packet)) {
                ajt->file_ctx->flags |= LOG_JSON_PACKET;
            }
        }
    }

    output_ctx->data = ajt->file_ctx;
    output_ctx->DeInit = JsonAlertLogDeInitCtxSub;

    return output_ctx;
}
开发者ID:johnjohnsp1,项目名称:suricata,代码行数:40,代码来源:output-json-alert.c


注:本文中的SCCalloc函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。