Tested with gcc (GCC) 6.2.1
20160830 and following options
CFLAGS="-O -fPIC -D_FORTIFY_SOURCE -W -Wabi -DANOTHER_BRICK_IN_THE -Wall
-Wattributes -Wbad-function-cast -Wbuiltin-macro-redefined -Wcast-align
-Wchar-subscripts -Wcoverage-mismatch -Wcpp -Wdeclaration-after-statement
-Wdeprecated -Wdeprecated-declarations -Wdisabled-optimization
-Wdiv-by-zero -Wendif-labels -Wextra -Wfloat-equal -Wformat-contains-nul
-Wformat-extra-args -Wformat-nonliteral -Wformat-security -Wformat-y2k
-Wformat-zero-length -Wformat=2 -Winit-self -Winvalid-pch -Wlogical-op
-Wmissing-declarations -Wmissing-include-dirs -Wmissing-noreturn
-Wmissing-prototypes -Wmultichar -Wnested-externs -Wno-format-nonliteral
-Wno-inline -Wno-logical-op -Wno-long-long -Wno-missing-field-initializers
-Wno-overlength-strings -Wno-sign-compare -Wno-unused-parameter
-Wno-unused-result -Wnormalized=nfc -Wold-style-definition -Woverflow
-Woverlength-strings -Wpacked -Wpacked-bitfield-compat -Wpointer-arith
-Wpointer-to-int-cast -Wpragmas -Wredundant-decls -Wshadow -Wsign-compare
-Wstrict-aliasing -Wstrict-aliasing=2 -Wstrict-prototypes
-Wsuggest-attribute=noreturn -Wsync-nand -Wtrampolines -Wtype-limits
-Wundef -Wuninitialized -Wunknown-pragmas -Wunused -Wunused-local-typedefs
-Wvla -Wvolatile-register-var -Wwrite-strings -fdata-sections
-fdiagnostics-show-option -ffunction-sections -fno-common -funit-at-a-time
-fvisibility=hidden -pipe" ./configure && make
// originX.asn.cymru.com txtrec: ASN | Route | Country | Registry | Allocated
static char* split_txtrec(struct mtr_ctl *ctl, char *txt_rec) {
+ char* prev;
+ char* next;
+ int i = 0, j;
+
if (!txt_rec)
return NULL;
if (iihash) {
}
}
- char* prev = txt_rec;
- char* next;
- int i = 0, j;
+ prev = txt_rec;
while ((next = strchr(prev, ITEMSEP)) && (i < ITEMSMAX)) {
*next = '\0';
#endif
static char *get_ipinfo(struct mtr_ctl *ctl, ip_t *addr){
- if (!addr)
- return NULL;
-
char key[NAMELEN];
char lookup_key[NAMELEN];
+ char *val = NULL;
+ ENTRY item;
+
+ if (!addr)
+ return NULL;
if (ctl->af == AF_INET6) {
#ifdef ENABLE_IPV6
return NULL;
}
- char *val = NULL;
- ENTRY item;
-
if (iihash) {
+ ENTRY *found_item;
+
DEB_syslog(LOG_INFO, ">> Search: %s", key);
item.key = key;;
- ENTRY *found_item;
if ((found_item = hsearch(item, FIND))) {
if (!(val = (*((items_t*)found_item->data))[ctl->ipinfo_no]))
val = (*((items_t*)found_item->data))[0];
static char *format_number (int n, int w, char *buf)
{
// XXX todo: implement w != 5..
- if (w != 5) return ("unimpl");
+ if (w != 5) {
+ snprintf (buf, w+1, "%s", "unimpl");
+ return (buf);
+ }
if (n < 100000) {
- snprintf (buf, w+1, "%5d", n);
return buf;
}
if (n < 1000000) {
move(0, 0);
attron(A_BOLD);
- pwcenter("My traceroute [v" PACKAGE_VERSION "]");
+ snprintf(buf, sizeof(buf), "%s%s%s", "My traceroute [v", PACKAGE_VERSION, "]");
+ pwcenter(buf);
attroff(A_BOLD);
mvprintw(1, 0, "%s (%s)", ctl->LocalHostname, net_localaddr());
} else {
char msg[80];
int padding = 30;
+ int max_cols;
+
#ifdef HAVE_IPINFO
if (is_printii(ctl))
padding += get_iiwidth(ctl->ipinfo_no);
#endif
- int max_cols = maxx<=SAVED_PINGS+padding ? maxx-padding : SAVED_PINGS;
+ max_cols = maxx <= SAVED_PINGS + padding ? maxx-padding : SAVED_PINGS;
startstat = padding - 2;
sprintf(msg, " Last %3d pings", max_cols);
extern void mtr_curses_open(struct mtr_ctl *ctl)
{
+ int bg_col = 0;
+ int i;
+
initscr();
raw();
noecho();
- int bg_col = 0;
start_color();
#ifdef HAVE_USE_DEFAULT_COLORS
if (use_default_colors() == OK)
bg_col = -1;
#endif
- int i;
for (i = 0; i < 8; i++)
init_pair(i+1, i, bg_col);
#include "mtr.h"
#include "display.h"
-#include "mtr-curses.h"
-#include "mtr-gtk.h"
#include "report.h"
#include "select.h"
#include "raw.h"
#include "dns.h"
#include "asn.h"
#include "mtr-gtk.h"
+#include "utils.h"
#include "img/mtr_icon.xpm"
#endif
static void gtk_add_ping_timeout (struct mtr_ctl *ctl)
{
+ int dt;
+
if(gtk_toggle_button_get_active((GtkToggleButton *)Pause_Button)){
return;
}
- int dt;
dt = calc_deltatime (ctl->WaitTime);
gtk_redraw(ctl);
ping_timeout_timer = g_timeout_add(dt / 1000, gtk_ping, ctl);
extern void gtk_open(struct mtr_ctl *ctl)
{
GdkPixbuf *icon;
-
- int argc;
+ int argc = 1;
char *args[2];
char **argv;
- argc = 1;
+
argv = args;
- argv[0] = "";
+ argv[0] = xstrdup("");
argv[1] = NULL;
gtk_do_init(&argc, &argv);
+ free(argv[0]);
icon = gdk_pixbuf_new_from_xpm_data((const char**)mtr_icon);
gtk_window_set_default_icon(icon);
#endif
{ NULL, 0, NULL, 0 }
};
- static const size_t num_options = sizeof(long_options) / sizeof(struct option);
+ enum { num_options = sizeof(long_options) / sizeof(struct option) };
char short_options[num_options * 2];
size_t n, p;
static void parse_mtr_options (struct mtr_ctl *ctl, char *string)
{
- int argc;
+ int argc = 1;
char *argv[128], *p;
if (!string) return;
-
- argv[0] = "mtr";
+ argv[0] = xstrdup(PACKAGE_NAME);
argc = 1;
p = strtok (string, " \t");
while (p != NULL && ((size_t) argc < (sizeof(argv)/sizeof(argv[0])))) {
}
parse_arg (ctl, argc, argv);
+ free(argv[0]);
optind = 0;
}
#ifdef ENABLE_IPV6
struct sockaddr_in6 * sa6;
#endif
+ time_t now;
+ names_t *head;
struct mtr_ctl ctl;
memset(&ctl, 0, sizeof(ctl));
/* initialize non-null values */
error(EXIT_FAILURE, 0, "Couldn't determine raw socket type");
}
- time_t now = time(NULL);
-
if (!names) append_to_names ("localhost"); // default: localhost.
- names_t* head = names;
+ head = names;
while (names != NULL) {
ctl.Hostname = names->name;
display_loop(&ctl);
net_end_transit();
+ now = time(NULL);
display_close(&ctl, now);
unlock(stdout);
size_t tsize = psize + dsize;
char *csumpacket;
int ret;
+ struct UDPv4PHeader *prepend;
+ struct UDPv4PHeader *udppheader;
+ struct UDPHeader *content;
+ struct UDPHeader *udpdata;
csumpacket = xmalloc(tsize);
memset(csumpacket, (unsigned char) abs(ctl->bitpattern), tsize);
csumpacket[psize + sizeof(struct UDPHeader) + 1] = 0;
}
- struct UDPv4PHeader *prepend = (struct UDPv4PHeader *) csumpacket;
- struct UDPv4PHeader *udppheader = (struct UDPv4PHeader *) pheader;
+ prepend = (struct UDPv4PHeader *) csumpacket;
+ udppheader = (struct UDPv4PHeader *) pheader;
prepend->saddr = udppheader->saddr;
prepend->daddr = udppheader->daddr;
prepend->zero = 0;
prepend->protocol = udppheader->protocol;
prepend->len = udppheader->len;
- struct UDPHeader *content = (struct UDPHeader *)(csumpacket + psize);
- struct UDPHeader *udpdata = (struct UDPHeader *) udata;
+ content = (struct UDPHeader *)(csumpacket + psize);
+ udpdata = (struct UDPHeader *) udata;
content->srcport = udpdata->srcport;
content->dstport = udpdata->dstport;
content->length = udpdata->length;
/* Attempt to find the host at a particular number of hops away */
static void net_send_query(struct mtr_ctl *ctl, int index)
{
- if (ctl->mtrtype == IPPROTO_TCP) {
- net_send_tcp(ctl, index);
- return;
- }
-
-#ifdef HAS_SCTP
- if (ctl->mtrtype == IPPROTO_SCTP) {
- net_send_sctp(ctl, index);
- return;
- }
-#endif
-
/*ok char packet[sizeof(struct IPHeader) + sizeof(struct ICMPHeader)];*/
char packet[MAXPACKET];
struct IPHeader *ip = (struct IPHeader *) packet;
struct UDPHeader *udp = NULL;
struct UDPv4PHeader *udpp = NULL;
uint16_t checksum_result;
-
/*ok int packetsize = sizeof(struct IPHeader) + sizeof(struct ICMPHeader) + datasize;*/
int rv;
static int first=1;
int ttl, iphsize = 0, echotype = 0, salen = 0;
-
- ttl = index + 1;
-
#ifdef ENABLE_IPV6
/* offset for ipv6 checksum calculation */
int offset = 6;
#endif
+ if (ctl->mtrtype == IPPROTO_TCP) {
+ net_send_tcp(ctl, index);
+ return;
+ }
+
+#ifdef HAS_SCTP
+ if (ctl->mtrtype == IPPROTO_SCTP) {
+ net_send_sctp(ctl, index);
+ return;
+ }
+#endif
+
+ ttl = index + 1;
+
if ( packetsize < MINPACKET ) packetsize = MINPACKET;
if ( packetsize > MAXPACKET ) packetsize = MAXPACKET;
if ( ctl->mtrtype == IPPROTO_UDP && ctl->remoteport && packetsize < (MINPACKET + 2)) {
char fmt[16];
size_t len=0;
size_t len_hosts = 33;
+#ifdef HAVE_IPINFO
+ int len_tmp = len_hosts;
+ const size_t iiwidth_len = get_iiwidth_len();
+#endif
if (ctl->reportwide)
{
}
#ifdef HAVE_IPINFO
- int len_tmp = len_hosts;
- const size_t iiwidth_len = get_iiwidth_len();
if (ctl->ipinfo_no >= 0 && iiwidth_len) {
ctl->ipinfo_no %= iiwidth_len;
if (ctl->reportwide) {
/* z is starting at 1 because addrs[0] is the same that addr */
for (z = 1; z < MAXPATH ; z++) {
+ int found = 0;
addr2 = net_addrs(at, z);
mplss = net_mplss(at, z);
- int found = 0;
if ((addrcmp ((void *) &ctl->unspec_addr, (void *) addr2, ctl->af)) == 0)
break;
for (w = 0; w < z; w++)
printf(" \"count\": \"%d\",\n", at+1);
printf(" \"host\": \"%s\",\n", name);
for( i=0; i<MAXFLD; i++ ) {
+ const char *format;
+
j = ctl->fld_index[ctl->fld_active[i]];
/* Commas */
if (j <= 0) continue; // Field nr 0, " " shouldn't be printed in this method.
/* Format value */
- const char *format;
format = data_fields[j].format;
if( strchr(format, 'f') ) {
format = "%.2f";
printf(" <HUB COUNT=\"%d\" HOST=\"%s\">\n", at+1, name);
for( i=0; i<MAXFLD; i++ ) {
+ const char *title;
+
j = ctl->fld_index[ctl->fld_active[i]];
if (j <= 0) continue; // Field nr 0, " " shouldn't be printed in this method.
snprintf(name, sizeof(name), "%s%s%s", " <%s>", data_fields[j].format, "</%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";
#include "net.h"
#include "asn.h"
#include "display.h"
+#include "select.h"
static double dnsinterval;
static struct timeval intervaltime;