diff --git a/AUTHORS b/AUTHORS
index 3ecfe55..c3ec5af 100644
--- a/AUTHORS
+++ b/AUTHORS
@@ -25,9 +25,9 @@
         Mike Simons <msimons@moria.simons-clan.com>
         Aaron Scarisbrick
         Craig Milo Rogers <Rogers@ISI.EDU>
-        Antonio Querubin <tony@aloha.net>
+        Antonio Querubin <tony@lavanauts.org>
         Russell Nelson <rn-mtr@crynwr.com>
-        Davin Milun <milun@acm.org>
+        Davin Milun
         Josh Martin <jmartin@columbiaservices.net>
         Alexander V. Lukyanov <lav@yars.free.net>
         Charles Levert <charles@comm.polymtl.ca> 
diff --git a/NEWS b/NEWS
index a7c75fa..9d27366 100644
--- a/NEWS
+++ b/NEWS
@@ -1,7 +1,21 @@
 WHAT'S NEW?
 
-V0.84 Fix some glib things by Thomas. 
+V0.86 Fixed default hostname logic. 
+      Fix for NetBSD: 64bit time_t -- Thomas Klausner
+      Fix unnecessary runtime dependency on glib from VSYakovetsky through 
+           Thomas
+      Inverted IPINFO define in the code. Removes double negatives. 
+         -- Vladimir Yakovetsky, REW.
+      Fixed failure on IPv4 only systems when IPv6 was available at
+         compile time. -- REW.
+      Fixed (longstanding) bug that mtr used 100% cpu when paused. 
+      Cosmetic changes from Richard Hartman. 
+
+V0.85 Fixed asn support. (better compile time detection of required features)
+      support for multiple hostnames. (fixed in 0.86)
+      support for TCP probes
 
+V0.84 Fix some glib things by Thomas. 
 
 V0.83 Move to github. Mostly done by Travis.
 
diff --git a/README b/README
index c7588d0..f2f6538 100644
--- a/README
+++ b/README
@@ -10,7 +10,7 @@ WHAT IS MTR?
   quality of the link to each machine.  As it does this, it prints
   running statistics about each machine.
 
-  mtr is distributed under the GNU General Public License. 
+  mtr is distributed under the GNU General Public License version 2.
   See the COPYING file for details.  
 
 INSTALLING
diff --git a/SECURITY b/SECURITY
index 6cfc40b..4ff73a9 100644
--- a/SECURITY
+++ b/SECURITY
@@ -7,15 +7,16 @@ minimal.
 Or you can make mtr setuid-root, and the following applies to you....
 
 Since mtr is installed as suid-root, some concern over security is
-justified.  Since version 0.21 of mtr, does the following two things
+justified.  Since version 0.21, mtr does the following two things
 after it is launched:
 
 *  mtr requests a pair of raw sockets from the kernel.  
-*  mtr sets the effective uid to match the real uid.
+*  mtr drops root privileges by setting the effective uid to match
+   uid or the user calling mtr.
 
 See main() in mtr.c and net_preopen() in net.c for the details of this
-process.  Note that no code from GTK+ or curses is executed before the
-drop in permissions.
+process.  Note that no code from GTK+ or curses is executed before
+dropping root privileges.
 
 This should severely limit the possibilities of using mtr to breach
 system security.  This means the worst case scenerio is as follows:
@@ -24,10 +25,10 @@ Due to some oversight in the mtr code, a malicious user is able to
 overrun one of mtr's internal buffers with binary code that is
 eventually executed.  The malicious user is still not able to read
 from or write to any system files which they wouldn't normally have
-permission to write to.  The only priveledge gained is access to the
-raw socket descriptors, which would allow the malicious user to listen
-to all ICMP packets arriving at the system, and send forged packets
-with arbitrary contents.
+permission to read or write to, repectively.  The only privilege
+gained is access to the raw socket descriptors, which would allow
+the malicious user to listen to all ICMP packets arriving at the
+system, and to send forged packets with arbitrary contents.
 
 The mtr-code does its best to prevent calling of external library
 code before dropping privileges. It seems that C++ library code has 
@@ -36,7 +37,7 @@ loader/linker.  That would mean that we're still vulnerable to
 errors in that code. This is why I would prefer to drop the backends, 
 have mtr-core always run in "raw" mode, and have the backends interpret
 the output from the mtr-core. Maybe a nice project for a college-level
-student. 
+student.
 
 If you have further questions or comments about security issues,
 please direct them to the mtr mailing list.  See README for details.
diff --git a/asn.c b/asn.c
index f384f19..33622ca 100644
--- a/asn.c
+++ b/asn.c
@@ -16,12 +16,14 @@
     Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 */
 
+#include "config.h"
+
 #include <unistd.h>
 #include <stdio.h>
 #include <stdlib.h>
 #include <sys/types.h>
 
-#ifndef __APPLE__
+#ifdef __APPLE__
 #define BIND_8_COMPAT
 #endif
 #include <arpa/nameser.h>
@@ -35,7 +37,6 @@
 #include <sys/socket.h>
 #include <search.h>
 
-#include "config.h"
 #include "mtr.h"
 #include "asn.h"
 
diff --git a/asn.h b/asn.h
index d5a6bd3..dd2d440 100644
--- a/asn.h
+++ b/asn.h
@@ -16,6 +16,18 @@
     Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 */
 
+// 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
+// define. 
+//
+// Similarly, this include file should be included unconditially. 
+// It will evaluate to nothing if we don't need it. 
+
+#ifndef NO_IPINFO
+#define IPINFO
+
+
 extern int ipinfo_no;
 extern int ipinfo_max;
 extern int iiwidth_len;
@@ -26,3 +38,4 @@ char *fmt_ipinfo(ip_t *addr);
 int get_iiwidth(void);
 int is_printii(void);
 
+#endif
diff --git a/configure.ac b/configure.ac
index 97f1372..d5d1b0e 100644
--- a/configure.ac
+++ b/configure.ac
@@ -1,4 +1,4 @@
-AC_INIT([mtr], [0.85])
+AC_INIT([mtr], [0.86])
 AC_CONFIG_SRCDIR([mtr.c])
 AM_INIT_AUTOMAKE([foreign])
 
@@ -42,25 +42,22 @@ AC_ARG_WITH(gtk,
 [  --without-gtk           Do not try to use GTK+ at all],
 WANTS_GTK=$withval, WANTS_GTK=yes)
 
-AC_ARG_WITH(glib,
-[  --without-glib          Do not try to use glib at all],
-WANTS_GLIB=$withval, WANTS_GLIB=yes)
-
 AC_ARG_WITH([ipinfo],
 [  --without-ipinfo        Do not try to use ipinfo lookup at all],
-[case "${withval}" in
-  yes) ipinfo=true ;;
-  no)  ipinfo=false ;;
-  *) AC_MSG_ERROR([bad value ${withval} for --with-ipinfo]) ;;
-esac],[ipinfo=true])
-AM_CONDITIONAL([IPINFO], [test x$ipinfo = xtrue])
-if test "x$ipinfo" = "xfalse"; then
-	AC_DEFINE([NO_IPINFO], [1], [Define to disable ipinfo lookup])
-fi
+[ipinfo="${withval}"], [ipinfo=yes])
+AM_CONDITIONAL([IPINFO], [test x$ipinfo = xyes])
 
 AC_ARG_ENABLE(ipv6,
 [  --disable-ipv6          Do not enable IPv6],
 WANTS_IPV6=$enableval, WANTS_IPV6=yes)
+
+m4_ifndef([AM_PATH_GTK_2_0], [m4_defun([AM_PATH_GTK_2_0], [AC_MSG_ERROR([
+  Could not locate the gtk2 automake macros, these are usually located in
+    .../share/aclocal/gtk-2.0.m4
+  Before running bootstrap try setting the environment variable
+    ACLOCAL_PATH="/own/dir"
+  or configure --without-gtk.
+])])])
    
 if test "x$WANTS_GTK" = "xyes"; then
         AM_PATH_GTK_2_0(2.6.0, CFLAGS="$CFLAGS $GTK_CFLAGS"
@@ -71,11 +68,10 @@ if test "x$WANTS_GTK" = "xyes"; then
 else
 	AC_DEFINE(NO_GTK)
 	GTK_OBJ=""
-	if test "x$WANTS_GLIB" = "xyes"; then
-		PKG_CHECK_MODULES([GLIB], [glib-2.0])
-	else
-		AC_DEFINE(NO_GLIB, 1, [Define if you don't have the glib libraries available.])
-	fi
+fi
+
+if test "x$ipinfo" = "xno"; then
+	AC_DEFINE([NO_IPINFO], [1], [Define to disable ipinfo lookup])
 fi
 
 AC_CHECK_FUNC(socket, , 
diff --git a/curses.c b/curses.c
index a103a43..3904cb1 100644
--- a/curses.c
+++ b/curses.c
@@ -16,7 +16,8 @@
     Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 */
 
-#include <config.h>
+#include "config.h"
+
 #include <strings.h>
 #include <unistd.h>
 
@@ -60,12 +61,11 @@
 
 #include "mtr.h"
 #include "mtr-curses.h"
-#include "display.h"
 #include "net.h"
 #include "dns.h"
-#ifndef NO_IPINFO
 #include "asn.h"
-#endif
+#include "display.h"
+
 #include "version.h"
 #endif
 
@@ -121,7 +121,7 @@ int mtr_curses_keyaction(void)
     return ActionMPLS;
   if (tolower(c) == 'n')
     return ActionDNS;
-#ifndef NO_IPINFO
+#ifdef IPINFO
   if (tolower(c) == 'y')
     return ActionII;
   if (tolower(c) == 'z')
@@ -304,7 +304,7 @@ int mtr_curses_keyaction(void)
     printw("  b <c>   set ping bit pattern to c(0..255) or random(c<0)\n" );
     printw("  Q <t>   set ping packet's TOS to t\n" );
     printw("  u       switch between ICMP ECHO and UDP datagrams\n" );
-#ifndef NO_IPINFO
+#ifdef IPINFO
     printw("  y       switching IP info\n");
     printw("  z       toggle ASN info on/off\n");
     pressanykey_row += 2;
@@ -344,7 +344,7 @@ void mtr_curses_hosts(int startstat)
       name = dns_lookup(addr);
       if (! net_up(at))
 	attron(A_BOLD);
-#ifndef NO_IPINFO
+#ifdef IPINFO
       if (is_printii())
         printw(fmt_ipinfo(addr));
 #endif
@@ -401,7 +401,7 @@ void mtr_curses_hosts(int startstat)
         name = dns_lookup(addrs);
         if (! net_up(at)) attron(A_BOLD);
         printw("\n    ");
-#ifndef NO_IPINFO
+#ifdef IPINFO
         if (is_printii())
           printw(fmt_ipinfo(addrs));
 #endif
@@ -490,13 +490,28 @@ void mtr_curses_init() {
 }
 
 
+static int block_col[NUM_FACTORS+1] =
+{	// 1:black 2:red 3:green 4:brown/yellow 5:blue 6:magenta 7:cyan 8:white
+        COLOR_PAIR(2)|A_BOLD,
+	A_NORMAL,
+	COLOR_PAIR(3),
+	COLOR_PAIR(3)|A_BOLD,
+	COLOR_PAIR(4)|A_BOLD,
+	COLOR_PAIR(6)|A_BOLD,
+	COLOR_PAIR(6),
+	COLOR_PAIR(2),
+	COLOR_PAIR(2)|A_BOLD
+};
+
 void mtr_print_scaled(int ms) 
 {
 	int i;
 
 	for (i = 0; i < NUM_FACTORS; i++) {
 		if (ms <= scale[i]) {
+			attrset(block_col[i+1]);
 			printw("%c", block_map[i]);
+			attrset(A_NORMAL);
 			return;
 		}
 	}
@@ -514,9 +529,9 @@ void mtr_fill_graph(int at, int cols)
 		if (saved[i] == -2) {
 			printw(" ");
 		} else if (saved[i] == -1) {
-			attron(A_BOLD);
-			printw("?");
-			attroff(A_BOLD);
+		        attrset(block_col[0]);
+			printw("%c", '?');
+			attrset(A_NORMAL);
 		} else {
 			if (display_mode == 1) {
 				if (saved[i] > scale[6]) {
@@ -552,7 +567,7 @@ void mtr_curses_graph(int startstat, int cols)
 		if (! net_up(at))
 			attron(A_BOLD);
 		if (addrcmp((void *) addr, (void *) &unspec_addr, af)) {
-#ifndef NO_IPINFO
+#ifdef IPINFO
 			if (is_printii())
 				printw(fmt_ipinfo(addr));
 #endif
@@ -642,7 +657,7 @@ void mtr_curses_redraw(void)
   } else {
     char msg[80];
     int padding = 30;
-#ifndef NO_IPINFO
+#ifdef IPINFO
     if (is_printii())
       padding += get_iiwidth();
 #endif
@@ -664,8 +679,16 @@ void mtr_curses_redraw(void)
     attroff(A_BOLD);
     
     for (i = 0; i < NUM_FACTORS-1; i++) {
-      printw("  %c:%d ms", block_map[i], scale[i]/1000);
+      printw("  ");
+      attrset(block_col[i+1]);
+      printw("%c", block_map[i]);
+      attrset(A_NORMAL);
+      printw(":%d ms", scale[i]/1000);
     }
+    printw("  ");
+    attrset(block_col[NUM_FACTORS]);
+    printw("%c", block_map[NUM_FACTORS-1]);
+    attrset(A_NORMAL);
   }
 
   refresh();
@@ -677,6 +700,10 @@ void mtr_curses_open(void)
   initscr();
   raw();
   noecho(); 
+  start_color();
+  int i;
+  for (i = 0; i < 8; i++)
+      init_pair(i+1, i, 0);
 
   mtr_curses_init();
   mtr_curses_redraw();
diff --git a/display.c b/display.c
index cc5cd59..3545467 100644
--- a/display.c
+++ b/display.c
@@ -16,7 +16,8 @@
     Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 */
 
-#include <config.h>
+#include "config.h"
+
 #include <stdio.h>
 #include <stdlib.h>
 #include <sys/types.h>
@@ -29,9 +30,7 @@
 #include "select.h"
 #include "raw.h"
 #include "dns.h"
-#ifndef NO_IPINFO
-#include <asn.h>
-#endif
+#include "asn.h"
 
 extern int DisplayMode;
 
@@ -97,7 +96,7 @@ void display_open(void)
     break;
   case DisplayCurses:
     mtr_curses_open();  
-#ifndef NO_IPINFO
+#ifdef IPINFO
     if (ipinfo_no >= 0)
         asn_open();
 #endif
@@ -128,7 +127,7 @@ void display_close(time_t now)
     csv_close(now);
     break;
   case DisplayCurses:
-#ifndef NO_IPINFO
+#ifdef IPINFO
     if (ipinfo_no >= 0)
         asn_close();
 #endif
diff --git a/display.h b/display.h
index 4ed2d66..6168914 100644
--- a/display.h
+++ b/display.h
@@ -22,7 +22,7 @@
    (notably the one on Irix 5.2) do not like that. */ 
 enum { ActionNone,  ActionQuit,  ActionReset,  ActionDisplay, 
        ActionClear, ActionPause, ActionResume, ActionMPLS, ActionDNS, 
-#ifndef NO_IPINFO
+#ifdef IPINFO
        ActionII, ActionAS,
 #endif
        ActionScrollDown, ActionScrollUp  };
diff --git a/dns.c b/dns.c
index 371934f..32b83c2 100644
--- a/dns.c
+++ b/dns.c
@@ -22,7 +22,8 @@
     Released under GPL, as above.
 */
 
-#include <config.h>
+#include "config.h"
+
 #include <sys/types.h>
 #include <sys/time.h>
 #include <sys/select.h>
@@ -56,10 +57,8 @@
 
 #ifdef ENABLE_IPV6
 #ifdef __GLIBC__
-#define NSCOUNT6 myres._u._ext.nscount6
 #define NSSOCKADDR6(i) (myres._u._ext.nsaddrs[i])
 #else
-#define NSCOUNT6 myres.nscount
 #define NSSOCKADDR6(i) (&(myres._u._ext.ext->nsaddrs[i].sin6))
 #endif
 #endif
@@ -529,10 +528,12 @@ void dns_open(void)
 #ifdef ENABLE_IPV6
   resfd6 = socket(AF_INET6, SOCK_DGRAM, 0);
   if (resfd6 == -1) {
+    // consider making removing this warning. For now leave it in to see 
+    // new code activated. -- REW
     fprintf(stderr,
             "Unable to allocate IPv6 socket for nameserver communication: %s\n",
 	    strerror(errno));
-    exit(-1);
+    //    exit(-1);
   }
 #endif
   option = 1;
@@ -543,11 +544,13 @@ void dns_open(void)
     exit(-1);
   }
 #ifdef ENABLE_IPV6
-  if (setsockopt(resfd6,SOL_SOCKET,SO_BROADCAST,(char *)&option,sizeof(option))) {
-    fprintf(stderr,
-            "Unable to setsockopt() on IPv6 nameserver communication socket: %s\n",
-	    strerror(errno));
-    exit(-1);
+  if (resfd6 > 0) {
+    if (setsockopt(resfd6,SOL_SOCKET,SO_BROADCAST,(char *)&option,sizeof(option))) {
+      fprintf(stderr,
+	      "Unable to setsockopt() on IPv6 nameserver communication socket: %s\n",
+	      strerror(errno));
+      exit(-1);
+    }
   }
 #endif
   longipstr( "127.0.0.1", &localhost, AF_INET );
@@ -932,19 +935,19 @@ void dorequest(char *s,int type,word id)
   }
   hp = (packetheader *)buf;
   hp->id = id;	/* htons() deliberately left out (redundant) */
-#ifdef ENABLE_IPV6
-  for (i = 0;i < NSCOUNT6;i++) {
-    if (!NSSOCKADDR6(i))
-      continue;
-    if (NSSOCKADDR6(i)->sin6_family == AF_INET6)
-      (void)sendto(resfd6,buf,r,0,(struct sockaddr *) NSSOCKADDR6(i),
-		   sizeof(struct sockaddr_in6));
-  }
-#endif
   for (i = 0;i < myres.nscount;i++)
     if (myres.nsaddr_list[i].sin_family == AF_INET)
       (void)sendto(resfd,buf,r,0,(struct sockaddr *)&myres.nsaddr_list[i],
 		   sizeof(struct sockaddr));
+#ifdef ENABLE_IPV6
+    else if (resfd6 > 0) {
+      if (!NSSOCKADDR6(i))
+	continue;
+      if (NSSOCKADDR6(i)->sin6_family == AF_INET6)
+	(void)sendto(resfd6,buf,r,0,(struct sockaddr *) NSSOCKADDR6(i),
+		     sizeof(struct sockaddr_in6));
+    }
+#endif
 }
 
 void resendrequest(struct resolve *rp,int type)
@@ -1327,13 +1330,16 @@ void dns_ack6(void)
   int r,i;
   static char addrstr[INET6_ADDRSTRLEN];
 
+  // Probably not necessary. -- REW
+  if (resfd6 < 0) return; 
+
   r = recvfrom(resfd6,(byte *)resrecvbuf,MaxPacketsize,0,
                from, &fromlen);
   if (r > 0) {
     /* Check to see if this server is actually one we sent to */
     if ( addrcmp( (void *) &(from6->sin6_addr), (void *) &localhost6,
                   (int) AF_INET6 ) == 0 ) {
-      for (i = 0;i < NSCOUNT6;i++) {
+      for (i = 0;i < myres.nscount;i++) {
         if (!NSSOCKADDR6(i))
           continue;
 
@@ -1344,14 +1350,14 @@ void dns_ack6(void)
 	  break;
       }
     } else
-      for (i = 0;i < NSCOUNT6;i++) {
+      for (i = 0;i < myres.nscount;i++) {
         if (!NSSOCKADDR6(i))
           continue;
 	if ( addrcmp( (void *) &(NSSOCKADDR6(i)->sin6_addr),
 		      (void *) &(from6->sin6_addr), AF_INET6 ) == 0 )
 	  break;
       }
-    if (i == NSCOUNT6) {
+    if (i == myres.nscount) {
       snprintf(tempstring, sizeof(tempstring), 
 	       "Resolver error: Received reply from unknown source: %s",
 	       inet_ntop( AF_INET6, &(from6->sin6_addr), addrstr,
diff --git a/getopt.c b/getopt.c
index 3d43e26..e2f8758 100644
--- a/getopt.c
+++ b/getopt.c
@@ -27,7 +27,7 @@
 #endif
 
 #ifdef HAVE_CONFIG_H
-#include <config.h>
+#include "config.h"
 #endif
 
 #if !defined (__STDC__) || !__STDC__
diff --git a/getopt1.c b/getopt1.c
index bccf8b2..0a2d405 100644
--- a/getopt1.c
+++ b/getopt1.c
@@ -16,7 +16,7 @@
    Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.  */
 
 #ifdef HAVE_CONFIG_H
-#include <config.h>
+#include "config.h"
 #endif
 
 #include "getopt.h"
diff --git a/gtk.c b/gtk.c
index d00f769..7faa132 100644
--- a/gtk.c
+++ b/gtk.c
@@ -17,7 +17,7 @@
     Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 */
 
-#include <config.h>
+#include "config.h"
 
 #include <stdio.h>
 #include <stdlib.h>
@@ -615,8 +615,10 @@ void gtk_loop(void)
   net_iochannel = g_io_channel_unix_new(net_waitfd());
   g_io_add_watch(net_iochannel, G_IO_IN, gtk_net_data, NULL);
 #ifdef ENABLE_IPV6
-  dns_iochannel = g_io_channel_unix_new(dns_waitfd6());
-  g_io_add_watch(dns_iochannel, G_IO_IN, gtk_dns_data6, NULL);
+  if (dns_waitfd6() > 0) {
+    dns_iochannel = g_io_channel_unix_new(dns_waitfd6());
+    g_io_add_watch(dns_iochannel, G_IO_IN, gtk_dns_data6, NULL);
+  }
 #endif
   dns_iochannel = g_io_channel_unix_new(dns_waitfd());
   g_io_add_watch(dns_iochannel, G_IO_IN, gtk_dns_data, NULL);
diff --git a/mtr.8 b/mtr.8
index c13d05a..16770c5 100644
--- a/mtr.8
+++ b/mtr.8
@@ -1,20 +1,14 @@
-.TH MTR 8 "March 4, 1999" "mtr" "mtr"
-
-
+.TH MTR 8 "July 12, 2014" "mtr" "mtr"
 .SH NAME
 mtr \- a network diagnostic tool
-
-
 .SH SYNOPSIS
-.B mtr 
-[\c
-.B \-hvrctglspeniuTP46\c
-]
+.B mtr
 [\c
-.B \-\-help\c
+.BR \-4 |\c
+.B \-6\c
 ]
 [\c
-.B \-\-version\c
+.BI \-F \ FILENAME\c
 ]
 [\c
 .B \-\-report\c
@@ -23,19 +17,22 @@ mtr \- a network diagnostic tool
 .B \-\-report-wide\c
 ]
 [\c
-.B \-\-report\-cycles\ COUNT\c
+.B \-\-xml\c
 ]
 [\c
-.B \-\-curses\c
+.B \-\-gtk\c
 ]
 [\c
-.B \-\-split\c
+.B \-\-curses\c
 ]
 [\c
 .B \-\-raw\c
 ]
 [\c
-.B \-\-mpls\c
+.B \-\-csv\c
+]
+[\c
+.B \-\-split\c
 ]
 [\c
 .B \-\-no-dns\c
@@ -44,46 +41,72 @@ mtr \- a network diagnostic tool
 .B \-\-show-ips\c
 ]
 [\c
-.B \-\-gtk\c
+.BI \-o \ FIELDS\c
+]
+[\c
+.BI \-y \ IPINFO\c
+]
+[\c
+.B \-\-aslookup\c
 ]
 [\c
-.B \-\-address\ IP.ADD.RE.SS\c
+.BI \-i \ INTERVAL\c
 ]
 [\c
-.B \-\-interval\ SECONDS\c
+.BI \-c \ COUNT\c
 ]
 [\c
-.B \-\-psize\ BYTES | -s BYTES\c
+.BI \-s \ PACKETSIZE\c
+]
+[\c
+.BI \-B \ BITPATTERN\c
+]
+[\c
+.BI \-Q \ TOS\c
+]
+[\c
+.B \-\-mpls\c
+]
+[\c
+.BI \-a \ ADDRESS\c
+]
+[\c
+.BI \-f \ FIRST\-TTL\c
+]
+[\c
+.BI \-m \ MAX\-TTL\c
+]
+[\c
+.B \-\-udp\c
 ]
 [\c
 .B \-\-tcp\c
 ]
 [\c
-.B \-\-port\ PORT\c
+.BI \-P \ PORT\c
 ]
 [\c
-.B \-\-timeout\ SECONDS\c
+.BI \-Z \ TIMEOUT\c
 ]
-.B HOSTNAME [PACKETSIZE]
-
-
+[\c
+.BI \-M \ MARK\c
+]
+.I HOSTNAME
 .SH DESCRIPTION
-
 .B mtr 
 combines the functionality of the 
 .B traceroute
 and 
 .B ping
 programs in a single network diagnostic tool.
-
 .PP
 As 
 .B mtr 
 starts, it investigates the network connection between the host 
 .B mtr
 runs on and 
-.BR HOSTNAME . 
-by sending packets with purposely low TTLs. It continues to send
+.BR HOSTNAME
+by sending packets with purposely low TTLs.  It continues to send
 packets with low TTL, noting the response time of the intervening
 routers.  This allows 
 .B mtr 
@@ -92,32 +115,27 @@ route to
 .BR HOSTNAME . 
 A sudden increase in packet loss or response time is often an indication
 of a bad (or simply overloaded) link. 
-
 .PP
 The results are usually reported as round-trip-response times in miliseconds 
 and the percentage of packetloss. 
-
 .SH OPTIONS
-
-.TP
-.B \-h
 .TP
-.B \-\-help
-.br
+.B \-h\fR, \fB\-\-help
 Print the summary of command line argument options.
-
-.TP
-.B \-v
 .TP
-.B \-\-version
-.br
+.B \-v\fR, \fB\-\-version
 Print the installed version of mtr.  
-
 .TP
-.B \-r
+.B \-4
+Use IPv4 only.
 .TP
-.B \-\-report
-.br
+.B \-6
+Use IPv6 only.  (IPV4 may be used for DNS lookups). 
+.TP
+.B \-F \fIFILENAME\fR, \fB\-\-filename \fIFILENAME
+MISSING
+.TP
+.B \-r\fR, \fB\-\-report
 This option puts 
 .B mtr
 into 
@@ -136,12 +154,8 @@ generates a significant amount of network traffic.  Using
 .B mtr
 to measure the quality of your network may result in decreased
 network performance.  
-
-.TP
-.B \-w
 .TP
-.B \-\-report-wide
-.br
+.B \-w\fR, \fB\-\-report\-wide
 This option puts 
 .B mtr
 into 
@@ -149,75 +163,61 @@ into
 mode.  When in this mode,
 .B mtr
 will not cut hostnames in the report. 
-
-.TP
-.B \-c\ COUNT
 .TP
-.B \-\-report\-cycles\ COUNT
-Use this option to set the number of pings sent to determine
-both the machines on the network and the reliability of 
-those machines.  Each cycle lasts one second.
-
-.TP
-.B \-s\ BYTES
-.TP
-.B \-\-psize\ BYTES
-.TP
-.B PACKETSIZE
-These options or a trailing PACKETSIZE on the command line sets 
-the packet size used for probing.
-It is in bytes inclusive IP and ICMP headers
-
-If set to a negative number, every iteration will use a different, random
-packet size upto that number. 
-.TP
-.B \-t
+.B \-x\fR, \fB\-\-xml
+Use this option to tell
+.B mtr
+to use the xml output format.  This format is better suited for
+automated processing of the measurement results.
 .TP
-.B \-\-curses
-.br
+.B \-t\fR, \fB\-\-curses
 Use this option to force 
 .B mtr 
 to use the curses based terminal
 interface (if available).
-
-.TP
-.B \-e
 .TP
-.B \-\-mpls
-.br
-Use this option to tell 
+.B \-g\fR, \fB\-\-gtk
+Use this option to force
 .B mtr 
-to display information from ICMP extensions for MPLS (RFC 4950)
-that are encoded in the response packets.
-
+to use the GTK+ based X11 window interface (if available).  
+GTK+ must have been available on the system when 
+.B mtr 
+was built for this to work.  See the GTK+ web page at 
+.B http://www.gtk.org/
+for more information about GTK+.
 .TP
-.B \-n
+.B \-l\fR, \fB\-\-raw
+Use this option to tell
+.B mtr
+to use the raw output format.  This format is better suited for
+archival of the measurement results.  It could be parsed to 
+be presented into any of the other display methods. 
 .TP
-.B \-\-no-dns
-.br
+.B \-C\fR, \fB\-\-csv
+MISSING
+.TP
+.B \-p\fR, \fB\-\-split
+Use this option to set
+.B mtr 
+to spit out a format that is suitable for a split-user interface.
+.TP
+.B \-n\fR, \fB\-\-no\-dns
 Use this option to force 
 .B mtr 
 to display numeric IP numbers and not try to resolve the
 host names. 
-
-.TP
-.B \-b
 .TP
-.B \-\-show-ips
-.br
+.B \-b\fR, \fB\-\-show\-ips
 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. In report mode, there is usually
-too little space to add the IPs, and they will be truncated. Use the 
+this adds an extra field to the output.  In report mode, there is usually
+too little space to add the IPs, and they will be truncated.  Use the
 wide report (-w) mode to see the IPs in report mode. 
-
-.TP
-.B \-o\ fields\ order
 .TP
-.B \-\-order\ fields\ order
-.br
-Use this option to specify the fields and their order when loading mtr.
+.B \-o \fIFIELDS\fR, \fB\-\-order \fIFIELDS
+Use this option to specify which fields to display and in which order.
+You may use one or more space characters to separate fields.
 .br
 Available fields:
 .TS
@@ -241,122 +241,129 @@ I%Interarrival Jitter
 .br
 
 Example:
--o "LSD NBAW"
+-o "LSD NBAW  X"
 .TP
-.B \-g
+.B \-y \fIn\fR, \fB\-\-ipinfo \fIn
+MISSING
 .TP
-.B \-\-gtk
-.br
-Use this option to force
-.B mtr 
-to use the GTK+ based X11 window interface (if available).  
-GTK+ must have been available on the system when 
-.B mtr 
-was built for this to work.  See the GTK+ web page at 
-.B http://www.gtk.org/
-for more information about GTK+.
-
+.B \-z\fR, \fB\-\-aslookup
+MISSING
 .TP
-.B \-p
+.B \-i \fISECONDS\fR, \fB\-\-interval \fISECONDS
+Use this option to specify the positive number of seconds between ICMP
+ECHO requests.  The default value for this parameter is one second.  The
+root user may choose values between zero and one.
 .TP
-.B \-\-split
-.br
-Use this option to set
-.B mtr 
-to spit out a format that is suitable for a split-user interface.
+.B \-c \fICOUNT\fR, \fB\-\-report\-cycles \fICOUNT
+Use this option to set the number of pings sent to determine
+both the machines on the network and the reliability of 
+those machines.  Each cycle lasts one second.
+.TP
+.B \-s \fIPACKETSIZE\fR, \fB\-\-psize \fIPACKETSIZE
+This option sets the packet size used for probing.  It is in bytes,
+inclusive IP and ICMP headers.
 
+If set to a negative number, every iteration will use a different, random
+packet size up to that number.
 .TP
-.B \-l
+.B \-B \fINUM\fR, \fB\-\-bitpattern \fINUM
+Specifies bit pattern to use in payload.  Should be within range 0 - 255.  If
+.I NUM
+is greater than 255, a random pattern is used.
 .TP
-.B \-\-raw
-.br
+.B \-Q \fINUM\fR, \fB\-\-tos \fINUM
+Specifies value for type of service field in IP header.  Should be within range 0
+- 255.
+.TP
+.B \-e\fR, \fB\-\-mpls
 Use this option to tell 
 .B mtr 
-to use the raw output format. This format is better suited for
-archival of the measurement results. It could be parsed to 
-be presented into any of the other display methods. 
-
+to display information from ICMP extensions for MPLS (RFC 4950)
+that are encoded in the response packets.
 .TP
-.B \-a\ IP.ADD.RE.SS
+.B \-a \fIADDRESS\fR, \fB\-\-address \fIADDRESS
+Use this option to bind the outgoing socket to
+.IR ADDRESS ,
+so that all packets will be sent with
+.I ADDRESS
+as source address.  NOTE that this option doesn't apply to DNS requests
+(which could be and could not be what you want).
 .TP
-.B \-\-address\ IP.ADD.RE.SS
-.br
-Use this option to bind outgoing packets' socket to specific interface,
-so that any packet will be sent through this interface. NOTE that this
-option doesn't apply to DNS requests (which could be and could not be 
-what you want).
-
+.B \-f \fINUM\fR, \fB\-\-first-ttl \fINUM
+Specifies with what TTL to start.  Defaults to 1.
 .TP
-.B \-i\ SECONDS
+.B \-m \fINUM\fR, \fB\-\-max-ttl \fINUM
+Specifies the maximum number of hops (max time-to-live value) traceroute will
+probe.  Default is 30.
 .TP
-.B \-\-interval\ SECONDS
-.br
-Use this option to specify the positive number of seconds between ICMP
-ECHO requests.  The default value for this parameter is one second.
-
-.TP
-.B \-u
-.br
+.B \-u\fR, \fB\-\-udp
 Use UDP datagrams instead of ICMP ECHO.
-
-.TP
-.B \-T
 .TP
-.B \-\-tcp
-.br
-Use TCP SYN packets instead of ICMP ECHO. PACKETSIZE is ignored, since
-SYN packets can not contain data.
-
-.TP
-.B \-P\ PORT
+.B \-T\fR, \fB\-\-tcp
+Use TCP SYN packets instead of ICMP ECHO.
+.I PACKETSIZE
+is ignored, since SYN packets can not contain data.
 .TP
-.B \-\-port\ PORT
-.br
+.B \-P \fIPORT\fR, \fB\-\-port \fIPORT
 The target port number for TCP traces.
-
 .TP
-.B \-\-timeout\ SECONDS
-.br
+.B \-Z \fISECONDS\fR, \fB\-\-timeout \fISECONDS
 The number of seconds to keep the TCP socket open before giving up on
-the connection. This will only affect the final hop. Using large values
+the connection.  This will only affect the final hop.  Using large values
 for this, especially combined with a short interval, will use up a lot
 of file descriptors.
-
 .TP
-.B \-4
-.br
-Use IPv4 only.
-
+.B \-M \fIMARK\fR, \fB\-\-mark \fIMARK
+MISSING
+.SH ENVIRONMENT
+.B mtr
+recognizes a few environment variables.
 .TP
-.B \-6
-.br
-Use IPv6 only.
+.B MTR_OPTIONS
+This environment variable allows to specify options, as if they were
+passed on the command line.  It is parsed before reading the actual
+command line options, so that options specified in
+.B MTR_OPTIONS
+are overriden by command-line options.
 
-.SH BUGS
+Example:
 
+.BI MTR_OPTIONS ="-4\ -c\ 1"
+.B mtr
+.I \-6\ localhost
+
+would send one probe (because of
+.I -c\ 1\c
+) towards
+.B ::1
+(because of
+.IR -6 ,
+which overrides the
+.I -4
+passed in
+.B MTR_OPTIONS\c
+).
+.TP
+.B DISPLAY
+Used for the GTK+ frontend.
+.SH BUGS
 Some modern routers give a lower priority to ICMP ECHO packets than 
 to other network traffic.  Consequently, the reliability of these
 routers reported by 
 .B mtr
 will be significantly lower than the actual reliability of 
 these routers.  
-
-
 .SH CONTACT INFORMATION
-
 .PP
 For the latest version, see the mtr web page at 
 .BR http://www.bitwizard.nl/mtr/ .
-
 .PP
 The mtr mailinglist was little used and is no longer active. 
-
 .PP
-Bug reports and feature requests should be submitted to the
-launchpad mtr bugtracker. 
-
+For patches, bug reports, or feature requests, please open an issue on
+GitHub at:
+.BR https://github.com/traviscross/mtr .
 .SH "SEE ALSO"
-
 traceroute(8),
 ping(8)
 TCP/IP Illustrated (Stevens, ISBN 0201633469).
diff --git a/mtr.c b/mtr.c
index 75a3b06..417caf6 100644
--- a/mtr.c
+++ b/mtr.c
@@ -16,19 +16,21 @@
     Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 */
 
+#include "config.h"
+
 #include <sys/types.h>
-#include <config.h>
-#include <netdb.h>
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
-#include <netinet/in.h>
-#include <sys/socket.h>
 #include <unistd.h>
-#include <strings.h>
-#include <time.h>
 #include <errno.h>
 #include <string.h>
+#include <strings.h>
+
+#include <netdb.h>
+#include <netinet/in.h>
+#include <sys/socket.h>
+#include <time.h>
 #include <ctype.h>
 #include <assert.h>
 #include <fcntl.h>
@@ -41,9 +43,7 @@
 #include "dns.h"
 #include "report.h"
 #include "net.h"
-#ifndef NO_IPINFO
 #include "asn.h"
-#endif
 #include "version.h"
 
 
@@ -76,6 +76,9 @@ int   enablempls = 0;
 int   cpacketsize = 64;          /* default packet size */
 int   bitpattern = 0;
 int   tos = 0;
+#ifdef SO_MARK
+int   mark = -1;
+#endif
 int   reportwide = 0;
 int af = DEFAULT_AF;
 int mtrtype = IPPROTO_ICMP;     /* Use ICMP as default packet type */
@@ -254,9 +257,20 @@ void parse_arg (int argc, char **argv)
 {
   int opt;
   int i;
+  /* IMPORTANT: when adding or modifying an option:
+       1/ mind the order of options, there is some logic;
+       2/ update the getopt_long call below;
+       3/ update the man page (use the same order);
+       4/ update the help message showed when using --help.
+   */
   static struct option long_options[] = {
-    { "version", 0, 0, 'v' },
     { "help", 0, 0, 'h' },
+    { "version", 0, 0, 'v' },
+
+    { "inet", 0, 0, '4' },	/* IPv4 only */
+    { "inet6", 0, 0, '6' },	/* IPv6 only */
+
+    { "filename", 1, 0, 'F' },
 
     { "report", 0, 0, 'r' },
     { "report-wide", 0, 0, 'w' },
@@ -268,7 +282,13 @@ void parse_arg (int argc, char **argv)
     { "split", 0, 0, 'p' },     /* BL */
     				/* maybe above should change to -d 'x' */
 
-    { "order", 1, 0, 'o' },	/* fileds to display & their order */
+    { "no-dns", 0, 0, 'n' },
+    { "show-ips", 0, 0, 'b' },
+    { "order", 1, 0, 'o' },	/* fields to display & their order */
+#ifdef IPINFO
+    { "ipinfo", 1, 0, 'y' },    /* IP info lookup */
+    { "aslookup", 0, 0, 'z' },  /* Do AS lookup (--ipinfo 0) */
+#endif
 
     { "interval", 1, 0, 'i' },
     { "report-cycles", 1, 0, 'c' },
@@ -277,30 +297,23 @@ void parse_arg (int argc, char **argv)
     { "bitpattern", 1, 0, 'B' },/* overload b>255, ->rand(0,255) */
     { "tos", 1, 0, 'Q' },	/* typeof service (0,255) */
     { "mpls", 0, 0, 'e' },
-    { "no-dns", 0, 0, 'n' },
-    { "show-ips", 0, 0, 'b' },
     { "address", 1, 0, 'a' },
     { "first-ttl", 1, 0, 'f' },	/* -f & -m are borrowed from traceroute */
-    { "filename", 1, 0, 'F' },
     { "max-ttl", 1, 0, 'm' },
     { "udp", 0, 0, 'u' },	/* UDP (default is ICMP) */
     { "tcp", 0, 0, 'T' },	/* TCP (default is ICMP) */
     { "port", 1, 0, 'P' },      /* target port number for TCP */
     { "timeout", 1, 0, 'Z' },   /* timeout for TCP sockets */
-    { "inet", 0, 0, '4' },	/* IPv4 only */
-    { "inet6", 0, 0, '6' },	/* IPv6 only */
-#ifndef NO_IPINFO
-    { "ipinfo", 1, 0, 'y' },    /* IP info lookup */
-    { "aslookup", 0, 0, 'z' },  /* Do AS lookup (--ipinfo 0) */
+#ifdef SO_MARK
+    { "mark", 1, 0, 'M' },      /* use SO_MARK */
 #endif
     { 0, 0, 0, 0 }
   };
 
   opt = 0;
   while(1) {
-    /* added f:m:o: byMin */
     opt = getopt_long(argc, argv,
-		      "vhrwxtglCpo:B:i:c:s:Q:ena:f:m:uTP:Zby:z46", long_options, NULL);
+		      "hv46F:rwxtglCpnbo:y:zi:c:s:B:Q:ea:f:m:uTP:Z:M:", long_options, NULL);
     if(opt == -1)
       break;
 
@@ -455,7 +468,7 @@ void parse_arg (int argc, char **argv)
       fprintf( stderr, "IPv6 not enabled.\n" );
       break;
 #endif
-#ifndef NO_IPINFO
+#ifdef IPINFO
     case 'y':
       ipinfo_no = atoi (optarg);
       if (ipinfo_no < 0)
@@ -464,6 +477,24 @@ void parse_arg (int argc, char **argv)
     case 'z':
       ipinfo_no = 0;
       break;
+#else
+    case 'y':
+    case 'z':
+      fprintf( stderr, "IPINFO not enabled.\n" );
+      break;
+#endif
+#ifdef SO_MARK
+    case 'M':
+      mark = atoi (optarg);
+      if (mark < 0) {
+        fprintf( stderr, "SO_MARK must be positive.\n" );
+        exit(EXIT_FAILURE);
+      }
+      break;
+#else
+    case 'M':
+      fprintf( stderr, "SO_MARK not enabled.\n" );
+      break;
 #endif
     }
   }
@@ -566,28 +597,30 @@ int main(int argc, char **argv)
   }
 
   if (PrintHelp) {
-    printf("usage: %s [-hvrwctglspniuT46] [--help] [--version] [--report]\n"
-	   "\t\t[--report-wide] [--report-cycles=COUNT] [--curses] [--gtk]\n"
-           "\t\t[--csv|-C] [--raw] [--split] [--mpls] [--no-dns] [--show-ips]\n"
-           "\t\t[--address interface] [--filename=FILE|-F]\n" /* BL */
-#ifndef NO_IPINFO
-           "\t\t[--ipinfo=item_no|-y item_no]\n"
-           "\t\t[--aslookup|-z]\n"
-#endif
-           "\t\t[--psize=bytes/-s bytes]\n"            /* ok */
-           "\t\t[--report-wide|-w] [-u|-T] [--port=PORT] [--timeout=SECONDS]\n"            /* rew */
-	   "\t\t[--interval=SECONDS] HOSTNAME\n", argv[0]);
+       printf("usage: %s [--help] [--version] [-4|-6] [-F FILENAME]\n"
+              "\t\t[--report] [--report-wide]\n"
+              "\t\t[--xml] [--gtk] [--curses] [--raw] [--csv] [--split]\n"
+              "\t\t[--no-dns] [--show-ips] [-o FIELDS] [-y IPINFO] [--aslookup]\n"
+              "\t\t[-i INTERVAL] [-c COUNT] [-s PACKETSIZE] [-B BITPATTERN]\n"
+              "\t\t[-Q TOS] [--mpls]\n"
+              "\t\t[-a ADDRESS] [-f FIRST-TTL] [-m MAX-TTL]\n"
+              "\t\t[--udp] [--tcp] [-P PORT] [-Z TIMEOUT]\n"
+              "\t\t[-M MARK] HOSTNAME\n", argv[0]);
+       printf("See the man page for details.\n");
     exit(0);
   }
 
   time_t now = time(NULL);
+
+  if (!names) append_to_names (argv[0], "localhost"); // default: localhost. 
+
   names_t* head = names;
   while (names != NULL) {
 
     Hostname = names->name;
-    if (Hostname == NULL) Hostname = "localhost";
+    //  if (Hostname == NULL) Hostname = "localhost"; // no longer necessary.
     if (gethostname(LocalHostname, sizeof(LocalHostname))) {
-    strcpy(LocalHostname, "UNKNOWNHOST");
+      strcpy(LocalHostname, "UNKNOWNHOST");
     }
 
     if (net_preopen_result != 0) {
diff --git a/net.c b/net.c
index 1c8d28f..d43054b 100644
--- a/net.c
+++ b/net.c
@@ -16,7 +16,7 @@
     Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 */
 
-#include <config.h>
+#include "config.h"
 
 #if defined(HAVE_SYS_XTI_H)
 #include <sys/xti.h>
@@ -210,6 +210,9 @@ extern int af;			/* address family of remote target */
 extern int mtrtype;		/* type of query packet used */
 extern int remoteport;          /* target port for TCP tracing */
 extern int timeout;             /* timeout for TCP connections */
+#ifdef SO_MARK
+extern int mark;		/* SO_MARK to set for ping packet*/
+#endif
 
 /* return the number of microseconds to wait before sending the next
    ping */
@@ -327,23 +330,24 @@ void net_send_tcp(int index)
     addrcpy((void *) &local4->sin_addr, (void *) &ssa4->sin_addr, af);
     addrcpy((void *) &remote4->sin_addr, (void *) remoteaddress, af);
     remote4->sin_port = htons(remoteport);
+    len = sizeof (struct sockaddr_in);
     break;
 #ifdef ENABLE_IPV6
   case AF_INET6:
     addrcpy((void *) &local6->sin6_addr, (void *) &ssa6->sin6_addr, af);
     addrcpy((void *) &remote6->sin6_addr, (void *) remoteaddress, af);
     remote6->sin6_port = htons(remoteport);
+    len = sizeof (struct sockaddr_in6);
     break;
 #endif
   }
 
-  if (bind(s, (struct sockaddr *) &local, sizeof (local))) {
+  if (bind(s, (struct sockaddr *) &local, len)) {
     display_clear();
     perror("bind()");
     exit(EXIT_FAILURE);
   }
 
-  len = sizeof (local);
   if (getsockname(s, (struct sockaddr *) &local, &len)) {
     display_clear();
     perror("getsockname()");
@@ -381,6 +385,13 @@ void net_send_tcp(int index)
 #endif
   }
 
+#ifdef SO_MARK
+    if (mark >= 0 && setsockopt( s, SOL_SOCKET, SO_MARK, &mark, sizeof mark ) ) {
+      perror( "setsockopt SO_MARK" );
+      exit( EXIT_FAILURE );
+    }
+#endif
+
   switch (local.ss_family) {
   case AF_INET:
     port = ntohs(local4->sin_port);
@@ -400,7 +411,7 @@ void net_send_tcp(int index)
   gettimeofday(&sequence[port].time, NULL);
   sequence[port].socket = s;
 
-  connect(s, (struct sockaddr *) &remote, sizeof (remote));
+  connect(s, (struct sockaddr *) &remote, len);
 }
 
 /*  Attempt to find the host at a particular number of hops away  */
@@ -481,6 +492,13 @@ void net_send_query(int index)
 #endif
   }
 
+#ifdef SO_MARK
+    if (mark >= 0 && setsockopt( sendsock, SOL_SOCKET, SO_MARK, &mark, sizeof mark ) ) {
+      perror( "setsockopt SO_MARK" );
+      exit( EXIT_FAILURE );
+    }
+#endif
+
   switch ( mtrtype ) {
   case IPPROTO_ICMP:
     icmp = (struct ICMPHeader *)(packet + iphsize);
@@ -1393,7 +1411,7 @@ void net_save_return(int at, int seq, int ms)
 {
   int idx;
   idx = seq - host[at].saved_seq_offset;
-  if (idx < 0 || idx > SAVED_PINGS) {
+  if (idx < 0 || idx >= SAVED_PINGS) {
     return;
   }
   host[at].saved[idx] = ms;
@@ -1562,4 +1580,4 @@ void net_harvest_fds(void)
   net_add_fds(&writefd, &maxfd);
   select(maxfd, NULL, &writefd, NULL, &tv);
   net_process_fds(&writefd);
-}
\ No newline at end of file
+}
diff --git a/raw.c b/raw.c
index 8b0df47..0e1f4f4 100644
--- a/raw.c
+++ b/raw.c
@@ -18,7 +18,8 @@
     Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 */
 
-#include <config.h>
+#include "config.h"
+
 #include <ctype.h>
 #include <stdlib.h>
 #include <stdio.h>
@@ -27,7 +28,6 @@
 #include <netinet/in.h>
 #include <arpa/inet.h>
 
-
 #include "mtr.h"
 #include "raw.h"
 #include "net.h"
diff --git a/report.c b/report.c
index f0e0a03..badb765 100644
--- a/report.c
+++ b/report.c
@@ -16,7 +16,8 @@
     Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 */
 
-#include <config.h>
+#include "config.h"
+
 #include <sys/types.h>
 #include <stdio.h>
 #include <netdb.h>
@@ -31,9 +32,7 @@
 #include "report.h"
 #include "net.h"
 #include "dns.h"
-#ifndef NO_IPINFO
 #include "asn.h"
-#endif
 
 #define MAXLOADBAL 5
 
@@ -77,7 +76,7 @@ static size_t snprint_addr(char *dst, size_t dst_len, ip_t *addr)
 }
 
 
-#ifndef NO_IPINFO
+#ifdef IPINFO
 void print_mpls(struct mplslen *mpls) {
   int k;
   for (k=0; k < mpls->labels; k++)
@@ -112,7 +111,7 @@ void report_close(void)
     }
   }
   
-#ifndef NO_IPINFO
+#ifdef IPINFO
   int len_tmp = len_hosts;
   if (ipinfo_no >= 0) {
     ipinfo_no %= iiwidth_len;
@@ -146,7 +145,7 @@ void report_close(void)
     mpls = net_mpls(at);
     snprint_addr(name, sizeof(name), addr);
 
-#ifndef NO_IPINFO
+#ifdef IPINFO
     if (is_printii()) {
       snprintf(fmt, sizeof(fmt), " %%2d. %%s%%-%ds", len_hosts);
       snprintf(buf, sizeof(buf), fmt, at+1, fmt_ipinfo(addr), name);
@@ -154,7 +153,7 @@ void report_close(void)
 #endif
     snprintf( fmt, sizeof(fmt), " %%2d.|-- %%-%ds", len_hosts);
     snprintf(buf, sizeof(buf), fmt, at+1, name);
-#ifndef NO_IPINFO
+#ifdef IPINFO
     }
 #endif
     len = reportwide ? strlen(buf) : len_hosts;  
@@ -192,7 +191,7 @@ void report_close(void)
 
       if (!found) {
   
-#ifndef NO_IPINFO
+#ifdef IPINFO
         if (is_printii()) {
           if (mpls->labels && z == 1 && enablempls)
             print_mpls(mpls);
@@ -221,14 +220,14 @@ void report_close(void)
           }
         }
 #endif
-#ifndef NO_IPINFO
+#ifdef IPINFO
         }
 #endif
       }
     }
 
     /* No multipath */
-#ifndef NO_IPINFO
+#ifdef IPINFO
     if (is_printii()) {
       if (mpls->labels && z == 1 && enablempls)
         print_mpls(mpls);
@@ -241,7 +240,7 @@ void report_close(void)
       }
     }
 #endif
-#ifndef NO_IPINFO
+#ifdef IPINFO
     }
 #endif
   }
@@ -271,19 +270,20 @@ void xml_close(void)
   ip_t *addr;
   char name[81];
 
-  printf("<MTR SRC=%s DST=%s", LocalHostname, Hostname);
-  printf(" TOS=0x%X", tos);
+  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);
+    printf(" PSIZE=\"%d\"", cpacketsize);
   } else {
-    printf(" PSIZE=rand(%d-%d)",MINPACKET, -cpacketsize);
+    printf(" PSIZE=\"rand(%d-%d)\"",MINPACKET, -cpacketsize);
   }
   if( bitpattern>=0 ) {
-    printf(" BITPATTERN=0x%02X", (unsigned char)(bitpattern));
+    printf(" BITPATTERN=\"0x%02X\"", (unsigned char)(bitpattern));
   } else {
-    printf(" BITPATTERN=rand(0x00-FF)");
+    printf(" BITPATTERN=\"rand(0x00-FF)\"");
   }
-  printf(" TESTS=%d>\n", MaxPing);
+  printf(" TESTS=\"%d\">\n", MaxPing);
 
   max = net_max();
   at  = net_min();
@@ -291,7 +291,7 @@ void xml_close(void)
     addr = net_addr(at);
     snprint_addr(name, sizeof(name), addr);
 
-    printf("    <HUB COUNT=%d HOST=%s>\n", at+1, name);
+    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;
@@ -299,17 +299,25 @@ void xml_close(void)
       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,
-		data_fields[j].title,
+		title,
 		data_fields[j].net_xxx(at) /1000.0,
-		data_fields[j].title );
+		title );
       } else {
 	printf( name,
-		data_fields[j].title,
+		title,
 		data_fields[j].net_xxx(at),
-		data_fields[j].title );
+		title );
       }
     }
     printf("    </HUB>\n");
@@ -340,15 +348,16 @@ void csv_close(time_t now)
     snprint_addr(name, sizeof(name), addr);
 
     int last = net_last(at);
+#ifdef IPINFO
     if(!ipinfo_no) {
       char* fmtinfo = fmt_ipinfo(addr);
       if (fmtinfo != NULL) fmtinfo = trim(fmtinfo);
-      printf("MTR.%s;%lu;%s;%s;%d;%s;%s;%d", MTR_VERSION, now, "OK", Hostname,
+      printf("MTR.%s;%lld;%s;%s;%d;%s;%s;%d", MTR_VERSION, (long long)now, "OK", Hostname,
              at+1, name, fmtinfo, last);
-    } else {
-      printf("MTR.%s;%lu;%s;%s;%d;%s;%d", MTR_VERSION, now, "OK", Hostname,
+    } else
+#endif
+      printf("MTR.%s;%lld;%s;%s;%d;%s;%d", MTR_VERSION, (long long)now, "OK", Hostname,
              at+1, name, last);
-    }
 
     for( i=0; i<MAXFLD; i++ ) {
       j = fld_index[fld_active[j]];
diff --git a/select.c b/select.c
index 377fe20..62478f4 100644
--- a/select.c
+++ b/select.c
@@ -16,7 +16,8 @@
     Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 */
 
-#include <config.h>
+#include "config.h"
+
 #include <sys/types.h>
 #include <sys/time.h>
 #include <stdlib.h>
@@ -29,12 +30,10 @@
 #include <errno.h>
 
 #include "mtr.h"
-#include "display.h"
 #include "dns.h"
 #include "net.h"
-#ifndef NO_IPINFO
 #include "asn.h"
-#endif
+#include "display.h"
 
 extern int Interactive;
 extern int MaxPing;
@@ -47,6 +46,8 @@ static struct timeval intervaltime;
 int display_offset = 0;
 
 
+#define GRACETIME (5 * 1000*1000)
+
 void select_loop(void) {
   fd_set readfd;
   fd_set writefd;
@@ -59,8 +60,12 @@ void select_loop(void) {
   int NumPing = 0;
   int paused = 0;
   struct timeval lasttime, thistime, selecttime;
+  struct timeval startgrace;
   int dt;
   int rv; 
+  int graceperiod = 0;
+
+  memset(&startgrace, 0, sizeof(startgrace));
 
   gettimeofday(&lasttime, NULL);
 
@@ -82,8 +87,12 @@ void select_loop(void) {
 #ifdef ENABLE_IPV6
     if (dns) {
       dnsfd6 = dns_waitfd6();
-      FD_SET(dnsfd6, &readfd);
-      if(dnsfd6 >= maxfd) maxfd = dnsfd6 + 1;
+      if (dnsfd6 >= 0) {
+        FD_SET(dnsfd6, &readfd);
+        if(dnsfd6 >= maxfd) maxfd = dnsfd6 + 1;
+      } else {
+        dnsfd6 = 0;
+      }
     } else
       dnsfd6 = 0;
 #endif
@@ -103,8 +112,13 @@ void select_loop(void) {
 
     do {
       if(anyset || paused) {
+	/* Set timeout to 0.1s.
+	 * While this is almost instantaneous for human operators,
+	 * it's slow enough for computers to go do something else;
+	 * this prevents mtr from hogging 100% CPU time on one core.
+	 */
 	selecttime.tv_sec = 0;
-	selecttime.tv_usec = 0;
+	selecttime.tv_usec = paused?100000:0; 
       
 	rv = select(maxfd, (void *)&readfd, &writefd, NULL, &selecttime);
 
@@ -117,10 +131,24 @@ void select_loop(void) {
 	   (thistime.tv_sec == lasttime.tv_sec + intervaltime.tv_sec &&
 	    thistime.tv_usec >= lasttime.tv_usec + intervaltime.tv_usec)) {
 	  lasttime = thistime;
-	  if(NumPing >= MaxPing && (!Interactive || ForceMaxPing))
+
+	  if (!graceperiod) {
+	    if (NumPing >= MaxPing && (!Interactive || ForceMaxPing)) {
+	      graceperiod = 1;
+	      startgrace = thistime;
+	    }
+
+	    /* do not send out batch when we've already initiated grace period */
+	    if (!graceperiod && net_send_batch())
+	      NumPing++;
+	  }
+	}
+
+	if (graceperiod) {
+	  dt = (thistime.tv_usec - startgrace.tv_usec) +
+		    1000000 * (thistime.tv_sec - startgrace.tv_sec);
+	  if (dt > GRACETIME)
 	    return;
-	  if (net_send_batch())
-	    NumPing++;
 	}
 
 	selecttime.tv_usec = (thistime.tv_usec - lasttime.tv_usec);
@@ -169,12 +197,12 @@ void select_loop(void) {
 
     /*  Have we finished a nameservice lookup?  */
 #ifdef ENABLE_IPV6
-    if(dns && FD_ISSET(dnsfd6, &readfd)) {
+    if(dns && dnsfd6 && FD_ISSET(dnsfd6, &readfd)) {
       dns_ack6();
       anyset = 1;
     }
 #endif
-    if(dns && FD_ISSET(dnsfd, &readfd)) {
+    if(dns && dnsfd && FD_ISSET(dnsfd, &readfd)) {
       dns_ack();
       anyset = 1;
     }
@@ -210,7 +238,7 @@ void select_loop(void) {
 	  display_clear();
 	}
 	break;
-#ifndef NO_IPINFO
+#ifdef IPINFO
       case ActionII:
 	if (ipinfo_no >= 0) {
 	  ipinfo_no++;
diff --git a/split.c b/split.c
index 642353e..5ead235 100644
--- a/split.c
+++ b/split.c
@@ -20,7 +20,8 @@
     Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 */
 
-#include <config.h>
+#include "config.h"
+
 #include <ctype.h>
 #include <stdlib.h>
 #include <stdio.h>
