Diff for /embedaddon/mtr/mtr.c between versions 1.1 and 1.1.1.2

version 1.1, 2013/07/21 23:43:42 version 1.1.1.2, 2016/11/01 09:33:48
Line 16 Line 16
     Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.      Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 */  */
   
   #include "config.h"
   
 #include <sys/types.h>  #include <sys/types.h>
 #include <config.h>  
 #include <netdb.h>  
 #include <stdio.h>  #include <stdio.h>
 #include <stdlib.h>  #include <stdlib.h>
 #include <string.h>  #include <string.h>
 #include <netinet/in.h>  
 #include <sys/socket.h>  
 #include <unistd.h>  #include <unistd.h>
 #include <strings.h>  
 #include <time.h>  
 #include <errno.h>  #include <errno.h>
 #include <string.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 <ctype.h>
 #include <assert.h>  #include <assert.h>
 #include <fcntl.h>  #include <fcntl.h>
Line 41 Line 43
 #include "dns.h"  #include "dns.h"
 #include "report.h"  #include "report.h"
 #include "net.h"  #include "net.h"
 #ifndef NO_IPINFO  
 #include "asn.h"  #include "asn.h"
 #endif  
 #include "version.h"  #include "version.h"
   
   
Line 76  int   enablempls = 0; Line 76  int   enablempls = 0;
 int   cpacketsize = 64;          /* default packet size */  int   cpacketsize = 64;          /* default packet size */
 int   bitpattern = 0;  int   bitpattern = 0;
 int   tos = 0;  int   tos = 0;
   #ifdef SO_MARK
   int   mark = -1;
   #endif
 int   reportwide = 0;  int   reportwide = 0;
 int af = DEFAULT_AF;  int af = DEFAULT_AF;
 int mtrtype = IPPROTO_ICMP;     /* Use ICMP as default packet type */  int mtrtype = IPPROTO_ICMP;     /* Use ICMP as default packet type */
Line 254  void parse_arg (int argc, char **argv) Line 257  void parse_arg (int argc, char **argv)
 {  {
   int opt;    int opt;
   int i;    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[] = {    static struct option long_options[] = {
     { "version", 0, 0, 'v' },  
     { "help", 0, 0, 'h' },      { "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", 0, 0, 'r' },
     { "report-wide", 0, 0, 'w' },      { "report-wide", 0, 0, 'w' },
     { "xml", 0, 0, 'x' },      { "xml", 0, 0, 'x' },
Line 268  void parse_arg (int argc, char **argv) Line 282  void parse_arg (int argc, char **argv)
     { "split", 0, 0, 'p' },     /* BL */      { "split", 0, 0, 'p' },     /* BL */
                                 /* maybe above should change to -d 'x' */                                  /* 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' },      { "interval", 1, 0, 'i' },
     { "report-cycles", 1, 0, 'c' },      { "report-cycles", 1, 0, 'c' },
Line 277  void parse_arg (int argc, char **argv) Line 297  void parse_arg (int argc, char **argv)
     { "bitpattern", 1, 0, 'B' },/* overload b>255, ->rand(0,255) */      { "bitpattern", 1, 0, 'B' },/* overload b>255, ->rand(0,255) */
     { "tos", 1, 0, 'Q' },       /* typeof service (0,255) */      { "tos", 1, 0, 'Q' },       /* typeof service (0,255) */
     { "mpls", 0, 0, 'e' },      { "mpls", 0, 0, 'e' },
     { "no-dns", 0, 0, 'n' },  
     { "show-ips", 0, 0, 'b' },  
     { "address", 1, 0, 'a' },      { "address", 1, 0, 'a' },
     { "first-ttl", 1, 0, 'f' }, /* -f & -m are borrowed from traceroute */      { "first-ttl", 1, 0, 'f' }, /* -f & -m are borrowed from traceroute */
     { "filename", 1, 0, 'F' },  
     { "max-ttl", 1, 0, 'm' },      { "max-ttl", 1, 0, 'm' },
     { "udp", 0, 0, 'u' },       /* UDP (default is ICMP) */      { "udp", 0, 0, 'u' },       /* UDP (default is ICMP) */
     { "tcp", 0, 0, 'T' },       /* TCP (default is ICMP) */      { "tcp", 0, 0, 'T' },       /* TCP (default is ICMP) */
     { "port", 1, 0, 'P' },      /* target port number for TCP */      { "port", 1, 0, 'P' },      /* target port number for TCP */
     { "timeout", 1, 0, 'Z' },   /* timeout for TCP sockets */      { "timeout", 1, 0, 'Z' },   /* timeout for TCP sockets */
    { "inet", 0, 0, '4' },      /* IPv4 only */#ifdef SO_MARK
    { "inet6", 0, 0, '6' },     /* IPv6 only */    { "mark", 1, 0, 'M' },      /* use SO_MARK */
#ifndef NO_IPINFO 
    { "ipinfo", 1, 0, 'y' },    /* IP info lookup */ 
    { "aslookup", 0, 0, 'z' },  /* Do AS lookup (--ipinfo 0) */ 
 #endif  #endif
     { 0, 0, 0, 0 }      { 0, 0, 0, 0 }
   };    };
   
   opt = 0;    opt = 0;
   while(1) {    while(1) {
     /* added f:m:o: byMin */  
     opt = getopt_long(argc, argv,      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)      if(opt == -1)
       break;        break;
   
Line 455  void parse_arg (int argc, char **argv) Line 468  void parse_arg (int argc, char **argv)
       fprintf( stderr, "IPv6 not enabled.\n" );        fprintf( stderr, "IPv6 not enabled.\n" );
       break;        break;
 #endif  #endif
#ifndef NO_IPINFO#ifdef IPINFO
     case 'y':      case 'y':
       ipinfo_no = atoi (optarg);        ipinfo_no = atoi (optarg);
       if (ipinfo_no < 0)        if (ipinfo_no < 0)
Line 464  void parse_arg (int argc, char **argv) Line 477  void parse_arg (int argc, char **argv)
     case 'z':      case 'z':
       ipinfo_no = 0;        ipinfo_no = 0;
       break;        break;
   #else
       case 'y':
       case 'z':
         fprintf( stderr, "IPINFO not enabled.\n" );
         break;
 #endif  #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
     }      }
   }    }
   
Line 566  int main(int argc, char **argv) Line 597  int main(int argc, char **argv)
   }    }
   
   if (PrintHelp) {    if (PrintHelp) {
    printf("usage: %s [-hvrwctglspniuT46] [--help] [--version] [--report]\n"       printf("usage: %s [--help] [--version] [-4|-6] [-F FILENAME]\n"
           "\t\t[--report-wide] [--report-cycles=COUNT] [--curses] [--gtk]\n"              "\t\t[--report] [--report-wide]\n"
           "\t\t[--csv|-C] [--raw] [--split] [--mpls] [--no-dns] [--show-ips]\n"              "\t\t[--xml] [--gtk] [--curses] [--raw] [--csv] [--split]\n"
           "\t\t[--address interface] [--filename=FILE|-F]\n" /* BL */              "\t\t[--no-dns] [--show-ips] [-o FIELDS] [-y IPINFO] [--aslookup]\n"
#ifndef NO_IPINFO              "\t\t[-i INTERVAL] [-c COUNT] [-s PACKETSIZE] [-B BITPATTERN]\n"
           "\t\t[--ipinfo=item_no|-y item_no]\n"              "\t\t[-Q TOS] [--mpls]\n"
           "\t\t[--aslookup|-z]\n"              "\t\t[-a ADDRESS] [-f FIRST-TTL] [-m MAX-TTL]\n"
#endif              "\t\t[--udp] [--tcp] [-P PORT] [-Z TIMEOUT]\n"
           "\t\t[--psize=bytes/-s bytes]\n"            /* ok */              "\t\t[-M MARK] HOSTNAME\n", argv[0]);
           "\t\t[--report-wide|-w] [-u|-T] [--port=PORT] [--timeout=SECONDS]\n"            /* rew */       printf("See the man page for details.\n");
           "\t\t[--interval=SECONDS] HOSTNAME\n", argv[0]); 
     exit(0);      exit(0);
   }    }
   
   time_t now = time(NULL);    time_t now = time(NULL);
   
     if (!names) append_to_names (argv[0], "localhost"); // default: localhost. 
   
   names_t* head = names;    names_t* head = names;
   while (names != NULL) {    while (names != NULL) {
   
     Hostname = names->name;      Hostname = names->name;
    if (Hostname == NULL) Hostname = "localhost";    //  if (Hostname == NULL) Hostname = "localhost"; // no longer necessary.
     if (gethostname(LocalHostname, sizeof(LocalHostname))) {      if (gethostname(LocalHostname, sizeof(LocalHostname))) {
    strcpy(LocalHostname, "UNKNOWNHOST");      strcpy(LocalHostname, "UNKNOWNHOST");
     }      }
   
     if (net_preopen_result != 0) {      if (net_preopen_result != 0) {

Removed from v.1.1  
changed lines
  Added in v.1.1.1.2


FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>