1 Star 0 Fork 0

zwhy/oflops

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
log.c 1.00 KB
一键复制 编辑 原始数据 按行查看 历史
#include "log.h"
const char *msg_type[] = {
"OFPT_FLOW_MOD_ADD",
"OFPT_STATS_REQUEST_FLOW",
"OFPT_STATS_REPLY_FLOW",
"OFPT_STATS_REQUEST_FLOW",
"OFPT_STATS_REPLY_PORT",
"OFPT_HELLO",
"OFPT_ECHO_REPLY",
"OFPT_ECHO_REQUEST",
"OFPT_ERROR",
"GENERIC_MSG",
"SNMP_MSG",
"PCAP_MSG",
"OFPT_PACKET_IN_MSG",
"PKTGEN_MSG"
};
FILE* logger;
/*
* Initializes the logging system of oflops.
* @param filename The file where the logging messages are stored.
*/
void
oflops_log_init(const char *filename) {
logger = fopen(filename, "w");
if(logger == NULL) {
perror_and_exit("failed to open log file", 1);
}
}
int
oflops_log(struct timeval ts, int type, char *details) {
fprintf(logger, "%lu.%06lu:%s:%s\n",(long unsigned int)ts.tv_sec,
(long unsigned int)ts.tv_usec, msg_type[type], details);
fflush(logger);
return 1;
}
/*
* Initializes the logging system of oflops.
* @param filename The file where the logging messages are stored.
*/
void
oflops_log_close() {
fclose(logger);
}
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/yinfuxing/oflops.git
git@gitee.com:yinfuxing/oflops.git
yinfuxing
oflops
oflops
master

搜索帮助

0d507c66 1850385 C8b1a773 1850385