/* $Id$ */ /* * Copyright (c) 2004 demon * * Permission to use, copy, modify, and distribute this software for any * purpose with or without fee is hereby granted, provided that the above * copyright notice and this permission notice appear in all copies. * * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ #include #include "main.h" #define XPOS 10 #define YPOS 5 #define ASTAT 30 u_long delta(u_long, u_long *); void av(u_long, u_long, u_int); u_int getmax(u_long *); u_long ani[ASTAT]; u_long ano[ASTAT]; u_long api[ASTAT]; u_long apo[ASTAT]; u_long ilast = 0, olast = 0; int out(struct ifdata *diff) { extern struct ifdata ifdata; u_long dli, dlo; WINDOW *scr; move(0,0); mvprintw(YPOS, XPOS, "IF: %s\n", ifdata.xname); mvprintw(YPOS, XPOS + 25, "BR: %d Mbps\n", ifdata.baudrate / 1000000); /* mvprintw(YPOS + 2, XPOS, "RX: %3lu kBps\n", diff->ibytes / 1024); mvprintw(YPOS + 3, XPOS, "RA: %3i kBps\n", delta(diff->ibytes, ani) / 1024); mvprintw(YPOS + 2, XPOS + 25, "TX: %3lu kBps\n", diff->obytes / 1024); mvprintw(YPOS + 3, XPOS + 25, "TA: %3i kBps\n", delta(diff->obytes, ano) / 1024); mvprintw(YPOS + 5, XPOS, "RX: %3lu pps\n", diff->ipackets); mvprintw(YPOS + 6, XPOS, "RA: %3lu pps\n", delta(diff->ipackets, api)); mvprintw(YPOS + 5, XPOS + 25, "TX: %3lu pps\n", diff->opackets); mvprintw(YPOS + 6, XPOS + 25, "TA: %3lu pps\n", delta(diff->opackets, apo)); mvprintw(YPOS + 8, XPOS, "RX: %lu MB\n", ifdata.ibytes / (1024 * 1024)); mvprintw(YPOS + 8, XPOS + 25, "TX: %lu MB\n", ifdata.obytes / (1024 * 1024)); */ dli = delta(diff->ibytes, ani); dlo = delta(diff->obytes, ano); mvprintw(YPOS + 2, XPOS, "/0 /.1 /.2 /.3 /.4 /.5 /.6 /.7 /.8 /.9 /1 x %3lu kBps", getmax(ani) / 1024); mvprintw(YPOS + 3, XPOS - 3, "RX --------------------------------------------------- %3lu kBps", diff->ibytes / 1024); move(YPOS + 3, XPOS); av(diff->ibytes / 1024, ilast, getmax(ani) / 1024); mvprintw(YPOS + 8, XPOS, "/0 /.1 /.2 /.3 /.4 /.5 /.6 /.7 /.8 /.9 /1 x %3lu kBps", getmax(ano) / 1024); mvprintw(YPOS + 9, XPOS - 3, "TX --------------------------------------------------- %3lu kBps", diff->obytes / 1024); move(YPOS + 9, XPOS); av(diff->obytes / 1024, olast, getmax(ano) / 1024); ilast = diff->ibytes / 1024; olast = diff->obytes / 1024; refresh(); } u_long delta(u_long n, u_long *an) { u_long nsum = 0; int i, del = ASTAT; for (i=ASTAT - 1; i>0; i--) { an[i] = an[i-1]; nsum += an[i]; if (an[i] == 0) del -= 1; } an[0] = n; nsum += n; return (nsum / del); } void av(u_long bytes, u_long avbytes, u_int max) { u_int b, avb, i, min; if (max != 0) { b = bytes * 50 / max; avb = avbytes * 50 / max; min = ((bytes < avbytes)?bytes:avbytes) * 50 / max; for (i = 0; i < min; i++) addch('='); if (b > avb) for (i = min; i < b; i++) addch(ACS_RARROW); else for (i = min; i < avb; i++) addch(ACS_LARROW); } } u_int getmax(u_long *an) { int i; u_int max = 0; for (i=0; i max) max = an[i]; } return max; }