/* $Id$ */ /* * Copyright (c) 2004 Dimitri Sokolyuk * * 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 ASTAT 30 #define XPOS 10 extern int LINES; 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); dli = delta(diff->ibytes, ani); dlo = delta(diff->obytes, ano); mvprintw(LINES / 3 - 1, XPOS, "/0 /.1 /.2 /.3 /.4 /.5 /.6 /.7 /.8 /.9 /1 x %3lu kBps\n", getmax(ani) / 1024); mvprintw(LINES / 3, XPOS - 3, "RX --------------------------------------------------- %3lu kBps\n", diff->ibytes / 1024); move(LINES / 3, XPOS); av(diff->ibytes / 1024, ilast, getmax(ani) / 1024); mvprintw(2 * LINES / 3 - 1, XPOS, "/0 /.1 /.2 /.3 /.4 /.5 /.6 /.7 /.8 /.9 /1 x %3lu kBps\n", getmax(ano) / 1024); mvprintw(2 * LINES / 3, XPOS - 3, "TX --------------------------------------------------- %3lu kBps\n", diff->obytes / 1024); move(2 * LINES / 3, 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 = (b < avb)?b:avb; if (b != 0 || avb != 0) { for (i = 0; i < min; i++) addch('='); if (b < avb) for (i = min; i <= avb; i++) addch(ACS_LARROW); else if (b > avb) for (i = min; i <= b; i++) addch(ACS_RARROW); else addch('='); } } } u_int getmax(u_long *an) { int i; u_int max = 0; for (i=0; i max) max = an[i]; } return max; }