Exemple #1
0
static void hostmonhelp(void)
{
	move(LINES - 1, 1);
	scrollkeyhelp();
	sortkeyhelp();
	stdexitkeyhelp();
}
Exemple #2
0
static void initiftab(struct iftab *table)
{
	table->borderwin = newwin(LINES - 2, COLS, 1, 0);
	table->borderpanel = new_panel(table->borderwin);

	move(LINES - 1, 1);
	scrollkeyhelp();
	stdexitkeyhelp();
	wattrset(table->borderwin, BOXATTR);
	tx_box(table->borderwin, ACS_VLINE, ACS_HLINE);
	labelstats(table->borderwin);
	table->statwin = newwin(LINES - 4, COLS - 2, 2, 1);
	table->statpanel = new_panel(table->statwin);
	tx_stdwinset(table->statwin);
	wtimeout(table->statwin, -1);
	wattrset(table->statwin, STDATTR);
	tx_colorwin(table->statwin);
	wattrset(table->statwin, BOXATTR);
	wmove(table->borderwin, LINES - 3, 32 * COLS / 80);
	wprintw(table->borderwin,
		" Total, IP, NonIP, and BadIP are packet counts ");
}
Exemple #3
0
/*
 * 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();
}
int start_tcp_analysis_mon(struct SETTINGS* mySettings)
{
  WINDOW * statwin;
  WINDOW * msgwin;
  WINDOW * scanwin;
  WINDOW * breakwin;
  WINDOW * listwin;
  WINDOW * capturewin;

  PANEL * statpanel;
  PANEL * msgpanel;
  PANEL * scanpanel;
  PANEL * breakpanel;
  PANEL * listpanel;
  PANEL * capturepanel;

  int exitloop;

  int first_instance = 1;
  int paused = 0; // used to pause screen
  
  int ch;
  int break_pos = 0; // used to mark breakdown position
  int list_pos = 1; // used to mark list position
  
  int nodelist_win = 1;
  int curr_view = 0;
  int select_node = 0;
  int node_count = 0;  // tracks whether there's change
  
  char elapsed[10];
  
  struct timeval tv_start;
  struct timeval tv_curr;
  struct timeval tv_old;
  struct timeval tv_new;

  print_tcp_stat_screen(&statwin,&statpanel, mySettings->card_type, mySettings->interface);
  print_tcp_activity_overview_labels(&scanwin,&scanpanel, curr_view);
  print_tcp_breakdown_labels(&breakwin,&breakpanel, curr_view);
  print_tcp_nodelist_labels(&listwin,&listpanel);
  if (mySettings->capture_mode == CAPTURE_MODE_PLAYBACK)
    make_capture_controls(&capturewin, &capturepanel);
  
  update_panels();
  doupdate();

  move(LINES - 1, 1);
  pausekeyhelp();
  viewkeyhelp();
  changewinkeyhelp();
  scrollkeyhelp();
  stdexitkeyhelp();
  update_panels();
  doupdate();

  leaveok(statwin, TRUE);
  exitloop = 0;

  /** initialize listwin to have ACTIVE key focus **/
  reset_active_win(listwin, 1);
  
  gettimeofday(&tv_start,NULL);
  tv_old = tv_start;

  /*
   * Data Display Loop
   */
  while ((!exitloop) && (!sysexit)) {
    ch = ERR;
    if (check_for_keystroke() != ERR)
      ch = wgetch(statwin);
    if (ch != ERR) {
      switch (ch)
	{
	case KEY_UP:
	  if (!nodelist_win)
	    scrollbreakdownwin(SCROLLUP, select_node, &break_pos);
	  else{
	    scrollnodelistwin(listwin, SCROLLUP, &select_node, &list_pos);
	    /**after changing wireless node, reset the breakdown
	       window **/
	    del_panel(breakpanel);
	    delwin(breakwin);
	    update_panels();
	    doupdate();

	    print_tcp_breakdown_labels(&breakwin,&breakpanel, curr_view);
	    if (nodelist_win){
	      reset_active_win(breakwin,0);
	      reset_active_win(listwin,1);
	    }
	    else{
	      reset_active_win(listwin,0);
	      reset_active_win(breakwin,1);
	    }
	    break_pos = 0;
	  }
	  break;
	case KEY_DOWN:
	  if (!nodelist_win)
	    scrollbreakdownwin(SCROLLDOWN, select_node, &break_pos);
	  else{
	    scrollnodelistwin(listwin, SCROLLDOWN, &select_node, &list_pos);
	    /**after changing wireless node, reset the breakdown
	       window **/
	    del_panel(breakpanel);
	    delwin(breakwin);
	    update_panels();
	    doupdate();

	    print_tcp_breakdown_labels(&breakwin,&breakpanel, curr_view);
	    if (nodelist_win){
	      reset_active_win(breakwin,0);
	      reset_active_win(listwin,1);
	    }
	    else{
	      reset_active_win(listwin,0);
	      reset_active_win(breakwin,1);
	    }
	    break_pos = 0;
	  }
	  break;
	case 12:
	case 'l':
	case 'L':
	  refresh_screen();
	  break;
	case 'p':
	case 'P':
	  if (mySettings->capture_mode == CAPTURE_MODE_PLAYBACK){
	    parse_capture_key(mySettings, ch);
	    break;
	  }
	  switch (paused)
	    {
	    case 0:
	      show_paused_win(&msgwin,&msgpanel,
		    "Analysis PAUSED...", "P-continue | X-Exit");
	      update_panels();
	      doupdate();
	      paused = 1;
	      break;
	    case 1:
	      del_panel(msgpanel);
	      delwin(msgwin);
	      update_panels();
	      doupdate();
	      refresh_screen();
	      paused = 0;
	      break;
	    }
	  break;
	case 'v':
	case 'V':
	  del_panel(breakpanel);
	  delwin(breakwin);
	  if (curr_view == PERF_BANDWIDTH){
	    curr_view = CONNECTIONS;
	  }
	  else{
	    curr_view++;
	  }
	  print_tcp_breakdown_labels(&breakwin,&breakpanel, curr_view);
	  if (nodelist_win){
	    reset_active_win(breakwin,0);
	    reset_active_win(listwin,1);
	  }
	  else{
	    reset_active_win(listwin,0);
	    reset_active_win(breakwin,1);
	  }
	  update_panels();
	  doupdate();
	  break;
	case 'w':
	case 'W':
	  if (nodelist_win){
	    nodelist_win = 0;
	    reset_active_win(listwin,0);
	    reset_active_win(breakwin,1);
	  }
	  else{
	    nodelist_win = 1;
	    reset_active_win(breakwin,0);
	    reset_active_win(listwin,1);
	  }
	  break;
	case 'Q':
	case 'q':
	case 'X':
	case 'x':
	case 24:
	case 27:
	  if (paused){
	    del_panel(msgpanel);
	    delwin(msgwin);
	  }
	  exitloop = 1;
	  break;
	default:
	  if (mySettings->capture_mode == CAPTURE_MODE_PLAYBACK){
	    parse_capture_key(mySettings, ch);
	  }
	  break;
	}	  
    }
    if(!paused){
      gettimeofday(&tv_new, NULL);

      if (GUI_DEBUG) fprintf(stderr,"doing packet stuff\n");

      /**
       * if it is first instance, and we haven't found a base
       * station yet, then just loop on, waiting for perhaps some
       * keystroke that will find a base channel for us...
       **/
      if (first_instance){
	if (get_detailed_snapshot()->bss_list_top != NULL){
	  first_instance = 0;
	}
	else{
	  continue;
	}
      }

      print_tcp_activity_overview_results(scanwin, select_node, curr_view);
      print_tcp_breakdown_results(breakwin, curr_view, select_node, break_pos);
      print_tcp_nodelist_results(listwin, &select_node, list_pos);      

      if (get_detailed_snapshot()->bss_list_top->num != node_count){
	del_panel(breakpanel);
	delwin(breakwin);
	del_panel(listpanel);
	delwin(listwin);
	if (mySettings->capture_mode == CAPTURE_MODE_PLAYBACK){
	  del_panel(capturepanel);
	  delwin(capturewin);
	}
	update_panels();
	doupdate();
	
	print_tcp_breakdown_labels(&breakwin,&breakpanel, curr_view);
	print_tcp_nodelist_labels(&listwin,&listpanel);
	if (nodelist_win){
	  reset_active_win(breakwin,0);
	  reset_active_win(listwin,1);
	}
	else{
	  reset_active_win(listwin,0);
	  reset_active_win(breakwin,1);
	}
	if (mySettings->capture_mode == CAPTURE_MODE_PLAYBACK)
	  make_capture_controls(&capturewin, &capturepanel);
	node_count = get_detailed_snapshot()->bss_list_top->num;
	if (node_count == 1){
	  del_panel(scanpanel);
	  delwin(scanwin);
	  update_panels();
	  doupdate();

	  print_tcp_activity_overview_labels(&scanwin,&scanpanel, curr_view);
	  select_node = 0;
	}
      }
      
      if (mySettings->capture_mode == CAPTURE_MODE_PLAYBACK)
	print_capture_update(capturewin, mySettings);
      
      wattrset(scanwin, HIGHATTR);
      gettimeofday(&tv_curr, NULL);
      get_elapsed_time(&tv_curr, &tv_start, elapsed);
      mvwprintw(scanwin, LINES - 7, 15, "%s", elapsed);
    }
  } // end loop
  del_panel(statpanel);
  delwin(statwin);
  del_panel(scanpanel);
  delwin(scanwin);
  del_panel(breakpanel);
  delwin(breakwin);
  del_panel(listpanel);
  delwin(listwin);
  if (mySettings->capture_mode == CAPTURE_MODE_PLAYBACK){
    del_panel(capturepanel);
    delwin(capturewin);
  }

  update_panels();
  doupdate();
  if (sysexit){
    if (paused){
      del_panel(msgpanel);
      delwin(msgwin);
    }
    sysexit = 0;
    return (0);
  }
  else{
    return (1);
  }
}
Exemple #5
0
void packet_size_breakdown(struct OPTIONS *options, char *ifname,
                           int facilitytime, struct filterstate *ofilter)
{
    WINDOW *win;
    PANEL *panel;
    WINDOW *borderwin;
    PANEL *borderpanel;

    struct ifstat_brackets brackets[20];
    unsigned int interval;

    int ch;

    int fd;

    char buf[MAX_PACKET_SIZE];
    int br;
    char *ipacket;
    char iface[10];
    unsigned int mtu;

    struct sockaddr_ll fromaddr;
    unsigned short linktype;
    int pkt_result;

    struct timeval tv;
    unsigned long starttime, startlog, timeint;
    unsigned long now;
    unsigned long long unow;
    unsigned long updtime = 0;
    unsigned long long updtime_usec = 0;

    int logging = options->logging;
    FILE *logfile = NULL;

    struct promisc_states *promisc_list;

    char msgstring[80];

    if (!facility_active(PKTSIZEIDFILE, ifname))
        mark_facility(PKTSIZEIDFILE, "Packet size breakdown", ifname);
    else {
        snprintf(msgstring, 80,
                 "Packet sizes already being monitored on %s", ifname);
        write_error(msgstring, daemonized);
        return;
    }

    if (!iface_supported(ifname)) {
        err_iface_unsupported();
        unmark_facility(PKTSIZEIDFILE, ifname);
        return;
    }
    if (!iface_up(ifname)) {
        err_iface_down();
        unmark_facility(PKTSIZEIDFILE, ifname);
        return;
    }
    borderwin = newwin(LINES - 2, COLS, 1, 0);
    borderpanel = new_panel(borderwin);

    wattrset(borderwin, BOXATTR);
    tx_box(borderwin, ACS_VLINE, ACS_HLINE);
    mvwprintw(borderwin, 0, 1, " Packet Distribution by Size ");

    win = newwin(LINES - 4, COLS - 2, 2, 1);
    panel = new_panel(win);

    tx_stdwinset(win);
    wtimeout(win, -1);
    wattrset(win, STDATTR);
    tx_colorwin(win);

    move(LINES - 1, 1);
    stdexitkeyhelp();

    initialize_brackets(ifname, brackets, &interval, &mtu, win);

    mvwprintw(win, 1, 1, "Packet size brackets for interface %s", ifname);
    wattrset(win, BOXATTR);

    mvwprintw(win, 4, 1, "Packet Size (bytes)");
    mvwprintw(win, 4, 26, "Count");
    mvwprintw(win, 4, 36, "Packet Size (bytes)");
    mvwprintw(win, 4, 60, "Count");
    wattrset(win, HIGHATTR);

    if (logging) {
        if (strcmp(current_logfile, "") == 0) {
            snprintf(current_logfile, 80, "%s-%s.log", PKTSIZELOG, ifname);

            if (!daemonized)
                input_logfile(current_logfile, &logging);
        }
    }

    if (logging) {
        opentlog(&logfile, current_logfile);

        if (logfile == NULL)
            logging = 0;
    }
    if (logging)
        signal(SIGUSR1, rotate_size_log);

    writelog(logging, logfile,
             "******** Packet size distribution facility started ********");

    exitloop = 0;
    gettimeofday(&tv, NULL);
    starttime = startlog = timeint = tv.tv_sec;

    open_socket(&fd);

    if (fd < 0) {
        unmark_facility(PKTSIZEIDFILE, ifname);
        return;
    }

    if ((first_active_facility()) && (options->promisc)) {
        init_promisc_list(&promisc_list);
        save_promisc_list(promisc_list);
        srpromisc(1, promisc_list);
        destroy_promisc_list(&promisc_list);
    }

    adjust_instance_count(PROCCOUNTFILE, 1);
    active_facility_countfile[0] = '\0';

    do {
        gettimeofday(&tv, NULL);
        now = tv.tv_sec;
        unow = tv.tv_sec * 1e+6 + tv.tv_usec;

        if (((options->updrate != 0)
             && (now - updtime >= options->updrate))
            || ((options->updrate == 0)
                && (unow - updtime_usec >= DEFAULT_UPDATE_DELAY))) {
            update_panels();
            doupdate();
            updtime = now;
            updtime_usec = unow;
        }
        if (now - timeint >= 5) {
            printelapsedtime(starttime, now, LINES - 3, 1, borderwin);
            timeint = now;
        }
        if ((now - startlog >= options->logspan) && (logging)) {
            write_size_log(brackets, now - starttime, ifname, mtu,
                           logfile);
            startlog = now;
        }
        check_rotate_flag(&logfile, logging);

        if ((facilitytime != 0)
            && (((now - starttime) / 60) >= facilitytime))
            exitloop = 1;

        getpacket(fd, buf, &fromaddr, &ch, &br, iface, win);

        if (ch != ERR) {
            switch (ch) {
            case 12:
            case 'l':
            case 'L':
                tx_refresh_screen();
                break;
            case 'x':
            case 'X':
            case 'q':
            case 'Q':
            case 27:
            case 24:
                exitloop = 1;
            }
        }
        if (br > 0) {
            pkt_result =
                processpacket(buf, &ipacket, &br, NULL, NULL, NULL,
                              &fromaddr, &linktype, ofilter,
                              MATCH_OPPOSITE_USECONFIG, iface, ifname);

            if (pkt_result != PACKET_OK)
                continue;

            update_size_distrib(br, brackets, interval, win);
        }
    } while (!exitloop);

    if (logging) {
        signal(SIGUSR1, SIG_DFL);
        write_size_log(brackets, now - starttime, ifname, mtu, logfile);
        writelog(logging, logfile,
                 "******** Packet size distribution facility stopped ********");
        fclose(logfile);
    }
    close(fd);

    if ((options->promisc) && (is_last_instance())) {
        load_promisc_list(&promisc_list);
        srpromisc(0, promisc_list);
        destroy_promisc_list(&promisc_list);
    }

    adjust_instance_count(PROCCOUNTFILE, -1);

    del_panel(panel);
    delwin(win);
    del_panel(borderpanel);
    delwin(borderwin);
    unmark_facility(PKTSIZEIDFILE, ifname);
    strcpy(current_logfile, "");
}
Exemple #6
0
void start_ids_mon(char *iface)
{
  WINDOW *statwin;
  PANEL *statpanel;

  WINDOW *overallwin;
  PANEL *overallpanel;

  WINDOW *helpwin;
  PANEL *helppanel;

  /** stat display information **/
  int stat_page = 0;
  
  int ch;
  int exitloop;
  int paused = 0;

  ids_t *ids_info = NULL;

  MAX_STAT_ROW = LINES * 0.6 - 2;

  overallwin = newwin(LINES -2, COLS, 1, 0);
  overallpanel = new_panel(overallwin);
  stdwinset(overallwin);
  wtimeout(overallwin, -1);
  wattrset(overallwin, BOXATTR);
  colorwin(overallwin);
  box(overallwin, ACS_VLINE, ACS_HLINE);
  
  /** make the ids list based on mac addresses **/
  statwin = newwin(LINES * 0.6, COLS, 1, 0);
  statpanel = new_panel(statwin);
  stdwinset(statwin);
  wtimeout(statwin, -1);
  wattrset(statwin, BOXATTR);
  colorwin(statwin);
  box(statwin, ACS_VLINE, ACS_HLINE);
  wmove(statwin, 0, 1);
  wprintw(statwin, " IDS Statistics for %s ", iface);
  print_ids_labels(statwin);
  print_ids_details(statwin, NULL, 0);

  /** make ids help window **/
  helpwin = newwin(LINES * 0.4 - 1, COLS, LINES * 0.6 + 1, 0);
  helppanel = new_panel(helpwin);
  wattrset(helpwin, BOXATTR);
  colorwin(helpwin);
  box(helpwin, ACS_VLINE, ACS_HLINE);
  print_help_win(helpwin);
  
  /** make the bottom key binding panel **/
  move(LINES - 1, 1);
  scrollkeyhelp();
  stdexitkeyhelp();

  update_panels();
  doupdate();
  
  leaveok(statwin, TRUE);
  
  exitloop = 1;

  /**
   * Data-gathering loop
   */
  while(!exitloop){
    ch = ERR;
    if (check_for_keystroke() != ERR)
      ch = wgetch(statwin);
    if (ch != ERR) {
      switch (ch)
	{
	case KEY_UP:
	  if (stat_page > 0){
	    stat_page --;
	    colorwin(statwin);
	  }
	  break;
	case KEY_DOWN:
	  if (((stat_page +1) * MAX_STAT_ROW) < ids_info->node_count){
	    stat_page ++;
	    colorwin(statwin);
	  } 
	  break;
	case KEY_PPAGE:
	case '-':
	  //scroll_nodewin(nodewin, SCROLLDOWN);
	  //	    pageethwin(nodewin, SCROLLDOWN);
	  break;
	case KEY_NPAGE:
	case ' ':
	  //scroll_nodewin(nodewin, SCROLLUP);
	  //	    pageethwin(nodewin, SCROLLUP);
	  break;
	case 'p':
	case 'P':
	  switch (paused)
	    {
	    case 0:
	      paused = 1;
	      break;
	    case 1:
	      paused = 0;
	      break;
	    }    
	  //	  markactive(curwin, nodeborder, paused);
	  update_panels();
	  doupdate();
	  break;
	case 12:
	case 'l':
	case 'L':
	  refresh_screen();
	  break;
	    
	case 'Q':
	case 'q':
	case 'X':
	case 'x':
	case 24:
	case 27:
	  exitloop = 1;
	  break;
	default:
	  break;
	}
    }
    if (!paused){
      // blah do stuff
      print_ids_details(statwin, ids_info, stat_page);
    }
  } // end loop
  del_panel(statpanel);
  delwin(statwin);

  del_panel(helppanel);
  delwin(helpwin);

  del_panel(overallpanel);
  delwin(overallwin);
  
  update_panels();
  doupdate();
}