Ejemplo n.º 1
0
static void initethtab(struct ethtab *table)
{
	table->head = table->tail = NULL;
	table->firstvisible = table->lastvisible = NULL;
	table->count = table->entcount = 0;

	table->borderwin = newwin(LINES - 2, COLS, 1, 0);
	table->borderpanel = new_panel(table->borderwin);

	table->tabwin = newwin(LINES - 4, COLS - 2, 2, 1);
	table->tabpanel = new_panel(table->tabwin);

	wattrset(table->borderwin, BOXATTR);
	tx_box(table->borderwin, ACS_VLINE, ACS_HLINE);
	wmove(table->borderwin, 0, 5 * COLS / 80);
	wprintw(table->borderwin, " PktsIn ");
	wmove(table->borderwin, 0, 16 * COLS / 80);
	wprintw(table->borderwin, " IP In ");
	wmove(table->borderwin, 0, 24 * COLS / 80);
	wprintw(table->borderwin, " BytesIn ");
	wmove(table->borderwin, 0, 34 * COLS / 80);
	wprintw(table->borderwin, " InRate ");

	wmove(table->borderwin, 0, 42 * COLS / 80);
	wprintw(table->borderwin, " PktsOut ");
	wmove(table->borderwin, 0, 53 * COLS / 80);
	wprintw(table->borderwin, " IP Out ");
	wmove(table->borderwin, 0, 61 * COLS / 80);
	wprintw(table->borderwin, " BytesOut ");
	wmove(table->borderwin, 0, 70 * COLS / 80);
	wprintw(table->borderwin, " OutRate ");

	wmove(table->borderwin, LINES - 3, 40);

	wprintw(table->borderwin, " InRate and OutRate are in %s ",
		dispmode(options.actmode));

	wattrset(table->tabwin, STDATTR);
	tx_colorwin(table->tabwin);
	tx_stdwinset(table->tabwin);
	wtimeout(table->tabwin, -1);

	update_panels();
	doupdate();
}
Ejemplo n.º 2
0
static void writeethlog(struct ethtabent *list, int unit, unsigned long nsecs,
			FILE * fd)
{
	char atime[TIME_TARGET_MAX];
	struct ethtabent *ptmp = list;

	genatime(time(NULL), atime);

	fprintf(fd, "\n*** LAN traffic log, generated %s\n\n", atime);

	while (ptmp != NULL) {
		if (ptmp->type == 0) {
			if (ptmp->un.desc.linktype == ARPHRD_ETHER)
				fprintf(fd, "\nEthernet address: %s",
					ptmp->un.desc.ascaddr);
			else if (ptmp->un.desc.linktype == ARPHRD_FDDI)
				fprintf(fd, "\nFDDI address: %s",
					ptmp->un.desc.ascaddr);

			if (ptmp->un.desc.withdesc)
				fprintf(fd, " (%s)", ptmp->un.desc.desc);

			fprintf(fd, "\n");
		} else {
			fprintf(fd,
				"\tIncoming total %llu packets, %llu bytes; %llu IP packets\n",
				ptmp->un.figs.inpcount, ptmp->un.figs.inbcount,
				ptmp->un.figs.inippcount);
			fprintf(fd,
				"\tOutgoing total %llu packets, %llu bytes; %llu IP packets\n",
				ptmp->un.figs.outpcount,
				ptmp->un.figs.outbcount,
				ptmp->un.figs.outippcount);

			fprintf(fd, "\tAverage rates: ");
			if (unit == KBITS)
				fprintf(fd,
					"%.2f kbits/s incoming, %.2f kbits/s outgoing\n",
					(float) (ptmp->un.figs.inbcount * 8 /
						 1000) / (float) nsecs,
					(float) (ptmp->un.figs.outbcount * 8 /
						 1000) / (float) nsecs);
			else
				fprintf(fd,
					"%.2f kbytes/s incoming, %.2f kbytes/s outgoing\n",
					(float) (ptmp->un.figs.inbcount /
						 1024) / (float) nsecs,
					(float) (ptmp->un.figs.outbcount /
						 1024) / (float) nsecs);

			if (nsecs > 5)
				fprintf(fd,
					"\tLast 5-second rates: %.2f %s incoming, %.2f %s outgoing\n",
					ptmp->un.figs.inrate, dispmode(unit),
					ptmp->un.figs.outrate, dispmode(unit));
		}

		ptmp = ptmp->next_entry;
	}

	fprintf(fd, "\nRunning time: %lu seconds\n", nsecs);
	fflush(fd);
}