void mtr_curses_graph(int startstat, int cols) { int max, at, y, x; 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); name = dns_lookup(addr); if (name) { printw("%s", name); } else { printw("%s", strlongip( addr ) ); } attroff(A_BOLD); getyx(stdscr, y, x); move(y, startstat); printw(" "); mtr_fill_graph(at, cols); printw("\n"); } }
void mtr_gen_scale(void) { int *saved, i, max, at; int range; low_ms = 1000000; high_ms = -1; for (i = 0; i < NUM_FACTORS; i++) { scale[i] = 0; } max = net_max(); for (at = display_offset; at < max; at++) { saved = net_saved_pings(at); for (i = 0; i < SAVED_PINGS; i++) { if (saved[i] < 0) continue; if (saved[i] < low_ms) { low_ms = saved[i]; } if (saved[i] > high_ms) { high_ms = saved[i]; } } } range = high_ms - low_ms; for (i = 0; i < NUM_FACTORS; i++) { scale[i] = low_ms + ((double)range * factors[i]); } }
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; } } } }
void xml_close(void) { int i, j, at, max; ip_t *addr; char name[81]; printf("<?xml version=\"1.0\"?>\n"); printf("<MTR SRC=\"%s\" DST=\"%s\"", LocalHostname, Hostname); printf(" TOS=\"0x%X\"", tos); if(cpacketsize >= 0) { printf(" PSIZE=\"%d\"", cpacketsize); } else { printf(" PSIZE=\"rand(%d-%d)\"",MINPACKET, -cpacketsize); } if( bitpattern>=0 ) { printf(" BITPATTERN=\"0x%02X\"", (unsigned char)(bitpattern)); } else { printf(" BITPATTERN=\"rand(0x00-FF)\""); } printf(" TESTS=\"%d\">\n", MaxPing); max = net_max(); at = net_min(); for(; at < max; at++) { addr = net_addr(at); snprint_addr(name, sizeof(name), addr); printf(" <HUB COUNT=\"%d\" HOST=\"%s\">\n", at+1, name); for( i=0; i<MAXFLD; i++ ) { j = fld_index[fld_active[i]]; if (j <= 0) continue; // Field nr 0, " " shouldn't be printed in this method. strcpy(name, " <%s>"); strcat(name, data_fields[j].format); strcat(name, "</%s>\n"); /* XML doesn't allow "%" in tag names, rename Loss% to just Loss */ const char *title; title = data_fields[j].title; if( strcmp(data_fields[j].title, "Loss%") == 0 ) { title = "Loss"; } /* 1000.0 is a temporay hack for stats usec to ms, impacted net_loss. */ if( index( data_fields[j].format, 'f' ) ) { printf( name, title, data_fields[j].net_xxx(at) /1000.0, title ); } else { printf( name, title, data_fields[j].net_xxx(at), title ); } } printf(" </HUB>\n"); } printf("</MTR>\n"); }
void csv_close(time_t now) { int i, j, at, max; ip_t *addr; char name[81]; for( i=0; i<MAXFLD; i++ ) { j = fld_index[fld_active[i]]; if (j < 0) continue; } max = net_max(); at = net_min(); for(; at < max; at++) { addr = net_addr(at); snprint_addr(name, sizeof(name), addr); if (at == net_min()) { printf("Mtr_Version,Start_Time,Status,Host,Hop,Ip,"); #ifdef IPINFO if(!ipinfo_no) { printf("Asn,"); } #endif for( i=0; i<MAXFLD; i++ ) { j = fld_index[fld_active[i]]; if (j < 0) continue; printf("%s,", data_fields[j].title); } printf("\n"); } #ifdef IPINFO if(!ipinfo_no) { char* fmtinfo = fmt_ipinfo(addr); if (fmtinfo != NULL) fmtinfo = trim(fmtinfo); printf("MTR.%s,%lld,%s,%s,%d,%s,%s", MTR_VERSION, (long long)now, "OK", Hostname, at+1, name, fmtinfo); } else #endif printf("MTR.%s,%lld,%s,%s,%d,%s", MTR_VERSION, (long long)now, "OK", Hostname, at+1, name); 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' ) ) { printf( ",%.2f", data_fields[j].net_xxx(at) / 1000.0); } else { printf( ",%d", data_fields[j].net_xxx(at) ); } } printf("\n"); } }
void csv_close(void) { int i, j, at, max; ip_t *addr; char name[81]; /* Caption */ printf("<SRC=%s DST=%s", LocalHostname, Hostname); printf(" TOS=0x%X", tos); if(cpacketsize >= 0) { printf(" PSIZE=%d", cpacketsize); } else { printf(" PSIZE=rand(%d-%d)",MINPACKET, -cpacketsize); } if( bitpattern>=0 ) { printf(" BITPATTERN=0x%02X", (unsigned char)(bitpattern)); } else { printf(" BITPATTERN=rand(0x00-FF)"); } printf(" TESTS=%d>\n", MaxPing); /* Header */ printf("HUPCOUNT, HOST"); for( i=0; i<MAXFLD; i++ ) { j = fld_index[fld_active[i]]; if (j < 0) continue; printf( ", %s", data_fields[j].title ); } printf("\n"); max = net_max(); at = net_min(); for(; at < max; at++) { addr = net_addr(at); snprint_addr(name, sizeof(name), addr); printf("%d, %s", at+1, name); for( i=0; i<MAXFLD; i++ ) { j = fld_index[fld_active[j]]; 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' ) ) { printf( ", %.2f", data_fields[j].net_xxx(at) / 1000.0); } else { printf( ", %d", data_fields[j].net_xxx(at) ); } } printf("\n"); } }
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"); } }
void gtk_redraw(void) { int max = net_max(); GtkTreeIter iter; int row = net_min(); gboolean valid; valid = gtk_tree_model_get_iter_first(GTK_TREE_MODEL(ReportStore), &iter); while(valid) { if(row < max) { update_tree_row(row++, &iter); valid = gtk_tree_model_iter_next(GTK_TREE_MODEL(ReportStore), &iter); } else { valid = gtk_list_store_remove(ReportStore, &iter); } } while(row < max) { gtk_list_store_append(ReportStore, &iter); update_tree_row(row++, &iter); } }
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 } }
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); }
void report_close(void) { int i, j, at, max; ip_t *addr; char name[81]; char buf[1024]; char fmt[16]; int len=0; int len_hosts = 33; struct hostent *host; if (reportwide) { // get the longest hostname len_hosts = strlen(LocalHostname); max = net_max(); at = net_min(); for (; at < max; at++) { addr = net_addr(at); if( addrcmp( (void *) addr, (void *) &unspec_addr, af ) != 0 ) { host = dns ? addr2host( (void *) addr, af ) : NULL; if (host != NULL) { strncpy( name, host->h_name, (sizeof name) - 1 ); name[ (sizeof name) - 1 ] = '\0'; } else { snprintf(name, sizeof(name), "%s", strlongip( addr ) ); } if (len_hosts < strlen(name)) { len_hosts = strlen(name); } } } } snprintf( fmt, sizeof(fmt), "HOST: %%-%ds", len_hosts); 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); if( addrcmp( (void *) addr, (void *) &unspec_addr, af ) == 0 ) { sprintf(name, "???"); } else { host = dns ? addr2host( (void *) addr, af ) : NULL; if (host != NULL) { strncpy( name, host->h_name, (sizeof name) - 1 ); name[ (sizeof name) - 1 ] = '\0'; } else { snprintf(name, sizeof(name), "%s", strlongip( addr ) ); } } snprintf( fmt, sizeof(fmt), " %%2d. %%-%ds", len_hosts); snprintf(buf, sizeof(buf), fmt, at+1, name); 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); } }
void csv_close(void) { int i, j, at, max; ip_t *addr; char name[81]; struct hostent *host; /* Caption */ printf("<SRC=%s DST=%s", LocalHostname, Hostname); printf(" TOS=0x%X", tos); if(cpacketsize >= 0) { printf(" PSIZE=%d", cpacketsize); } else { printf(" PSIZE=rand(%d-%d)",MINPACKET, -cpacketsize); } if( bitpattern>=0 ) { printf(" BITPATTERN=0x%02X", (unsigned char)(bitpattern)); } else { printf(" BITPATTERN=rand(0x00-FF)"); } printf(" TESTS=%d>\n", MaxPing); /* Header */ printf("HUPCOUNT, HOST"); for( i=0; i<MAXFLD; i++ ) { j = fld_index[fld_active[i]]; if (j < 0) continue; printf( ", %s", data_fields[j].title ); } printf("\n"); max = net_max(); at = net_min(); for(; at < max; at++) { addr = net_addr(at); if( addrcmp( (void *) addr, (void *) &unspec_addr, af ) == 0 ) { sprintf(name, "???"); } else { host = dns ? addr2host( (void *) addr, af ) : NULL; if (host != NULL) { strncpy( name, host->h_name, (sizeof name) - 1 ); name[ (sizeof name) - 1 ] = '\0'; } else { sprintf(name, "%s", strlongip( addr ) ); } } printf("%d, %s", at+1, name); for( i=0; i<MAXFLD; i++ ) { j = fld_index[fld_active[j]]; 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' ) ) { printf( ", %.2f", data_fields[j].net_xxx(at) / 1000.0); } else { printf( ", %d", data_fields[j].net_xxx(at) ); } } printf("\n"); } }
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); }
void gc_keyaction(int c) { if (!c) return; if (c == ACTION_RESIZE) { if (params.enable_legend) { curses_cols = cr_recalc(hostinfo_max); pr_lastd(); } return; } if (params.enable_legend) { switch (c) { case '+': { // ScrollDown int hops = net_max() - net_min(); display_offset += 5; if (display_offset >= hops) display_offset = hops - 1; hostinfo_max = 0; GCDEBUG_MSG(("display_offset=%d\n", display_offset)); } break; case '-': { // ScrollUp int rest = display_offset % 5; if (rest) display_offset -= rest; else display_offset -= 5; if (display_offset < 0) display_offset = 0; hostinfo_max = 0; GCDEBUG_MSG(("display_offset=%d\n", display_offset)); } break; } switch (tolower(c)) { case 'd': // Display display_mode = (display_mode + 1) % display_mode_max; if (display_mode) curses_cols = cr_recalc(hostinfo_max); pr_lastd(); GCDEBUG_MSG(("display_mode=%d\n", display_mode)); break; case 'e': // MPLS enablempls = !enablempls; GCDEBUG_MSG(("enable_mpls=%d\n", enablempls)); break; case 'j': if (index(fld_active, 'N')) strcpy(fld_active, "DR AGJMXI"); else strcpy(fld_active, "LS NABWV"); mtr_curses_data_fields(legend_hd[LEGEND_HEADER_STATIC]); GCDEBUG_MSG(("toggle latency/jitter stats\n")); break; case 'n': // DNS use_dns = !use_dns; hostinfo_max = 0; GCDEBUG_MSG(("use_dns=%d\n", use_dns)); break; #ifdef IPINFO case 'y': // IP Info ii_action(0); hostinfo_max = 0; GCDEBUG_MSG(("switching ip info\n")); break; case 'z': // ASN ii_action(1); hostinfo_max = 0; GCDEBUG_MSG(("toggle asn info\n")); break; #endif } } switch (c) { case 'q': // Quit gc_close(); GCDEBUG_MSG(("bye-bye\n")); exit(0); break; case ' ': // Resume paused = 0; cr_net_reset(1); GCDEBUG_MSG(("...resume\n")); break; } switch (tolower(c)) { case 'p': // Pause paused = 1; GCDEBUG_MSG(("pause...\n")); break; case 'r': // Reset net_reset(); cr_net_reset(0); num_pings = 0; GCDEBUG_MSG(("net reset\n")); break; case 't': // TCP and ICMP ECHO switch (mtrtype) { case IPPROTO_ICMP: case IPPROTO_UDP: mtrtype = IPPROTO_TCP; GCDEBUG_MSG(("tcp_syn packets\n")); break; case IPPROTO_TCP: mtrtype = IPPROTO_ICMP; GCDEBUG_MSG(("icmp_echo packets\n")); break; } break; case 'u': // UDP and ICMP ECHO switch (mtrtype) { case IPPROTO_ICMP: case IPPROTO_TCP: GCDEBUG_MSG(("udp datagrams\n")); mtrtype = IPPROTO_UDP; break; case IPPROTO_UDP: mtrtype = IPPROTO_ICMP; GCDEBUG_MSG(("icmp_echo packets\n")); break; } break; } }
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); }
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; } } } }