#define NAMELEN 127
#define UNKN "???"
-int ipinfo_no = -1;
-int ipinfo_max = -1;
static int iihash = 0;
-char fmtinfo[32];
+static char fmtinfo[32];
// items width: ASN, Route, Country, Registry, Allocated
-int iiwidth[] = { 7, 19, 4, 8, 11}; // item len + space
-int iiwidth_len = sizeof(iiwidth)/sizeof((iiwidth)[0]);
+static const int iiwidth[] = { 7, 19, 4, 8, 11 }; // item len + space
typedef char* items_t[ITEMSMAX + 1];
static items_t items_a; // without hash: items
}
// originX.asn.cymru.com txtrec: ASN | Route | Country | Registry | Allocated
-static char* split_txtrec(char *txt_rec) {
+static char* split_txtrec(struct mtr_ctl *ctl, char *txt_rec) {
if (!txt_rec)
return NULL;
if (iihash) {
for (j = i; j <= ITEMSMAX; j++)
(*items)[j] = NULL;
- if (i > ipinfo_max)
- ipinfo_max = i;
- if (ipinfo_no >= i) {
- if (ipinfo_no >= ipinfo_max)
- ipinfo_no = 0;
+ if (i > ctl->ipinfo_max)
+ ctl->ipinfo_max = i;
+ if (ctl->ipinfo_no >= i) {
+ if (ctl->ipinfo_no >= ctl->ipinfo_max)
+ ctl->ipinfo_no = 0;
return (*items)[0];
} else
- return (*items)[ipinfo_no];
+ return (*items)[ctl->ipinfo_no];
}
#ifdef ENABLE_IPV6
item.key = key;;
ENTRY *found_item;
if ((found_item = hsearch(item, FIND))) {
- if (!(val = (*((items_t*)found_item->data))[ipinfo_no]))
+ if (!(val = (*((items_t*)found_item->data))[ctl->ipinfo_no]))
val = (*((items_t*)found_item->data))[0];
DEB_syslog(LOG_INFO, "Found (hashed): %s", val);
}
if (!val) {
DEB_syslog(LOG_INFO, "Lookup: %s", key);
- if ((val = split_txtrec(ipinfo_lookup(lookup_key)))) {
+ if ((val = split_txtrec(ctl, ipinfo_lookup(lookup_key)))) {
DEB_syslog(LOG_INFO, "Looked up: %s", key);
if (iihash)
if ((item.key = strdup(key))) {
return val;
}
-extern int get_iiwidth(void) {
- return (ipinfo_no < iiwidth_len) ? iiwidth[ipinfo_no] : iiwidth[ipinfo_no % iiwidth_len];
+extern int get_iiwidth (struct mtr_ctl *ctl) {
+ return (ctl->ipinfo_no <
+ ctl->iiwidth_len) ? iiwidth[ctl->ipinfo_no] :
+ iiwidth[ctl->ipinfo_no % ctl->iiwidth_len];
}
extern char *fmt_ipinfo(struct mtr_ctl *ctl, ip_t *addr){
char *ipinfo = get_ipinfo(ctl, addr);
char fmt[8];
- snprintf(fmt, sizeof(fmt), "%s%%-%ds", ipinfo_no?"":"AS", get_iiwidth());
+ snprintf(fmt, sizeof(fmt), "%s%%-%ds", ctl->ipinfo_no?"":"AS", get_iiwidth(ctl));
snprintf(fmtinfo, sizeof(fmtinfo), fmt, ipinfo?ipinfo:UNKN);
return fmtinfo;
}
-extern int is_printii(void) {
- return ((ipinfo_no >= 0) && (ipinfo_no != ipinfo_max));
+extern int is_printii(struct mtr_ctl *ctl) {
+ return ((ctl->ipinfo_no >= 0) && (ctl->ipinfo_no != ctl->ipinfo_max));
}
-extern void asn_open(void) {
- if (ipinfo_no >= 0) {
+extern void asn_open(struct mtr_ctl *ctl) {
+ if (ctl->ipinfo_no >= 0) {
DEB_syslog(LOG_INFO, "hcreate(%d)", IIHASH_HI);
if (!(iihash = hcreate(IIHASH_HI)))
error(0, errno, "ipinfo hash");
}
}
-extern void asn_close(void) {
- if ((ipinfo_no >= 0) && iihash) {
+extern void asn_close(struct mtr_ctl *ctl) {
+ if ((ctl->ipinfo_no >= 0) && iihash) {
DEB_syslog(LOG_INFO, "hdestroy()");
hdestroy();
iihash = 0;
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
-extern int ipinfo_no;
-extern int ipinfo_max;
-extern int iiwidth_len;
-extern void asn_open();
-extern void asn_close();
+extern void asn_open(struct mtr_ctl *ctl);
+extern void asn_close(struct mtr_ctl *ctl);
extern char *fmt_ipinfo(struct mtr_ctl *ctl, ip_t *addr);
-extern int get_iiwidth(void);
-extern int is_printii(void);
+extern int get_iiwidth(struct mtr_ctl *ctl);
+extern int is_printii(struct mtr_ctl *ctl);
max = net_max(ctl);
- for(at = net_min(ctl) + display_offset; at < max; at++) {
+ for(at = net_min(ctl) + ctl->display_offset; at < max; at++) {
printw("%2d. ", at + 1);
addr = net_addr(at);
mpls = net_mpls(at);
- if( addrcmp( (void *) addr, (void *) &unspec_addr, ctl->af ) != 0 ) {
+ if( addrcmp( (void *) addr, (void *) &ctl->unspec_addr, ctl->af ) != 0 ) {
name = dns_lookup(ctl, addr);
if (! net_up(at))
attron(A_BOLD);
#ifdef HAVE_IPINFO
- if (is_printii())
+ if (is_printii(ctl))
printw(fmt_ipinfo(ctl, addr));
#endif
if(name != NULL) {
addrs = net_addrs(at, i);
mplss = net_mplss(at, i);
if ( addrcmp( (void *) addrs, (void *) addr, ctl->af ) == 0 ) continue;
- if ( addrcmp( (void *) addrs, (void *) &unspec_addr, ctl->af ) == 0 ) break;
+ if ( addrcmp( (void *) addrs, (void *) &ctl->unspec_addr, ctl->af ) == 0 ) break;
name = dns_lookup(ctl, addrs);
if (! net_up(at)) attron(A_BOLD);
printw("\n ");
#ifdef HAVE_IPINFO
- if (is_printii())
+ if (is_printii(ctl))
printw(fmt_ipinfo(ctl, addrs));
#endif
if (name != NULL) {
scale[i] = 0;
}
max = net_max(ctl);
- for (at = display_offset; at < max; at++) {
+ for (at = ctl->display_offset; at < max; at++) {
saved = net_saved_pings(at);
for (i = 0; i < SAVED_PINGS; i++) {
if (saved[i] < 0) continue;
max = net_max(ctl);
- for (at = display_offset; at < max; at++) {
+ for (at = ctl->display_offset; at < max; at++) {
printw("%2d. ", at+1);
addr = net_addr(at);
if (! net_up(at))
attron(A_BOLD);
- if (addrcmp((void *) addr, (void *) &unspec_addr, ctl->af)) {
+ if (addrcmp((void *) addr, (void *) &ctl->unspec_addr, ctl->af)) {
#ifdef HAVE_IPINFO
- if (is_printii())
+ if (is_printii(ctl))
printw(fmt_ipinfo(ctl, addr));
#endif
name = dns_lookup(ctl, addr);
char msg[80];
int padding = 30;
#ifdef HAVE_IPINFO
- if (is_printii())
- padding += get_iiwidth();
+ if (is_printii(ctl))
+ padding += get_iiwidth(ctl);
#endif
int max_cols = maxx<=SAVED_PINGS+padding ? maxx-padding : SAVED_PINGS;
startstat = padding - 2;
case DisplayCurses:
mtr_curses_open(ctl);
#ifdef HAVE_IPINFO
- asn_open();
+ asn_open(ctl);
#endif
break;
#endif
case DisplayGTK:
gtk_open(ctl);
#ifdef HAVE_IPINFO
- asn_open();
+ asn_open(ctl);
#endif
break;
#endif
#ifdef HAVE_NCURSES
case DisplayCurses:
#ifdef HAVE_IPINFO
- asn_close();
+ asn_close(ctl);
#endif
mtr_curses_close();
break;
extern int display_keyaction(struct mtr_ctl *ctl);
extern void display_loop(struct mtr_ctl *ctl);
extern void display_clear(struct mtr_ctl *ctl);
-
-extern int display_offset; /* only used in text mode */
G_CALLBACK(ReportTreeView_clicked), ctl);
#ifdef HAVE_IPINFO
- if (is_printii()) {
+ if (is_printii(ctl)) {
renderer = gtk_cell_renderer_text_new ();
column = gtk_tree_view_column_new_with_attributes ("ASN",
renderer,
char str[256]="???", *name=str;
addr = net_addr(row);
- if (addrcmp( (void *) addr, (void *) &unspec_addr, ctl->af)) {
+ if (addrcmp( (void *) addr, (void *) &ctl->unspec_addr, ctl->af)) {
if ((name = dns_lookup(ctl, addr))) {
if (ctl->show_ips) {
snprintf(str, sizeof(str), "%s (%s)", name, strlongip(ctl, addr));
-1);
#ifdef HAVE_IPINFO
- if (is_printii())
+ if (is_printii(ctl))
gtk_list_store_set(ReportStore, iter, COL_ASN, fmt_ipinfo(ctl, addr), -1);
#endif
}
#include <stdint.h>
#include <sys/socket.h>
+#include <arpa/inet.h>
/* Typedefs */
#define MAXFLD 20 /* max stats fields to display */
#ifndef HAVE_SOCKLEN_T
-typedef int socklen_t;
+typedef int socklen_t;
#endif
extern char *
char *InterfaceAddress;
char LocalHostname[128];
int ipinfo_no;
+ int ipinfo_max;
+ int iiwidth_len;
int cpacketsize; /* packet size used by ping */
int bitpattern; /* packet bit pattern used by ping */
int tos; /* type of service set in ping packet*/
#ifdef SO_MARK
uint32_t mark;
#endif
+ ip_t unspec_addr;
int af; /* address family of remote target */
int mtrtype; /* type of query packet used */
int fstTTL; /* initial hub(ttl) to ping byMin */
unsigned char fld_active[2 * MAXFLD]; /* SO_MARK to set for ping packet*/
int fld_index[256]; /* default display field (defined by key in net.h) and order */
char available_options[MAXFLD];
+ int display_offset; /* only used in text mode */
void *gtk_data; /* pointer to hold arbitrary gtk data */
unsigned int /* bit field to hold named booleans */
ForceMaxPing:1,
static int recvsock6;
static int sendsock;
static int recvsock;
-ip_t unspec_addr;
#ifdef ENABLE_IPV6
static struct sockaddr_storage sourcesockaddr_struct;
/* impossible? if( totusec < 0 ) totusec = 0 */;
if ( addrcmp( (void *) &(host[index].addr),
- (void *) &unspec_addr, ctl->af ) == 0 ) {
+ (void *) &ctl->unspec_addr, ctl->af ) == 0 ) {
/* should be out of if as addr can change */
addrcpy( (void *) &(host[index].addr), addrcopy, ctl->af );
host[index].mpls = mpls;
if( addrcmp( (void *) &(host[index].addrs[i]), (void *) &addrcopy,
ctl->af ) == 0 ||
addrcmp( (void *) &(host[index].addrs[i]),
- (void *) &unspec_addr, ctl->af ) == 0 ) break;
+ (void *) &ctl->unspec_addr, ctl->af ) == 0 ) break;
i++;
}
if( addrcmp( (void *) &(host[index].addrs[i]), addrcopy, ctl->af ) != 0 &&
(void *) remoteaddress, ctl->af ) == 0 ) {
return at + 1;
} else if ( addrcmp( (void *) &(host[at].addr),
- (void *) &unspec_addr, ctl->af ) != 0 ) {
+ (void *) &ctl->unspec_addr, ctl->af ) != 0 ) {
max = at + 2;
}
}
net_send_query(ctl, batch_at);
for (i=ctl->fstTTL-1;i<batch_at;i++) {
- if ( addrcmp( (void *) &(host[i].addr), (void *) &unspec_addr, ctl->af ) == 0 )
+ if ( addrcmp( (void *) &(host[i].addr), (void *) &ctl->unspec_addr, ctl->af ) == 0 )
n_unknown++;
/* The second condition in the next "if" statement was added in mtr-0.56,
extern struct fields data_fields[MAXFLD];
-/* keys: the value in the array is the index number in data_fields[] */
-extern ip_t unspec_addr;
-
/* MPLS label object */
struct mplslen {
unsigned long label[MAXLABELS]; /* label value */
static size_t snprint_addr(struct mtr_ctl *ctl, char *dst, size_t dst_len, ip_t *addr)
{
- if(addrcmp((void *) addr, (void *) &unspec_addr, ctl->af)) {
+ if(addrcmp((void *) addr, (void *) &ctl->unspec_addr, ctl->af)) {
struct hostent *host = ctl->dns ? addr2host((void *) addr, ctl->af) : NULL;
if (!host) return snprintf(dst, dst_len, "%s", strlongip(ctl, addr));
else if (ctl->dns && ctl->show_ips)
#ifdef HAVE_IPINFO
int len_tmp = len_hosts;
- if (ipinfo_no >= 0) {
- ipinfo_no %= iiwidth_len;
+ if (ctl->ipinfo_no >= 0) {
+ ctl->ipinfo_no %= ctl->iiwidth_len;
if (ctl->reportwide) {
len_hosts++; // space
- len_tmp += get_iiwidth();
- if (!ipinfo_no)
+ len_tmp += get_iiwidth(ctl);
+ if (!ctl->ipinfo_no)
len_tmp += 2; // align header: AS
}
}
snprint_addr(ctl, name, sizeof(name), addr);
#ifdef HAVE_IPINFO
- if (is_printii()) {
+ if (is_printii(ctl)) {
snprintf(fmt, sizeof(fmt), " %%2d. %%s%%-%zus", len_hosts);
snprintf(buf, sizeof(buf), fmt, at+1, fmt_ipinfo(ctl, addr), name);
} else {
addr2 = net_addrs(at, z);
mplss = net_mplss(at, z);
int found = 0;
- if ((addrcmp ((void *) &unspec_addr, (void *) addr2, ctl->af)) == 0)
+ if ((addrcmp ((void *) &ctl->unspec_addr, (void *) addr2, ctl->af)) == 0)
break;
for (w = 0; w < z; w++)
/* Ok... checking if there are ips repeated on same hop */
if (!found) {
#ifdef HAVE_IPINFO
- if (is_printii()) {
+ if (is_printii(ctl)) {
if (mpls->labels && z == 1 && ctl->enablempls)
print_mpls(mpls);
snprint_addr(ctl, name, sizeof(name), addr2);
/* No multipath */
#ifdef HAVE_IPINFO
- if (is_printii()) {
+ if (is_printii(ctl)) {
if (mpls->labels && z == 1 && ctl->enablempls)
print_mpls(mpls);
} else {
if (at == net_min(ctl)) {
printf("Mtr_Version,Start_Time,Status,Host,Hop,Ip,");
#ifdef HAVE_IPINFO
- if(!ipinfo_no) {
+ if(!ctl->ipinfo_no) {
printf("Asn,");
}
#endif
}
#ifdef HAVE_IPINFO
- if(!ipinfo_no) {
+ if(!ctl->ipinfo_no) {
char* fmtinfo = fmt_ipinfo(ctl, addr);
fmtinfo = trim(fmtinfo);
printf("MTR.%s,%lld,%s,%s,%d,%s,%s", PACKAGE_VERSION, (long long)now, "OK", ctl->Hostname,
break;
#ifdef HAVE_IPINFO
case ActionII:
- ipinfo_no++;
- if (ipinfo_no > ipinfo_max)
- ipinfo_no = 0;
+ ctl->ipinfo_no++;
+ if (ctl->ipinfo_no > ctl->ipinfo_max)
+ ctl->ipinfo_no = 0;
break;
case ActionAS:
- ipinfo_no = ipinfo_no?0:ipinfo_max;
+ ctl->ipinfo_no = ctl->ipinfo_no ? 0 : ctl->ipinfo_max;
break;
#endif
*/
for(at = 0; at < max; at++) {
addr = net_addr(at);
- if(addrcmp((void*)addr, (void*)&unspec_addr, ctl->af)) {
+ if(addrcmp((void*)addr, (void*)&ctl->unspec_addr, ctl->af)) {
char str[256], *name;
if (!(name = dns_lookup(ctl, addr)))
name = strlongip(ctl, addr);