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

2015-03-08 23:07:51 +08:00
 moxiaotiao
#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)));
2219 次点击
所在节点    问与答
0 条回复

这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。

https://www.v2ex.com/t/175409

V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。

V2EX is a community of developers, designers and creative people.

© 2021 V2EX