Example #1
0
void mtr_curses_graph(int startstat, int cols) 
{
	int max, at, y;
	ip_t * addr;
	char* name;

	max = net_max();

	for (at = display_offset; at < max; at++) {
		printw("%2d. ", at+1);

		addr = net_addr(at);
		if (!addr) {
			printw("???\n");
			continue;
		}

		if (! net_up(at))
			attron(A_BOLD);
		if (addrcmp((void *) addr, (void *) &unspec_addr, af)) {
#ifdef IPINFO
			if (is_printii())
				printw(fmt_ipinfo(addr));
#endif
			name = dns_lookup(addr);
			printw("%s", name?name:strlongip(addr));
		} else
			printw("???");
		attroff(A_BOLD);

		getyx(stdscr, y, __unused_int);
		move(y, startstat);

		printw(" ");
		mtr_fill_graph(at, cols);
		printw("\n");
	}
}
Example #2
0
void report_close(void) 
{
  int i, j, at, max, z, w;
  struct mplslen *mpls, *mplss;
  ip_t *addr;
  ip_t *addr2 = NULL;  
  char name[81];
  char buf[1024];
  char fmt[16];
  int len=0;
  int len_hosts = 33;

  if (reportwide)
  {
    // get the longest hostname
    len_hosts = strlen(LocalHostname);
    max = net_max();
    at  = net_min();
    for (; at < max; at++) {
      int nlen;
      addr = net_addr(at);
      if ((nlen = snprint_addr(name, sizeof(name), addr)))
        if (len_hosts < nlen)
          len_hosts = nlen;
    }
  }
  
#ifndef NO_IPINFO
  int len_tmp = len_hosts;
  if (ipinfo_no >= 0) {
    ipinfo_no %= iiwidth_len;
    if (reportwide) {
      len_hosts++;    // space
      len_tmp   += get_iiwidth();
      if (!ipinfo_no)
        len_tmp += 2; // align header: AS
    }
  }
  snprintf( fmt, sizeof(fmt), "HOST: %%-%ds", len_tmp);
#else
  snprintf( fmt, sizeof(fmt), "HOST: %%-%ds", len_hosts);
#endif
  snprintf(buf, sizeof(buf), fmt, LocalHostname);
  len = reportwide ? strlen(buf) : len_hosts;
  for( i=0; i<MAXFLD; i++ ) {
    j = fld_index[fld_active[i]];
    if (j < 0) continue;

    snprintf( fmt, sizeof(fmt), "%%%ds", data_fields[j].length );
    snprintf( buf + len, sizeof(buf), fmt, data_fields[j].title );
    len +=  data_fields[j].length;
  }
  printf("%s\n",buf);

  max = net_max();
  at  = net_min();
  for(; at < max; at++) {
    addr = net_addr(at);
    mpls = net_mpls(at);
    snprint_addr(name, sizeof(name), addr);

#ifndef NO_IPINFO
    if (is_printii()) {
      snprintf(fmt, sizeof(fmt), " %%2d. %%s%%-%ds", len_hosts);
      snprintf(buf, sizeof(buf), fmt, at+1, fmt_ipinfo(addr), name);
    } else {
#endif
    snprintf( fmt, sizeof(fmt), " %%2d.|-- %%-%ds", len_hosts);
    snprintf(buf, sizeof(buf), fmt, at+1, name);
#ifndef NO_IPINFO
    }
#endif
    len = reportwide ? strlen(buf) : len_hosts;  
    for( i=0; i<MAXFLD; i++ ) {
      j = fld_index[fld_active [i]];
      if (j < 0) continue;

      /* 1000.0 is a temporay hack for stats usec to ms, impacted net_loss. */
      if( index( data_fields[j].format, 'f' ) ) {
        snprintf( buf + len, sizeof(buf), data_fields[j].format,
		data_fields[j].net_xxx(at) /1000.0 );
      } else {
        snprintf( buf + len, sizeof(buf), data_fields[j].format,
		data_fields[j].net_xxx(at) );
      }
      len +=  data_fields[j].length;
    }
    printf("%s\n",buf);

    /* This feature shows 'loadbalances' on routes */

    /* z is starting at 1 because addrs[0] is the same that addr */
    for (z = 1; z < MAXPATH ; z++) {
      addr2 = net_addrs(at, z);
      mplss = net_mplss(at, z);
      int found = 0;
      if ((addrcmp ((void *) &unspec_addr, (void *) addr2, af)) == 0)
        break;
      for (w = 0; w < z; w++)
        /* Ok... checking if there are ips repeated on same hop */
        if ((addrcmp ((void *) addr2, (void *) net_addrs (at,w), af)) == 0) {
           found = 1;
           break;
        }   

      if (!found) {
  
#ifndef NO_IPINFO
        if (is_printii()) {
          if (mpls->labels && z == 1 && enablempls)
            print_mpls(mpls);
          snprint_addr(name, sizeof(name), addr2);
          printf("     %s%s\n", fmt_ipinfo(addr2), name);
          if (enablempls)
            print_mpls(mplss);
        } else {
#else
        int k;
        if (mpls->labels && z == 1 && enablempls) {
          for (k=0; k < mpls->labels; k++) {
            printf("    |  |+-- [MPLS: Lbl %lu Exp %u S %u TTL %u]\n", mpls->label[k], mpls->exp[k], mpls->s[k], mpls->ttl[k]);
          }
        }

        if (z == 1) {
          printf ("    |  `|-- %s\n", strlongip(addr2));
          for (k=0; k < mplss->labels && enablempls; k++) {
            printf("    |   +-- [MPLS: Lbl %lu Exp %u S %u TTL %u]\n", mplss->label[k], mplss->exp[k], mplss->s[k], mplss->ttl[k]);
          }
        } else {
          printf ("    |   |-- %s\n", strlongip(addr2));
          for (k=0; k < mplss->labels && enablempls; k++) {
            printf("    |   +-- [MPLS: Lbl %lu Exp %u S %u TTL %u]\n", mplss->label[k], mplss->exp[k], mplss->s[k], mplss->ttl[k]);
          }
        }
#endif
#ifndef NO_IPINFO
        }
#endif
      }
    }

    /* No multipath */
#ifndef NO_IPINFO
    if (is_printii()) {
      if (mpls->labels && z == 1 && enablempls)
        print_mpls(mpls);
    } else {
#else
    if(mpls->labels && z == 1 && enablempls) {
      int k;
      for (k=0; k < mpls->labels; k++) {
        printf("    |   +-- [MPLS: Lbl %lu Exp %u S %u TTL %u]\n", mpls->label[k], mpls->exp[k], mpls->s[k], mpls->ttl[k]);
      }
    }
#endif
#ifndef NO_IPINFO
    }
#endif
  }
}
Example #3
0
void mtr_curses_redraw(void)
{
  int maxx;
  int startstat;
  int rowstat;
  time_t t;

  int i, j;
  int  hd_len = 0;
  char buf[1024];
  char fmt[16];
  

  erase();
  getmaxyx(stdscr, __unused_int, maxx);

  rowstat = 5;

  move(0, 0);
  attron(A_BOLD);
  pwcenter("My traceroute  [v" MTR_VERSION "]");
  attroff(A_BOLD);

  mvprintw(1, 0, "%s (%s)", LocalHostname, net_localaddr());
  /*
  printw("(tos=0x%X ", tos);
  printw("psize=%d ", packetsize );
  printw("bitpattern=0x%02X)", (unsigned char)(abs(bitpattern)));
  if( cpacketsize > 0 ){
    printw("psize=%d ", cpacketsize);
  } else {
    printw("psize=rand(%d,%d) ",MINPACKET, -cpacketsize);
  }
  if( bitpattern>=0 ){
    printw("bitpattern=0x%02X)", (unsigned char)(bitpattern));
  } else {
    printw("bitpattern=rand(0x00-FF))");
  }
  */
  time(&t);
  mvprintw(1, maxx-25, ctime(&t));

  printw("Keys:  ");
  attron(A_BOLD); printw("H"); attroff(A_BOLD); printw("elp   ");
  attron(A_BOLD); printw("D"); attroff(A_BOLD); printw("isplay mode   ");
  attron(A_BOLD); printw("R"); attroff(A_BOLD); printw("estart statistics   ");
  attron(A_BOLD); printw("O"); attroff(A_BOLD); printw("rder of fields   ");
  attron(A_BOLD); printw("q"); attroff(A_BOLD); printw("uit\n");
  
  if (display_mode == 0) {
    for (i=0; i < MAXFLD; i++ ) {
	j = fld_index[fld_active[i]];
	if (j < 0) continue;

	sprintf( fmt, "%%%ds", data_fields[j].length );
        sprintf( buf + hd_len, fmt, data_fields[j].title );
	hd_len +=  data_fields[j].length;
    }
    attron(A_BOLD);
    mvprintw(rowstat - 1, 0, " Host");
    mvprintw(rowstat - 1, maxx-hd_len-1, "%s", buf);
    mvprintw(rowstat - 2, maxx-hd_len-1, "   Packets               Pings");
    attroff(A_BOLD);

    move(rowstat, 0);
    mtr_curses_hosts(maxx-hd_len-1);

  } else {
    char msg[80];
    int padding = 30;
#ifdef IPINFO
    if (is_printii())
      padding += get_iiwidth();
#endif
    int max_cols = maxx<=SAVED_PINGS+padding ? maxx-padding : SAVED_PINGS;
    startstat = padding - 2;

    sprintf(msg, " Last %3d pings", max_cols);
    mvprintw(rowstat - 1, startstat, msg);
    
    attroff(A_BOLD);
    move(rowstat, 0);

    mtr_gen_scale();
    mtr_curses_graph(startstat, max_cols);

    printw("\n");
    attron(A_BOLD);
    printw("Scale:");
    attroff(A_BOLD);
    
    for (i = 0; i < NUM_FACTORS-1; i++) {
      printw("  ");
      attrset(block_col[i+1]);
      printw("%c", block_map[i]);
      attrset(A_NORMAL);
      printw(":%d ms", block_map[i], scale[i]/1000);
    }
    printw("  ");
    attrset(block_col[NUM_FACTORS]);
    printw("%c", block_map[NUM_FACTORS-1]);
    attrset(A_NORMAL);
  }

  refresh();
}
Example #4
0
void mtr_curses_hosts(int startstat) 
{
  int max;
  int at;
  struct mplslen *mpls, *mplss;
  ip_t *addr, *addrs;
  int y;
  char *name;

  int i, j, k;
  int hd_len;
  char buf[1024];

  max = net_max();

  for(at = net_min () + display_offset; at < max; at++) {
    printw("%2d. ", at + 1);
    addr = net_addr(at);
    mpls = net_mpls(at);

    if( addrcmp( (void *) addr, (void *) &unspec_addr, af ) != 0 ) {
      name = dns_lookup(addr);
      if (! net_up(at))
	attron(A_BOLD);
#ifdef IPINFO
      if (is_printii())
        printw(fmt_ipinfo(addr));
#endif
      if(name != NULL) {
        if (show_ips) printw("%s (%s)", name, strlongip(addr));
        else printw("%s", name);
      } else {
	printw("%s", strlongip( addr ) );
      }
      attroff(A_BOLD);

      getyx(stdscr, y, __unused_int);
      move(y, startstat);

      /* net_xxx returns times in usecs. Just display millisecs */
      hd_len = 0;
      for( i=0; i<MAXFLD; i++ ) {
	/* Ignore options that don't exist */
	/* On the other hand, we now check the input side. Shouldn't happen, 
	   can't be careful enough. */
	j = fld_index[fld_active[i]];
	if (j == -1) continue; 

	/* temporay hack for stats usec to ms... */
	if( index( data_fields[j].format, 'f' ) ) {
	  sprintf(buf + hd_len, data_fields[j].format,
		data_fields[j].net_xxx(at) /1000.0 );
	} else {
	  sprintf(buf + hd_len, data_fields[j].format,
		data_fields[j].net_xxx(at) );
	}
	hd_len +=  data_fields[j].length;
      }
      buf[hd_len] = 0;
      printw("%s", buf);

      for (k=0; k < mpls->labels && enablempls; k++) {
        if((k+1 < mpls->labels) || (mpls->labels == 1)) {
           /* if we have more labels */
           printw("\n    [MPLS: Lbl %lu Exp %u S %u TTL %u]", mpls->label[k], mpls->exp[k], mpls->s[k], mpls->ttl[k]);
        } else {
           /* bottom label */
           printw("\n    [MPLS: Lbl %lu Exp %u S %u TTL %u]", mpls->label[k], mpls->exp[k], mpls->s[k], mpls->ttl[k]);
        }
      }

      /* Multi path */
      for (i=0; i < MAXPATH; i++ ) {
        addrs = net_addrs(at, i);
        mplss = net_mplss(at, i);
	if ( addrcmp( (void *) addrs, (void *) addr, af ) == 0 ) continue;
	if ( addrcmp( (void *) addrs, (void *) &unspec_addr, af ) == 0 ) break;

        name = dns_lookup(addrs);
        if (! net_up(at)) attron(A_BOLD);
        printw("\n    ");
#ifdef IPINFO
        if (is_printii())
          printw(fmt_ipinfo(addrs));
#endif
        if (name != NULL) {
	  if (show_ips) printw("%s (%s)", name, strlongip(addrs));
	  else printw("%s", name);
        } else {
	  printw("%s", strlongip( addrs ) );
        }
        for (k=0; k < mplss->labels && enablempls; k++) {
          printw("\n    [MPLS: Lbl %lu Exp %u S %u TTL %u]", mplss->label[k], mplss->exp[k], mplss->s[k], mplss->ttl[k]);
        }
        attroff(A_BOLD);
      }

    } else {
      printw("???");
    }

    printw("\n");
  }
  move(2, 0);
}
Example #5
0
void mtr_curses_hosts(int startstat) 
{
  int max;
  int at;
  struct mplslen *mpls, *mplss;
  ip_t *addr, *addrs;
  int y;
  char *name;

  char *country,*province,*city,*district,*isp,*type,*desc;
  int icountry,iprovince,icity,idistrict,iisp,itype,idesc;

  int i, j, k;
  int hd_len;
  char buf[1024];

  max = net_max();

  for(at = net_min () + display_offset; at < max; at++) {
    printw("%2d. ", at + 1);
    addr = net_addr(at);
    mpls = net_mpls(at);

    if( addrcmp( (void *) addr, (void *) &unspec_addr, af ) != 0 ) {
      name = dns_lookup(addr);
      if (! net_up(at))
	attron(A_BOLD);
#ifdef IPINFO
      if (is_printii())
        printw(fmt_ipinfo(addr));
#endif
      if(name != NULL) {
        if (show_ips) printw("%s (%s)", name, strlongip(addr));
        else printw("%s", name);
      } else {
	printw("%s", strlongip( addr ) );
      }
      attroff(A_BOLD);

      getyx(stdscr, y, __unused_int);

#ifdef ENABLE_BILIIP
      if (ip_resolve) {
      long key = biliip_query(biliip,ntohl(*(unsigned long *)addr));
      if (key != 0)
      {
        if (biliip->index_ptr[key] == 0)
        {
          biliip->ptr = BILIIP_BASE_PTR+(biliip->nCount*2+key-1)*sizeof(int);
          biliip->index_ptr[key] = htonl(*(int *)(biliip->mmap+biliip->ptr));
        }
        biliip->ptr = biliip->index_ptr[key]+4;

        country = biliip_getstr(biliip,&icountry);
        province = biliip_getstr(biliip,&iprovince);
        city = biliip_getstr(biliip,&icity);
        district = biliip_getstr(biliip,&idistrict);
        isp = biliip_getstr(biliip,&iisp);
        type = biliip_getstr(biliip,&itype);
        desc = biliip_getstr(biliip,&idesc);

        char biliip_buf[64];
        char *biliip_last = biliip_buf;

        if (startstat > 70) {
            if (icountry > 0 && country) {
              biliip_last += sprintf(biliip_last, "%.*s", icountry, country);
            }
            move(y, startstat - 50);

            attron(A_BOLD | COLOR_PAIR(4));
            printw("%s", biliip_buf);
            attroff(A_BOLD | COLOR_PAIR(4));

            biliip_last = biliip_buf;
            *biliip_last = '\0';

            if (iprovince > 0 && province) {
              biliip_last += sprintf(biliip_last, " %.*s", iprovince, province);
              while (biliip_last > biliip_buf && *(biliip_last-1) == ' ') *--biliip_last = '\0';
              printw("%s", biliip_buf);
              biliip_last = biliip_buf;
              *biliip_last = '\0';
            }
            if (icity > 0 && city && (iprovince != icity || strncmp(province, city, icity) != 0)) {
              biliip_last += sprintf(biliip_last, " %.*s", icity, city);
              while (biliip_last > biliip_buf && *(biliip_last-1) == ' ') *--biliip_last = '\0';
              printw("%s", biliip_buf);
              biliip_last = biliip_buf;
              *biliip_last = '\0';
            }
        }

        if (iisp > 0 && isp) {
          biliip_last += sprintf(biliip_last, "%.*s", iisp, isp);
          while (biliip_last > biliip_buf && *(biliip_last-1) == ' ') *--biliip_last = '\0';
        }
        if (idesc > 0 && desc) {
          biliip_last += sprintf(biliip_last, " %.*s", idesc, desc);
          while (biliip_last > biliip_buf && *(biliip_last-1) == ' ') *--biliip_last = '\0';
        }
        move(y, startstat - 25);
        attron(A_BOLD | COLOR_PAIR(7));
        printw("%s", biliip_buf);
        attroff(A_BOLD | COLOR_PAIR(7));
      }
    }
#endif
      move(y, startstat);

      /* net_xxx returns times in usecs. Just display millisecs */
      hd_len = 0;
      for( i=0; i<MAXFLD; i++ ) {
	/* Ignore options that don't exist */
	/* On the other hand, we now check the input side. Shouldn't happen, 
	   can't be careful enough. */
	j = fld_index[fld_active[i]];
	if (j == -1) continue; 

	/* temporay hack for stats usec to ms... */
	if( index( data_fields[j].format, 'f' ) ) {
	  sprintf(buf + hd_len, data_fields[j].format,
		data_fields[j].net_xxx(at) /1000.0 );
	} else {
	  sprintf(buf + hd_len, data_fields[j].format,
		data_fields[j].net_xxx(at) );
	}
	hd_len +=  data_fields[j].length;
      }
      buf[hd_len] = 0;
      printw("%s", buf);

      for (k=0; k < mpls->labels && enablempls; k++) {
        if((k+1 < mpls->labels) || (mpls->labels == 1)) {
           /* if we have more labels */
           printw("\n    [MPLS: Lbl %lu Exp %u S %u TTL %u]", mpls->label[k], mpls->exp[k], mpls->s[k], mpls->ttl[k]);
        } else {
           /* bottom label */
           printw("\n    [MPLS: Lbl %lu Exp %u S %u TTL %u]", mpls->label[k], mpls->exp[k], mpls->s[k], mpls->ttl[k]);
        }
      }

// printw("aasdfasdf");
      /* Multi path */
      for (i=0; i < MAXPATH; i++ ) {
        addrs = net_addrs(at, i);
        mplss = net_mplss(at, i);
	if ( addrcmp( (void *) addrs, (void *) addr, af ) == 0 ) continue;
	if ( addrcmp( (void *) addrs, (void *) &unspec_addr, af ) == 0 ) break;

        name = dns_lookup(addrs);
        if (! net_up(at)) attron(A_BOLD);
        printw("\n    ");
#ifdef IPINFO
        if (is_printii())
          printw(fmt_ipinfo(addrs));
#endif
        if (name != NULL) {
	  if (show_ips) printw("%s (%s)", name, strlongip(addrs));
	  else printw("%s", name);
        } else {
	  printw("%s", strlongip( addrs ) );
        }
        for (k=0; k < mplss->labels && enablempls; k++) {
          printw("\n    [MPLS: Lbl %lu Exp %u S %u TTL %u]", mplss->label[k], mplss->exp[k], mplss->s[k], mplss->ttl[k]);
        }
        attroff(A_BOLD);
      }

    } else {
      printw("???");
    }

    printw("\n");
  }
  move(2, 0);
}