/* * The detailed interface statistics function */ void detstats(char *iface, time_t facilitytime) { int logging = options.logging; WINDOW *statwin; PANEL *statpanel; int pkt_result = 0; FILE *logfile = NULL; unsigned int iplen = 0; struct ifcounts ifcounts; int ch; struct timeval tv; struct timeval start_tv; struct timeval updtime; time_t starttime; time_t now; time_t statbegin; time_t startlog; struct proto_counter span; struct rate rate; struct rate rate_in; struct rate rate_out; unsigned long peakactivity = 0; unsigned long peakactivity_in = 0; unsigned long peakactivity_out = 0; struct rate pps_rate; struct rate pps_rate_in; struct rate pps_rate_out; unsigned long peakpps = 0; unsigned long peakpps_in = 0; unsigned long peakpps_out = 0; int fd; if (!dev_up(iface)) { err_iface_down(); return; } LIST_HEAD(promisc); if (options.promisc) { promisc_init(&promisc, iface); promisc_set_list(&promisc); } move(LINES - 1, 1); stdexitkeyhelp(); statwin = newwin(LINES - 2, COLS, 1, 0); statpanel = new_panel(statwin); tx_stdwinset(statwin); wtimeout(statwin, -1); wattrset(statwin, BOXATTR); tx_colorwin(statwin); tx_box(statwin, ACS_VLINE, ACS_HLINE); wmove(statwin, 0, 1); wprintw(statwin, " Statistics for %s ", iface); wattrset(statwin, STDATTR); update_panels(); doupdate(); memset(&ifcounts, 0, sizeof(struct ifcounts)); if (logging) { if (strcmp(current_logfile, "") == 0) { snprintf(current_logfile, 64, "%s-%s.log", DSTATLOG, iface); if (!daemonized) input_logfile(current_logfile, &logging); } } if (logging) { opentlog(&logfile, current_logfile); if (logfile == NULL) logging = 0; } if (logging) { signal(SIGUSR1, rotate_dstat_log); rotate_flag = 0; writelog(logging, logfile, "******** Detailed interface statistics started ********"); } printdetlabels(statwin); printdetails(&ifcounts, statwin); update_panels(); doupdate(); memset(&span, 0, sizeof(span)); rate_alloc(&rate, 5); rate_alloc(&rate_in, 5); rate_alloc(&rate_out, 5); rate_alloc(&pps_rate, 5); rate_alloc(&pps_rate_in, 5); rate_alloc(&pps_rate_out, 5); gettimeofday(&tv, NULL); start_tv = tv; updtime = tv; starttime = startlog = statbegin = tv.tv_sec; leaveok(statwin, TRUE); fd = socket(PF_PACKET, SOCK_RAW, htons(ETH_P_ALL)); if(fd == -1) { write_error("Unable to obtain monitoring socket"); goto err; } if(dev_bind_ifname(fd, iface) == -1) { write_error("Unable to bind interface on the socket"); goto err_close; } exitloop = 0; PACKET_INIT(pkt); /* * Data-gathering loop */ while (!exitloop) { gettimeofday(&tv, NULL); now = tv.tv_sec; if ((now - starttime) >= 1) { char buf[64]; unsigned long activity, activity_in, activity_out; unsigned long pps, pps_in, pps_out; unsigned long msecs; wattrset(statwin, BOXATTR); printelapsedtime(statbegin, now, LINES - 3, 1, statwin); msecs = timeval_diff_msec(&tv, &start_tv); rate_add_rate(&rate, span.proto_total.pc_bytes, msecs); activity = rate_get_average(&rate); rate_add_rate(&rate_in, span.proto_in.pc_bytes, msecs); activity_in = rate_get_average(&rate_in); rate_add_rate(&rate_out, span.proto_out.pc_bytes, msecs); activity_out = rate_get_average(&rate_out); rate_add_rate(&pps_rate, span.proto_total.pc_packets, msecs); pps = rate_get_average(&pps_rate); rate_add_rate(&pps_rate_in, span.proto_in.pc_packets, msecs); pps_in = rate_get_average(&pps_rate_in); rate_add_rate(&pps_rate_out, span.proto_out.pc_packets, msecs); pps_out = rate_get_average(&pps_rate_out); memset(&span, 0, sizeof(span)); starttime = now; start_tv = tv; wattrset(statwin, HIGHATTR); rate_print(activity, buf, sizeof(buf)); mvwprintw(statwin, 14, 19, "%s", buf); rate_print_pps(pps, buf, sizeof(buf)); mvwprintw(statwin, 15, 19, "%s", buf); rate_print(activity_in, buf, sizeof(buf)); mvwprintw(statwin, 17, 19, "%s", buf); rate_print_pps(pps_in, buf, sizeof(buf)); mvwprintw(statwin, 18, 19, "%s", buf); rate_print(activity_out, buf, sizeof(buf)); mvwprintw(statwin, 20, 19, "%s", buf); rate_print_pps(pps_out, buf, sizeof(buf)); mvwprintw(statwin, 21, 19, "%s", buf); if (activity > peakactivity) peakactivity = activity; if (activity_in > peakactivity_in) peakactivity_in = activity_in; if (activity_out > peakactivity_out) peakactivity_out = activity_out; if (pps > peakpps) peakpps = pps; if (pps_in > peakpps_in) peakpps_in = pps_in; if (pps_out > peakpps_out) peakpps_out = pps_out; } if (logging) { check_rotate_flag(&logfile); if ((now - startlog) >= options.logspan) { writedstatlog(iface, peakactivity, peakpps, peakactivity_in, peakpps_in, peakactivity_out, peakpps_out, &ifcounts, time(NULL) - statbegin, logfile); startlog = now; } } if (screen_update_needed(&tv, &updtime)) { printdetails(&ifcounts, statwin); update_panels(); doupdate(); updtime = tv; } if ((facilitytime != 0) && (((now - statbegin) / 60) >= facilitytime)) exitloop = 1; if (packet_get(fd, &pkt, &ch, statwin) == -1) { write_error("Packet receive failed"); exitloop = 1; break; } switch (ch) { case ERR: /* no key ready, do nothing */ break; case 12: case 'l': case 'L': tx_refresh_screen(); break; case 'Q': case 'q': case 'X': case 'x': case 24: case 27: exitloop = 1; break; } if (pkt.pkt_len <= 0) continue; int outgoing; pkt_result = packet_process(&pkt, NULL, NULL, NULL, MATCH_OPPOSITE_USECONFIG, options.v6inv4asv6); if (pkt_result != PACKET_OK && pkt_result != MORE_FRAGMENTS) continue; outgoing = (pkt.pkt_pkttype == PACKET_OUTGOING); update_proto_counter(&ifcounts.total, outgoing, pkt.pkt_len); if (pkt.pkt_pkttype == PACKET_BROADCAST) { update_pkt_counter(&ifcounts.bcast, pkt.pkt_len); } update_proto_counter(&span, outgoing, pkt.pkt_len); /* account network layer protocol */ switch(pkt.pkt_protocol) { case ETH_P_IP: if (pkt_result == CHECKSUM_ERROR) { update_pkt_counter(&ifcounts.bad, pkt.pkt_len); continue; } iplen = ntohs(pkt.iphdr->tot_len); update_proto_counter(&ifcounts.ipv4, outgoing, iplen); break; case ETH_P_IPV6: iplen = ntohs(pkt.ip6_hdr->ip6_plen) + 40; update_proto_counter(&ifcounts.ipv6, outgoing, iplen); break; default: update_proto_counter(&ifcounts.nonip, outgoing, iplen); continue; } __u8 ip_protocol = pkt_ip_protocol(&pkt); /* account transport layer protocol */ switch (ip_protocol) { case IPPROTO_TCP: update_proto_counter(&ifcounts.tcp, outgoing, iplen); break; case IPPROTO_UDP: update_proto_counter(&ifcounts.udp, outgoing, iplen); break; case IPPROTO_ICMP: case IPPROTO_ICMPV6: update_proto_counter(&ifcounts.icmp, outgoing, iplen); break; default: update_proto_counter(&ifcounts.other, outgoing, iplen); break; } } err_close: close(fd); err: rate_destroy(&pps_rate_out); rate_destroy(&pps_rate_in); rate_destroy(&pps_rate); rate_destroy(&rate_out); rate_destroy(&rate_in); rate_destroy(&rate); if (options.promisc) { promisc_restore_list(&promisc); promisc_destroy(&promisc); } if (logging) { signal(SIGUSR1, SIG_DFL); writedstatlog(iface, peakactivity, peakpps, peakactivity_in, peakpps_in, peakactivity_out, peakpps_out, &ifcounts, time(NULL) - statbegin, logfile); writelog(logging, logfile, "******** Detailed interface statistics stopped ********"); fclose(logfile); } del_panel(statpanel); delwin(statwin); strcpy(current_logfile, ""); pkt_cleanup(); update_panels(); doupdate(); }
void docommand(char ch) { int count; char dateb[7]; switch (ch) { case ARROWR : if (status.stockprice != 3 + 1) exit(0);goright(); break; case ARROWL : if (status.stockprice != 5 - 1) exit(0);goleft(); break; case ARROWU : if (status.stockprice != 2 + 2) exit(0);goup(); break; case ARROWD : if (status.stockprice != 3 + 1) exit(0);godown(); break; case HOME : leavecell(sys.cell); if ((sys.screen == SCREEN1 || sys.screen == SCREEN3) && page == PAGEDOWN) { sys.cell.row = 23; sys.cell.col = MONTH; } else if (sys.screen == SCREEN2) { sys.cell.row = 8; sys.cell.col = SHARESPER; } else { sys.cell.row = 8; sys.cell.col = MONTH; } entercell(sys.cell); break; case END : leavecell(sys.cell); if ((sys.screen == SCREEN1 || sys.screen == SCREEN3) && page == PAGEDOWN) { sys.cell.row = 37; sys.cell.col = MONTH; } else if (sys.screen == SCREEN2) { sys.cell.row = 22; sys.cell.col = SHARESPER; } else { sys.cell.row = 22; sys.cell.col = MONTH; } entercell(sys.cell); break; case PGUP : if ((sys.screen == SCREEN1 || sys.screen == SCREEN3) && page == PAGEDOWN) { page = PAGEUP; if (sys.cell.row >= 8) sys.cell.row -= 15; disppage(); } showall(); entercell(sys.cell); break; case PGDN : if ((sys.screen == SCREEN1 || sys.screen == SCREEN3) && page == PAGEUP) { page = PAGEDOWN; if (sys.cell.row >= 8) sys.cell.row += 15; disppage(); } showall(); entercell(sys.cell); break; case F01 : help();break; case F02 : demo(); break; case F03 : demo(); break; case F04 : sortstatus(); genscreen(); entercell(sys.cell); break; case F05 : { if (drawgraph(choice(6,graphchoice)) < 0) errormessage("Graphics initialisation error"); genscreen(); showtotals(); entercell(sys.cell); } break; case F06 : leavecell(sys.cell); switch (choice(3,screenchoice)) { case 1 : if (tosavesys) savesys(); sys.screen = SCREEN1; page = PAGEUP; sys.cell.col = MONTH; sys.cell.row = 8; sys.display = HELDS; genscreen(); break; case 2 : sys.screen = SCREEN2; sys.display = HELDS; page = PAGEUP; sys.cell.row = 8; sys.cell.col = EXPIRYDAY; genscreen(); break; case 3 : if (tosavesys) savesys(); sys.cell.col = MONTH; page = PAGEUP; sys.screen = SCREEN3; sys.display = INVVOL; sys.cell.row = 8; wait(); if (recalcvolvalues) calcallvol(); ready(); genscreen(); break; } showtotals(); entercell(sys.cell); break; case F07 : switch(choice(3,clearchoice)) { case 1 : if (sys.cell.row < 8 || sys.screen == SCREEN2) break; wait(); clearrow(); calcall(); showall(); totals(); entercell(sys.cell); break; case 2 : wait(); switch( sys.cell.col) { case VOLC : case VALUEC : case VOLP : case DELTAC : case VALUEP : case DELTAP: case SHAREPRICE :break; case STOCKHELD : status.stockheld = 0; break; case VOLATILITY : status.volatility = 0.0;break; case INTEREST : status.interest = 0.0; break; case DATE : case YEARMONTH : case SHARESPER : for (count =0;count <24; count++) status.sizepay[count].sharesper = 1000; break; case EXPIRYDAY : case DAYSLEFT : case MONTH : break; case STRIKE : for (count = 0;count < 30; count++) { status.data[count].strike = 0.0; status.data[count].volc = 0.0; status.data[count].volp = 0.0; } break; case MARKETC : for (count = 0;count < 30; count++) { status.data[count].marketc = 0.0; status.data[count].volc = 0.0; } break; case HELDC : for (count = 0;count < 30; count++) status.data[count].heldc = 0; break; case MARKETP : for (count = 0;count < 30; count++) { status.data[count].marketp = 0.0; status.data[count].volp = 0.0; } break; case HELDP : for (count = 0;count < 30; count++) status.data[count].heldp = 0; break; case DIVIDENDDAY : for (count = 0;count < 24; count++) status.sizepay[count].dday = 0; break; case DIVIDENDCENTS : for (count = 0;count < 24; count++) status.sizepay[count].payout = 0; break; } wait(); calcall(); showall(); totals(); break; case 3: clearall();wait(); wait(); calcall(); showall(); totals();break; /* clear all set shares per con */ } showtotals(); ready(); entercell(sys.cell); /* inverse vol now invalid */ break; case F08 : leavecell(sys.cell); switch( choice(7, utilchoice)) { case 1 : getdir(); break; case 2 : bonusissue(); wait(); calcall(); showall(); totals(); showtotals(); ready(); break; case 3 : cashissue(); wait(); calcall(); showall(); totals(); showtotals(); ready(); break; case 4: switch( choice(3,resolutionchoice)) { case 1: numpts = 10; break; case 2: numpts = 15; break; case 3: numpts = 30; break; } break; case 5:switch (choice(3,printchoice)) { case 1: printdetails(); break; case 2: demo1();break; case 3: demo1(); break; } break; case 6: filedelete(); break; case 7 : reinstall(); } entercell(sys.cell); break; case F09 : switch (sys.screen) { case SCREEN1 : leavecell(sys.cell); if (sys.display == HELDS) sys.display = DELTAS; else sys.display = HELDS; if (sys.cell.row >= 8) sys.cell.col = MONTH; textcolor(sys.graphics.colors.heading); textbackground(sys.graphics.colors.databack); drawheadings(); showall(); showtotals(); entercell(sys.cell);break; case SCREEN2 : break; case SCREEN3 : leavecell(sys.cell); if (sys.display == INVVOL) sys.display = OVERVALUED; else sys.display = INVVOL; textcolor(sys.graphics.colors.heading); textbackground(sys.graphics.colors.databack); drawheadings(); showall(); showtotals(); entercell(sys.cell);break; } break; case F10 : switch (choice(3,quitchoice)) { case 0 : break; case 1 : wait(); textcolor(LIGHTGRAY); textbackground(BLACK); savesys(); clrscr(); gotoxy(2,2); cprintf(" The Option Analyst is a product of"); gotoxy(2,3); cprintf(" EFAM RESOURCES Pty. Ltd.\n"); retcursor(); exit(0); break; case 2 : demo(); break; case 3 : break; } break; } }