V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
V2EX 提问指南
moxiaotiao
V2EX  ›  问与答

ubuntu 下编译 C 语言错误,帮忙给看看

  •  
  •   moxiaotiao · 2015-03-08 23:07:51 +08:00 · 2203 次点击
    这是一个创建于 3555 天前的主题,其中的信息可能已经有所发展或是发生改变。
    #include <math.h>
    #include "flowcalc.h"

    struct stats {
    uint64_t pkts;

    uint16_t pktlen_min;
    uint16_t pktlen_max;
    double pktlen_mean;
    double pktlen_std;
    uint16_t pktlen_total_min;
    uint16_t pktlen_total_max;
    double pktlen_total_mean;
    double pktlen_total_std;

    double last_ts;
    uint32_t iat_min;
    uint32_t iat_max;
    double iat_mean;
    double iat_std;
    uint32_t iat_total_min;
    uint32_t iat_total_max;
    double iat_total_mean;
    double iat_total_std;
    };

    struct flow {
    struct stats up;
    struct stats down;
    };

    /*****************************/

    bool init()
    {
    printf("%%%% basic_stats 0.1\n");
    printf("%% bs_min_size_up: minimum payload size in forward direction\n");
    printf("%% bs_avg_size_up: average payload size in forward direction\n");
    printf("%% bs_max_size_up: maximum payload size in forward direction\n");
    printf("%% bs_std_size_up: standard deviation of payload size in forward direction\n");
    printf("%% bs_min_size_down: minimum payload size in backward direction\n");
    printf("%% bs_avg_size_down: average payload size in backward direction\n");
    printf("%% bs_max_size_down: maximum payload size in backward direction\n");
    printf("%% bs_std_size_down: standard deviation of payload size in backward direction\n");
    printf("%% bs_pktlen_total_min: minimum payload size in total direction\n");
    printf("%% bs_pktlen_total_max: maximum payload size in total direction\n");
    printf("%% bs_total_avg_size: maverage payload size in total direction\n");
    printf("%% bs_total_std_size: standard deviation of payload size in total direction\n");
    printf("%% bs_min_iat_up: minimum inter-arrival time in forward direction\n");
    printf("%% bs_avg_iat_up: average inter-arrival time in forward direction\n");
    printf("%% bs_max_iat_up: maximum inter-arrival time in forward direction\n");
    printf("%% bs_std_iat_up: standard deviation of inter-arrival time in forward direction\n");
    printf("%% bs_min_iat_down: minimum inter-arrival time in backward direction\n");
    printf("%% bs_avg_iat_down: average inter-arrival time in backward direction\n");
    printf("%% bs_max_iat_down: maximum inter-arrival time in backward direction\n");
    printf("%% bs_std_iat_down: standard deviation of inter-arrival time in backward direction\n");
    printf("%% bs_iat_total_min: minimum inter-arrival time in total direction\n");
    printf("%% bs_iat_total_max: maximum inter-arrival time in total direction\n");
    printf("%% bs_iat_total_mean: average inter-arrival time in total direction\n");
    printf("%% bs_iat_total_std: standard deviation of inter-arrival time in total direction\n");

    printf("@attribute bs_min_size_up numeric\n");
    printf("@attribute bs_avg_size_up numeric\n");
    printf("@attribute bs_max_size_up numeric\n");
    printf("@attribute bs_std_size_up numeric\n");
    printf("@attribute bs_min_size_down numeric\n");
    printf("@attribute bs_avg_size_down numeric\n");
    printf("@attribute bs_max_size_down numeric\n");
    printf("@attribute bs_std_size_down numeric\n");
    printf("@attribute bs_min_iat_up numeric\n");
    printf("@attribute bs_avg_iat_up numeric\n");
    printf("@attribute bs_max_iat_up numeric\n");
    printf("@attribute bs_std_iat_up numeric\n");
    printf("@attribute bs_min_iat_down numeric\n");
    printf("@attribute bs_avg_iat_down numeric\n");
    printf("@attribute bs_max_iat_down numeric\n");
    printf("@attribute bs_std_iat_down numeric\n");

    return true;
    }

    void pkt(struct lfc *lfc, void *pdata,
    struct lfc_flow *lf, void *data,
    double ts, bool up, bool is_new, libtrace_packet_t *pkt)
    {
    struct flow *flow = data;
    struct stats *is;
    int pktlen;
    uint32_t iat;
    double diff, mean, iatd;

    if (is_new) {
    flow->up.pktlen_min = UINT16_MAX;
    flow->up.iat_min = UINT32_MAX;

    flow->down.pktlen_min = UINT16_MAX;
    flow->down.iat_min = UINT32_MAX;
    }

    is = (up ? &flow->up : &flow->down);
    is->pkts++;

    /* pkt length statistics */
    pktlen = trace_get_wire_length(pkt);
    if (pktlen < is->pktlen_min)
    is->pktlen_min = pktlen;
    is->pktlen_total_min = pktlen;
    if (pktlen > is->pktlen_max)
    is->pktlen_max = pktlen;
    is->pktlen_total_max = pktlen;

    diff = pktlen - is->pktlen_mean;
    mean = is->pktlen_mean + diff / is->pkts;
    is->pktlen_std += diff * (pktlen - mean);
    is->pktlen_mean = mean;

    /* pkt inter-arrival time */
    if (is->last_ts > 0) {
    iatd = ts - is->last_ts;
    if (iatd < 0) {
    iat = 0;
    } else {
    /* convert to us */
    iatd *= 1000000;

    if (iatd > UINT32_MAX)
    iat = UINT32_MAX;
    else
    iat = iatd;
    }

    if (iat < is->iat_min)
    is->iat_min = iat;
    is->iat_total_min = iat;
    if (iat > is->iat_max)
    is->iat_max = iat;
    is->iat_total_max = iat;
    diff = iat - is->iat_mean;
    mean = is->iat_mean + diff / is->pkts;
    is->iat_std += diff * (iat - mean);
    is->iat_mean = mean;
    }

    /* update timestamp of last pkt in this direction */
    is->last_ts = ts;
    }

    void flow(struct lfc *lfc, void *pdata,
    struct lfc_flow *lf, void *data)
    {
    struct flow *flow = data;
    struct stats *is;
    int i;

    /* print packet length statistics */
    is = &flow->up;
    for (i = 0; i < 2; i++) {
    if (is->pkts == 0) {
    printf(",0,0,0,0");
    } else {
    printf("%u,%.0f,%u,%.0f",
    is->pktlen_min, is->pktlen_mean, is->pktlen_max,
    (is->pktlen_std / is->pkts));
    }
    is = &flow->down;
    }
    printf(",%u,%u,%.0f,%.0f",
    is->pktlen_total_min, is->pktlen_total_max,
    1/2*(flow->up.pktlen_mean + flow->down.pktlen_mean),
    1/2*((flow->up.pktlen_std / flow->up.pkts) + (flow->down.pktlen_std / flow->down.pkts)));

    /* print inter-arrival time statistics */
    is = &flow->up;
    for (i = 0; i < 2; i++) {
    if (is->pkts < 2) {
    printf(",0,0,0,0");
    } else {
    printf(",%u,%.0f,%u,%.0f",
    is->iat_min, is->iat_mean, is->iat_max,
    (is->iat_std / is->pkts));
    }
    is = &flow->down;
    }
    }
    printf(",%u,%u,%.0f,%.0f",
    is->iat_total_min, is->iat_total_max,
    1/2*(flow->up.iat_mean + flow->down.iat_mean),
    1/2*((flow->up.iat_std / flow->up.pkts) + (flow->down.iat_std / flow->down.pkts)));

    struct module module = {
    .size = sizeof(struct flow),
    .init = init,
    .pkt = pkt,
    .flow = flow
    };

    #:sudo make 后直接报错,错误信息如下:

    basic.c:193:32: 错误: expected declaration specifiers or ‘...’ before string constant
    basic.c:194:32: 错误: 未知的类型名‘is’
    basic.c:194:51: 错误: 未知的类型名‘is’
    basic.c:195:32: 错误: expected declaration specifiers or ‘...’ before numeric constant
    basic.c:196:32: 错误: expected declaration specifiers or ‘...’ before numeric constant


    #193 printf(",%u,%u,%.0f,%.0f",
    #194 is->iat_total_min, is->iat_total_max,
    #195 1/2*(flow->up.iat_mean + flow->down.iat_mean),
    #196 1/2*((flow->up.iat_std / flow->up.pkts) + (flow->down.iat_std / flow->down.pkts)));
    目前尚无回复
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   实用小工具   ·   2645 人在线   最高记录 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 27ms · UTC 07:02 · PVG 15:02 · LAX 23:02 · JFK 02:02
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.