if (! net_up(at))
attron(A_BOLD);
if(name != NULL) {
- printw("%s", name);
+ if (show_ips) printw("%s (%s)", name, strlongip(addr));
+ else printw("%s", name);
} else {
printw("%s", strlongip( addr ) );
}
{
char *t;
- if (!dns) return strlongip (ip);
- t = dns_lookup2 (ip);
- return (t&&use_dns)?t:strlongip(ip);
+ if (!dns) return NULL;
+ t = dns_lookup2(ip);
+ return (t && use_dns) ? t : NULL;
}
#ifdef ENABLE_IPV6
void update_tree_row(int row, GtkTreeIter *iter)
{
ip_t *addr;
- char str[256], *name;
+ char str[256]="???", *name=str;
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;
- }
+ if (addrcmp( (void *) addr, (void *) &unspec_addr, af)) {
+ if ((name = dns_lookup(addr))) {
+ if (show_ips) {
+ snprintf(str, sizeof(str), "%s (%s)", name, strlongip(addr));
+ name = str;
+ }
+ } else name = strlongip(addr);
}
gtk_list_store_set(ReportStore, iter,
.B \-\-no-dns\c
]
[\c
+.B \-\-show-ips\c
+]
+[\c
.B \-\-gtk\c
]
[\c
to display numeric IP numbers and not try to resolve the
host names.
+.TP
+.B \-z
+.TP
+.B \-\-show-ips
+.br
+Use this option to tell
+.B mtr
+to display both the host names and numeric IP numbers. In split mode
+this adds an extra field to the output.
+
.TP
.B \-o\ fields\ order
.TP
char *InterfaceAddress = NULL;
char LocalHostname[128];
int dns = 1;
+int show_ips = 0;
int enablempls = 0;
int cpacketsize = 64; /* default packet size */
int bitpattern = 0;
{ "tos", 1, 0, 'Q' }, /* typeof service (0,255) */
{ "mpls", 0, 0, 'e' },
{ "no-dns", 0, 0, 'n' },
+ { "show-ips", 0, 0, 'z' },
{ "address", 1, 0, 'a' },
{ "first-ttl", 1, 0, 'f' }, /* -f & -m are borrowed from traceroute */
{ "max-ttl", 1, 0, 'm' },
while(1) {
/* added f:m:o: byMin */
opt = getopt_long(argc, argv,
- "vhrwxtglpo:i:c:s:b:Q:ena:f:m:u46", long_options, NULL);
+ "vhrwxtglpo:i:c:s:b:Q:ena:f:m:uz46", long_options, NULL);
if(opt == -1)
break;
case 'u':
mtrtype = IPPROTO_UDP;
break;
+ case 'z':
+ show_ips = 1;
+ reportwide = 1;
+ break;
case '4':
af = AF_INET;
break;
if (PrintHelp) {
printf("usage: %s [-hvrwctglspniu46] [--help] [--version] [--report]\n"
"\t\t[--report-wide] [--report-cycles=COUNT] [--curses] [--gtk]\n"
- "\t\t[--raw] [--split] [--mpls] [--no-dns] [--address interface]\n" /* BL */
+ "\t\t[--raw] [--split] [--mpls] [--no-dns] [--show-ips]\n"
+ "\t\t[--address interface]\n" /* BL */
"\t\t[--psize=bytes/-s bytes]\n" /* ok */
"\t\t[--report-wide|-w] [-u]\n" /* rew */
"\t\t[--interval=SECONDS] HOSTNAME [PACKETSIZE]\n", argv[0]);
extern int enablempls;
extern int dns;
+extern int show_ips;
extern int use_dns;
#ifdef __GNUC__
{
}
+static size_t snprint_addr(char *dst, size_t dst_len, ip_t *addr)
+{
+ if(addrcmp((void *) addr, (void *) &unspec_addr, af)) {
+ struct hostent *host = dns ? addr2host((void *) addr, af) : NULL;
+ if (!host) return snprintf(dst, dst_len, "%s", strlongip(addr));
+ else if (dns && show_ips)
+ return snprintf(dst, dst_len, "%s (%s)", host->h_name, strlongip(addr));
+ else return snprintf(dst, dst_len, "%s", host->h_name);
+ } else return snprintf(dst, dst_len, "%s", "???");
+}
+
void report_close(void)
{
char fmt[16];
int len=0;
int len_hosts = 33;
- struct hostent *host;
if (reportwide)
{
max = net_max();
at = net_min();
for (; at < max; at++) {
+ int nlen;
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);
- }
- }
+ if ((nlen = snprint_addr(name, sizeof(name), addr)))
+ if (len_hosts < nlen)
+ len_hosts = nlen;
}
}
for(; at < max; at++) {
addr = net_addr(at);
mpls = net_mpls(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 ) );
- }
- }
+ snprint_addr(name, sizeof(name), addr);
snprintf( fmt, sizeof(fmt), " %%2d.|-- %%-%ds", len_hosts);
snprintf(buf, sizeof(buf), fmt, at+1, name);
int i, j, at, max;
ip_t *addr;
char name[81];
- struct hostent *host;
printf("<MTR SRC=%s DST=%s", LocalHostname, Hostname);
printf(" TOS=0x%X", tos);
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 ) );
- }
- }
+ snprint_addr(name, sizeof(name), addr);
printf(" <HUB COUNT=%d HOST=%s>\n", at+1, name);
for( i=0; i<MAXFLD; i++ ) {
int i, j, at, max;
ip_t *addr;
char name[81];
- struct hostent *host;
/* Caption */
printf("<SRC=%s DST=%s", LocalHostname, Hostname);
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 ) );
- }
- }
+ snprint_addr(name, sizeof(name), addr);
printf("%d, %s", at+1, name);
for( i=0; i<MAXFLD; i++ ) {
int max;
int at;
ip_t *addr;
- char *name;
char newLine[MAX_LINE_SIZE];
int i;
*/
for(at = 0; at < max; at++) {
addr = net_addr(at);
-
- if( addrcmp( (void *) addr, (void *) &unspec_addr, af ) != 0 ) {
- name = dns_lookup(addr);
- if(name != NULL) {
- /* 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 {
- snprintf(newLine, sizeof(newLine), "%s %d %d %d %d %d %d",
- strlongip( addr ),
- net_loss(at),
- net_returned(at), net_xmit(at),
- net_best(at) /1000, net_avg(at)/1000,
- net_worst(at)/1000);
+ 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, "???");
}