📄 stat.c
字号:
/* This file is part of sniffer, a packet capture utility and network moniter The author can be contacted at <mistral@stev.org> the lastest version is avilable from http://stev.org This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.*/#include "config.h"#include <stdio.h>#include <string.h>#include <time.h>#include "stat.h"struct gen_stat stat_global;void init_stat(struct gen_stat *stat, char *title) { static char *str_bytes = "Bytes"; /* just set every thing in the struct to 0 */ bzero(stat, sizeof(struct gen_stat)); stat->title = title; stat->last = time(NULL); stat->init = time(NULL); stat->messure = str_bytes; stat_process(stat); /* we need to set up our processing */}void stat_process(struct gen_stat *stat) { time_t t; time_t ctime; ctime = time(NULL); t = ctime - stat->last; stat->readable = stat->bytes; if (stat->readable > 100000) { stat->readable /= 1024; if (stat->readable > 100000) { stat->readable /= 1024; if (stat->readable > 10000) { stat->readable /= 1024; stat->messure = "GB"; } else { stat->messure = "MB"; } } else { stat->messure = "KB"; } } else { stat->messure = "B"; } if (t < 4) /* lets do it at a 4 second minimun */ return; /* calculate all the rates */ stat->rate_packets = (float) (stat->packets - stat->old_packets) / t; stat->rate_kb = (float) (stat->bytes - stat->old_bytes) / t / 1024; stat->avg_packets = (float) stat->packets / (ctime - stat->init); stat->avg_kb = (float) (stat->bytes / (ctime - stat->init)) / 1024; stat->old_packets = stat->packets; stat->old_bytes = stat->bytes; stat->old_dropped = stat->dropped; /* set the last time this was done before we return */ stat->last = time(NULL); return;}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -