Navigation Menu

Skip to content

Commit

Permalink
ipinfo update
Browse files Browse the repository at this point in the history
1) now `y' and `z' keys work when MTR is started without `y' or `z' option

  for example: start mtr then press `y' ...

2) `y/ipinfo' option can accept multiple values

  syntax:
    -y/--ipinfo origin,fields

  examples:

    origin.asn.spameatingmonkey.net: CC, ASN, ORG
    % mtr -4t -y3,5,2,3 hostname

    origin.asn.cymru.com: ASN
    % mtr -4t -y, hostname
  • Loading branch information
yvs2014 committed Jun 14, 2014
1 parent 97af563 commit 74b12d9
Show file tree
Hide file tree
Showing 8 changed files with 287 additions and 141 deletions.
296 changes: 214 additions & 82 deletions asn.c

Large diffs are not rendered by default.

16 changes: 8 additions & 8 deletions asn.h
Expand Up @@ -16,6 +16,9 @@
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/

#ifndef ASN_H
#define ASN_H

// The autoconf system provides us with the NO_IPINFO define.
// Littering the code with #ifndef NO_IPINFO (double negative)
// does not benefit readabilty. So here we invert the sense of the
Expand All @@ -27,15 +30,12 @@
#ifndef NO_IPINFO
#define IPINFO


extern int ipinfo_no;
extern int ipinfo_max;
extern int iiwidth_len;
extern int iihash;
void asn_open();
extern int enable_ipinfo;
void asn_close();
char *fmt_ipinfo(ip_t *addr);
int get_iiwidth(void);
int is_printii(void);
void ii_parsearg(char *arg);
void ii_action(int action_asn);
int ii_getwidth(void);

#endif
#endif
10 changes: 5 additions & 5 deletions curses.c
Expand Up @@ -345,7 +345,7 @@ void mtr_curses_hosts(int startstat)
if (! net_up(at))
attron(A_BOLD);
#ifdef IPINFO
if (is_printii())
if (enable_ipinfo)
printw(fmt_ipinfo(addr));
#endif
if(name != NULL) {
Expand Down Expand Up @@ -402,7 +402,7 @@ void mtr_curses_hosts(int startstat)
if (! net_up(at)) attron(A_BOLD);
printw("\n ");
#ifdef IPINFO
if (is_printii())
if (enable_ipinfo)
printw(fmt_ipinfo(addrs));
#endif
if (name != NULL) {
Expand Down Expand Up @@ -553,7 +553,7 @@ void mtr_curses_graph(int startstat, int cols)
attron(A_BOLD);
if (addrcmp((void *) addr, (void *) &unspec_addr, af)) {
#ifdef IPINFO
if (is_printii())
if (enable_ipinfo)
printw(fmt_ipinfo(addr));
#endif
name = dns_lookup(addr);
Expand Down Expand Up @@ -643,8 +643,8 @@ void mtr_curses_redraw(void)
char msg[80];
int padding = 30;
#ifdef IPINFO
if (is_printii())
padding += get_iiwidth();
if (enable_ipinfo)
padding += ii_getwidth();
#endif
int max_cols = maxx<=SAVED_PINGS+padding ? maxx-padding : SAVED_PINGS;
startstat = padding - 2;
Expand Down
9 changes: 2 additions & 7 deletions display.c
Expand Up @@ -96,10 +96,6 @@ void display_open(void)
break;
case DisplayCurses:
mtr_curses_open();
#ifdef IPINFO
if (ipinfo_no >= 0)
asn_open();
#endif
break;
case DisplaySplit:
split_open();
Expand Down Expand Up @@ -127,11 +123,10 @@ void display_close(time_t now)
csv_close(now);
break;
case DisplayCurses:
mtr_curses_close();
#ifdef IPINFO
if (ipinfo_no >= 0)
asn_close();
asn_close();
#endif
mtr_curses_close();
break;
case DisplaySplit:
split_close();
Expand Down
42 changes: 41 additions & 1 deletion mtr.8
Expand Up @@ -8,7 +8,7 @@ mtr \- a network diagnostic tool
.SH SYNOPSIS
.B mtr
[\c
.B \-BfhvrctglxspQemniuTP46\c
.B \-BfhvrctglxspQemniuTP46yz\c
]
[\c
.B \-\-help\c
Expand Down Expand Up @@ -274,6 +274,46 @@ was built for this to work. See the GTK+ web page at
.B http://www.gtk.org/
for more information about GTK+.

.TP
.B \-z
.TP
.B \-\-aslookup
.br
Turn on ASN lookups. Origin - asn.routeviews.org (IPv4 only).

Key: `z' toggle ASN info on/off

.TP
.B \-y\ origin,fields
.TP
.B \-\-ipinfo\ origin,fields
.br
Use this option to specify the IP info origin and their fields and order.

Available origins and their fields:
1 - origin.asn.cymru.com (both IPv4 and IPv6):
.br
ASN, Route, CC, Registry, Allocated
.br
2 - asn.routeviews.org (IPv4 only):
.br
ASN
.br
3 - origin.asn.spameatingmonkey.net (IPv4 only):
.br
Route, ASN, Organization, Allocated, CC
.br
Default: 1,1
.br
Examples:
.br
-y3,5,2,3 (origin.asn.spameatingmonkey.net: CC ASN ORG)
.br
-y, (origin.asn.cymru.com: ASN)
.br

Key: `y' switching IP info

.TP
.B \-p
.TP
Expand Down
18 changes: 5 additions & 13 deletions mtr.c
Expand Up @@ -311,8 +311,8 @@ void parse_arg (int argc, char **argv)
{ "inet", 0, 0, '4' }, /* IPv4 only */
{ "inet6", 0, 0, '6' }, /* IPv6 only */
#ifdef IPINFO
{ "ipinfo", 1, 0, 'y' }, /* IP info lookup */
{ "aslookup", 0, 0, 'z' }, /* Do AS lookup (--ipinfo 0) */
{ "ipinfo", 1, 0, 'y' },
{ "aslookup", 0, 0, 'z' },
#endif
{ 0, 0, 0, 0 }
};
Expand Down Expand Up @@ -477,17 +477,10 @@ void parse_arg (int argc, char **argv)
#endif
#ifdef IPINFO
case 'y':
ipinfo_no = atoi (optarg);
if (ipinfo_no < 0)
ipinfo_no = 0;
ii_parsearg(optarg);
break;
case 'z':
ipinfo_no = 0;
break;
#else
case 'y':
case 'z':
fprintf( stderr, "IPINFO not enabled.\n" );
ii_parsearg("2"); // routeviews.org origin
break;
#endif
}
Expand Down Expand Up @@ -596,8 +589,7 @@ int main(int argc, char **argv)
"\t\t[--csv|-C] [--raw] [--xml] [--split] [--mpls] [--no-dns] [--show-ips]\n"
"\t\t[--address interface] [--filename=FILE|-F]\n" /* BL */
#ifdef IPINFO
"\t\t[--ipinfo=item_no|-y item_no]\n"
"\t\t[--aslookup|-z]\n"
"\t\t[--aslookup|-z] [--ipinfo|-y origin,fields]\n"
#endif
"\t\t[--psize=bytes/-s bytes] [--order fields]\n" /* ok */
"\t\t[--report-wide|-w] [--inet] [--inet6] [--max-ttl=NUM] [--first-ttl=NUM]\n"
Expand Down
19 changes: 6 additions & 13 deletions report.c
Expand Up @@ -113,15 +113,8 @@ void report_close(void)

#ifdef 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
}
}
if (enable_ipinfo && reportwide)
len_tmp += ii_getwidth() - 1;
snprintf( fmt, sizeof(fmt), "HOST: %%-%ds", len_tmp);
#else
snprintf( fmt, sizeof(fmt), "HOST: %%-%ds", len_hosts);
Expand All @@ -146,7 +139,7 @@ void report_close(void)
snprint_addr(name, sizeof(name), addr);

#ifdef IPINFO
if (is_printii()) {
if (enable_ipinfo) {
snprintf(fmt, sizeof(fmt), " %%2d. %%s%%-%ds", len_hosts);
snprintf(buf, sizeof(buf), fmt, at+1, fmt_ipinfo(addr), name);
} else {
Expand Down Expand Up @@ -192,7 +185,7 @@ void report_close(void)
if (!found) {

#ifdef IPINFO
if (is_printii()) {
if (enable_ipinfo) {
if (mpls->labels && z == 1 && enablempls)
print_mpls(mpls);
snprint_addr(name, sizeof(name), addr2);
Expand Down Expand Up @@ -228,7 +221,7 @@ void report_close(void)

/* No multipath */
#ifdef IPINFO
if (is_printii()) {
if (enable_ipinfo) {
if (mpls->labels && z == 1 && enablempls)
print_mpls(mpls);
} else {
Expand Down Expand Up @@ -340,7 +333,7 @@ void csv_close(time_t now)

int last = net_last(at);
#ifdef IPINFO
if(!ipinfo_no) {
if(enable_ipinfo) {
char* fmtinfo = fmt_ipinfo(addr);
if (fmtinfo != NULL) fmtinfo = trim(fmtinfo);
printf("MTR.%s;%lld;%s;%s;%d;%s;%s;%d", MTR_VERSION, (long long)now, "OK", Hostname,
Expand Down
18 changes: 6 additions & 12 deletions select.c
Expand Up @@ -239,19 +239,13 @@ void select_loop(void) {
}
break;
#ifdef IPINFO
case ActionII:
if (ipinfo_no >= 0) {
ipinfo_no++;
if (ipinfo_no > ipinfo_max)
ipinfo_no = 0;
}
break;
case ActionAS:
if (ipinfo_no >= 0)
ipinfo_no = ipinfo_no?0:ipinfo_max;
break;
case ActionII:
ii_action(0);
break;
case ActionAS:
ii_action(1);
break;
#endif

case ActionScrollDown:
display_offset += 5;
break;
Expand Down

0 comments on commit 74b12d9

Please sign in to comment.