Example #1
0
void split_redraw(void) 
{
  int   max;
  int   at;
  ip_t *addr;
  char  newLine[MAX_LINE_SIZE];
  int   i;

#if DEBUG
  fprintf(stderr, "split_redraw()\n"); 
#endif

  /* 
   * If there is less lines than last time, we delete them
   * TEST THIS PLEASE
   */
  max = net_max();
  for (i=LineCount; i>max; i--) {
    printf("-%d\n", i);
    LineCount--;
  }

  /*
   * For each line, we compute the new one and we compare it to the old one
   */
  for(at = 0; at < max; at++) {
    addr = net_addr(at);
    if(addrcmp((void*)addr, (void*)&unspec_addr, af)) {
      char str[256], *name;
      if (!(name = dns_lookup(addr)))
        name = strlongip(addr);
      if (show_ips) {
        snprintf(str, sizeof(str), "%s %s", name, strlongip(addr));
        name = str;
      }
      /* May be we should test name's length */
      snprintf(newLine, sizeof(newLine), "%s %d %d %d %d %d %d", name,
               net_loss(at),
               net_returned(at), net_xmit(at),
               net_best(at) /1000, net_avg(at)/1000,
               net_worst(at)/1000);
    } else {
      sprintf(newLine, "???");
    }

    if (strcmp(newLine, Lines[at]) == 0) {
      /* The same, so do nothing */
#if DEBUG
      printf("SAME LINE\n");
#endif
    } else {
      printf("%d %s\n", at+1, newLine);
      fflush(stdout);
      strcpy(Lines[at], newLine);
      if (LineCount < (at+1)) {
	LineCount = at+1;
      }
    }
  }
}
Example #2
0
void update_tree_row(int row, GtkTreeIter *iter)
{
  ip_t *addr;
  char str[256], *name;

  addr = net_addr(row);
  name = "???";
  if ( addrcmp( (void *) addr, (void *) &unspec_addr, af ) != 0 ) {
    name = dns_lookup(addr);
    if(!name) {
      sprintf(str, "%s", strlongip( addr ));
      name = str;
    }
  }

  gtk_list_store_set(ReportStore, iter,
    COL_HOSTNAME, name,
    COL_LOSS, (float)(net_loss(row)/1000.0),

    COL_RCV, net_returned(row),
    COL_SNT, net_xmit(row),

    COL_LAST, net_last(row)/1000,
    COL_BEST, net_best(row)/1000,
    COL_AVG, net_avg(row)/1000,
    COL_WORST, net_worst(row)/1000,
    COL_STDEV, (float)(net_stdev(row)/1000.0),
    
    COL_COLOR, net_up(row) ? "black" : "red",

    -1);
}
Example #3
0
void gc_redraw(void) {
	gc_keyaction(cr_dispatch_event());
	if (paused)
		return;

	int i, at;
	int min = net_min();
	int max = net_max();
	int hops = max - min /* + 1 */;
	if (!hops)
		hops++;

	cr_set_hops(hops, min);

	struct timeval now;
	gettimeofday(&now, NULL);
	int dt = (now.tv_sec - lasttime.tv_sec) * USECONDS + (now.tv_usec - lasttime.tv_usec);
	lasttime = now;

	if (dt < timeout) {
		int pings = net_xmit(min);
		for (at = min + 1; at < max; at++)
			if (net_xmit(at) != pings)
					return;
		if (pings > num_pings)
			num_pings = pings;
		else
			return;
	}

	if (params.enable_legend) {
		static int hi_max;
		if (!hostinfo_max)
			   hi_max = 0;
		if (hostinfo_max > hi_max) {
			hi_max = hostinfo_max;
			curses_cols = cr_recalc(hostinfo_max);
			pr_lastd();
		}
		cr_init_legend();
		cr_print_legend_header(display_mode ? legend_hd[LEGEND_HEADER] : legend_hd[LEGEND_HEADER_STATIC]);
	}

	for (i = 0, at = min; i < hops; i++, at++) {
		ip_t *addr = net_addr(at);

		if (addrcmp((void *)addr, (void *)&unspec_addr, af) != 0) {
			int *saved = net_saved_pings(at);
			int saved_ndx = SAVED_PINGS - 2;	// waittime ago
			if (params.jitter_graph) {
				// jitter, defined as "tN - tN-1" (net.c)
				if ((saved[saved_ndx] < 0) || (saved[saved_ndx - 1] < 0))	// unsent, unknown, etc.
					data[i] = -1;
				else {
					int saved_jttr = saved[saved_ndx] - saved[saved_ndx - 1];
					data[i] = (saved_jttr < 0) ? -saved_jttr : saved_jttr;
				}
			} else
				data[i] = (saved[saved_ndx] >= 0) ? saved[saved_ndx] : -1;

			if (params.enable_legend) {
				// line+hop
				cr_print_hop(i);

				// hostinfo
				fill_hostinfo(at, addr);

				char *stat = buf + strlen(buf) + 1;
				// statistics
				if (display_mode) {
					mtr_gen_scale_gc();
					char *pos = stat;
					int j;
#ifdef UNICODE
					if (display_mode == 3) {
						for (j = SAVED_PINGS - curses_cols; j < SAVED_PINGS; j++) {
							*(wchar_t*)pos = mtr_curses_saved_wch(saved[j]);
							pos += sizeof(wchar_t);
						}
						*(wchar_t*)pos = L'\0';
					} else
#endif
					{
						for (j = SAVED_PINGS - curses_cols; j < SAVED_PINGS; j++)
							*pos++ = mtr_curses_saved_ch(saved[j]);
						*pos = 0;
					}
				} else
					mtr_fill_data(at, stat);
				cr_print_host(i, data[i], buf, stat);

				// mpls
				if (enablempls)
					gc_print_mpls(i, data[i], net_mpls(at));

				// multipath
				if (params.enable_multipath) {
					int j;
					for (j = 0; j < MAXPATH; j++) {
						ip_t *addrs = net_addrs(at, j);
						if (addrcmp((void *)addrs, (void *)addr, af) == 0)
							continue;
						if (addrcmp((void *)addrs, (void *)&unspec_addr, af) == 0)
							break;
						fill_hostinfo(at, addrs);
						cr_print_host(i, data[i], buf, NULL);
						if (enablempls)	// multipath+mpls
							gc_print_mpls(i, data[i], net_mplss(at, j));
					}
				}
			}
		} else	// empty hop
			if (params.enable_legend) {
				cr_print_hop(i);
				cr_print_host(i, 0, NULL, NULL);
			}
	}

	if (params.enable_legend)
		if (display_mode) {
			mtr_curses_scale_desc(legend_hd[LEGEND_FOOTER]);
			cr_print_legend_footer(legend_hd[LEGEND_FOOTER]);
		}

	cr_redraw(data);

	if (hops)
		timeout = POS_ROUND(((WaitTime * hops) / NUMHOSTS) * USECONDS);
}
Example #4
0
void split_redraw(void) 
{
  int   max;
  int   at;
  ip_t *addr, *addrs;
  char  newLine[MAX_LINE_SIZE];
  int   i;

#if DEBUG
  SPLIT_PRINT(("split_redraw()"));
#endif

  /* 
   * If there is less lines than last time, we delete them
   * TEST THIS PLEASE
   */
  max = net_max();
  for (i=LineCount; i>max; i--) {
    SPLIT_PRINT(("-%d", i));
    LineCount--;
  }

  /*
   * For each line, we compute the new one and we compare it to the old one
   */
  for(at = 0; at < max; at++) {
    addr = net_addr(at);
    if(addrcmp((void*)addr, (void*)&unspec_addr, af)) {
      char str[256], *name;
      if (!(name = dns_lookup(addr)))
        name = strlongip(addr);
      if (show_ips) {
        snprintf(str, sizeof(str), "%s\t%s", name, strlongip(addr));
        name = str;
      }
      /* May be we should test name's length */
      snprintf(newLine, sizeof(newLine), "%s\t%s\t%.1f\t%d\t%d\t%.1f\t%.1f\t%.1f\t%.1f", name, fmt_ipinfo(addr),
               net_loss(at)/1000.0,
               net_returned(at), net_xmit(at),
               net_best(at) /1000.0, net_avg(at)/1000.0,
               net_worst(at)/1000.0,
               net_stdev(at)/1000.0);
    } else {
      sprintf(newLine, "???");
    }

    if (strcmp(newLine, Lines[at]) == 0) {
      /* The same, so do nothing */
#if DEBUG
      SPLIT_PRINT(("SAME LINE"));
#endif
    } else {
      SPLIT_PRINT(("%d\t%s", at+1, newLine));

      if (strcmp(newLine, "???") != 0) {
        /* Multi path */
        for (i=0; i < MAXPATH; i++ ) {
          addrs = net_addrs(at, i);
          if ( addrcmp( (void *) addrs, (void *) addr, af ) == 0 ) continue;
          if ( addrcmp( (void *) addrs, (void *) &unspec_addr, af ) == 0 ) break;
          char *name;
 
          if (!(name = dns_lookup(addrs)))
            name = strlongip(addrs);
          if (show_ips) {
            SPLIT_PRINT(("-\t%d\t%d\t%s\t%s\t%s", at+1, i+1, name, strlongip(addrs), fmt_ipinfo(addrs)));
          } else {
            SPLIT_PRINT(("-\t%d\t%d\t%s\t%s", at+1, i+1, name, fmt_ipinfo(addrs)));
          }
        }
      }
 
      fflush(stdout);
      strcpy(Lines[at], newLine);
      if (LineCount < (at+1)) {
	LineCount = at+1;
      }
    }
  }
}