├── .tarball-version ├── portability ├── .gitignore ├── error.h ├── error.c ├── getopt1.c └── getopt.h ├── bootstrap.sh ├── .dir-locals.el ├── packet ├── sockaddr.h ├── wait.h ├── timeval.h ├── construct_unix.h ├── platform.h ├── command.h ├── sockaddr.c ├── cmdparse.h ├── deconstruct_unix.h ├── wait_cygwin.c ├── timeval.c ├── probe_cygwin.h ├── probe_unix.h ├── packet.c ├── protocols.h ├── cmdparse.c ├── wait_unix.c ├── probe.h └── probe.c ├── test ├── lint.sh ├── param.py ├── cmdparse.py └── packet_listen.c ├── .gitignore ├── ui ├── select.h ├── split.h ├── mtr-curses.h ├── mtr-gtk.h ├── asn.h ├── raw.h ├── report.h ├── dns.h ├── utils.h ├── cmdpipe.h ├── raw.c ├── display.h ├── net.h ├── split.c ├── utils.c ├── mtr.h ├── display.c ├── dns.c ├── asn.c └── select.c ├── BSDCOPYING ├── bash-completion └── mtr ├── SECURITY ├── AUTHORS ├── FORMATS ├── README.md ├── Makefile.am ├── TODO ├── img └── mtr_icon.xpm ├── configure.ac └── man └── mtr-packet.8.in /.tarball-version: -------------------------------------------------------------------------------- 1 | 0.94 2 | -------------------------------------------------------------------------------- /portability/.gitignore: -------------------------------------------------------------------------------- 1 | /.deps 2 | /.dirstamp 3 | -------------------------------------------------------------------------------- /bootstrap.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | aclocal $ACLOCAL_OPTS 4 | autoheader 5 | automake --add-missing --copy --foreign 6 | autoconf --force 7 | -------------------------------------------------------------------------------- /.dir-locals.el: -------------------------------------------------------------------------------- 1 | ((c-mode . ((indent-tabs-mode . nil) 2 | (c-file-style . "gnu") 3 | (c-basic-offset . 4)))) 4 | -------------------------------------------------------------------------------- /packet/sockaddr.h: -------------------------------------------------------------------------------- 1 | unsigned int sockaddr_size(const void *x); 2 | 3 | void *sockaddr_addr_offset(const void *x); 4 | unsigned int sockaddr_addr_size(const void *x); 5 | 6 | in_port_t *sockaddr_port_offset(const void *x); 7 | -------------------------------------------------------------------------------- /test/lint.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | # Check the Python test source for good style 4 | 5 | PYTHON_SOURCE=*.py 6 | 7 | pep8 $PYTHON_SOURCE 8 | pylint --reports=n $PYTHON_SOURCE 2>/dev/null 9 | mypy --py2 $PYTHON_SOURCE 10 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # .gitignore 2 | *.o 3 | *.pyc 4 | 5 | Makefile 6 | Makefile.in 7 | aclocal.m4 8 | confdefs.h 9 | config.* 10 | configure 11 | confinc 12 | confmf 13 | conftest.* 14 | stamp-h1* 15 | 16 | /build-aux/compile 17 | /build-aux/depcomp 18 | /build-aux/install-sh 19 | /build-aux/missing 20 | /build-aux/test-driver 21 | 22 | /autom4te.cache/ 23 | /.deps/ 24 | /packet/.deps/ 25 | /packet/.dirstamp 26 | /packet/testpacket.py.log 27 | /packet/testpacket.py.trs 28 | /test-suite.log 29 | /ChangeLog 30 | /INSTALL 31 | /mtr 32 | /mtr-packet 33 | /mtr-packet-listen 34 | /mtr.8 35 | /mtr-packet.8 36 | /test/.deps/ 37 | /test/.dirstamp 38 | /ui/.deps/ 39 | /ui/.dirstamp 40 | 41 | /test/*.py.log 42 | /test/*.py.trs 43 | 44 | /mtr-*.tar.gz 45 | -------------------------------------------------------------------------------- /ui/select.h: -------------------------------------------------------------------------------- 1 | /* 2 | mtr -- a network diagnostic tool 3 | Copyright (C) 1997,1998 Matt Kimball 4 | 5 | This program is free software; you can redistribute it and/or modify 6 | it under the terms of the GNU General Public License version 2 as 7 | published by the Free Software Foundation. 8 | 9 | This program is distributed in the hope that it will be useful, 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | GNU General Public License for more details. 13 | 14 | You should have received a copy of the GNU General Public License along 15 | with this program; if not, write to the Free Software Foundation, Inc., 16 | 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 17 | */ 18 | 19 | extern void select_loop( 20 | struct mtr_ctl *ctl); 21 | -------------------------------------------------------------------------------- /portability/error.h: -------------------------------------------------------------------------------- 1 | /* 2 | Linux error(3) function go around for systems that has err(3) and 3 | warn(3), but no error(3). MacOS is good example of such. 4 | 5 | The GNU C Library is free software; you can redistribute it and/or 6 | modify it under the terms of the GNU Lesser General Public 7 | License as published by the Free Software Foundation version 2. 8 | 9 | The GNU C Library is distributed in the hope that it will be useful, 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | Lesser General Public License for more details. 13 | 14 | You should have received a copy of the GNU Lesser General Public 15 | License along with this library; if not, write to the Free Software 16 | Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 17 | 02110-1301 USA. 18 | */ 19 | 20 | void error(int status, int errnum, const char *format, ...); 21 | -------------------------------------------------------------------------------- /packet/wait.h: -------------------------------------------------------------------------------- 1 | /* 2 | mtr -- a network diagnostic tool 3 | Copyright (C) 2016 Matt Kimball 4 | 5 | This program is free software; you can redistribute it and/or modify 6 | it under the terms of the GNU General Public License version 2 as 7 | published by the Free Software Foundation. 8 | 9 | This program is distributed in the hope that it will be useful, 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | GNU General Public License for more details. 13 | 14 | You should have received a copy of the GNU General Public License along 15 | with this program; if not, write to the Free Software Foundation, Inc., 16 | 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 17 | */ 18 | 19 | #ifndef WAIT_H 20 | #define WAIT_H 21 | 22 | #include "command.h" 23 | #include "probe.h" 24 | 25 | void wait_for_activity( 26 | struct command_buffer_t *command_buffer, 27 | struct net_state_t *net_state); 28 | 29 | #endif 30 | -------------------------------------------------------------------------------- /packet/timeval.h: -------------------------------------------------------------------------------- 1 | /* 2 | mtr -- a network diagnostic tool 3 | Copyright (C) 2016 Matt Kimball 4 | 5 | This program is free software; you can redistribute it and/or modify 6 | it under the terms of the GNU General Public License version 2 as 7 | published by the Free Software Foundation. 8 | 9 | This program is distributed in the hope that it will be useful, 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | GNU General Public License for more details. 13 | 14 | You should have received a copy of the GNU General Public License along 15 | with this program; if not, write to the Free Software Foundation, Inc., 16 | 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 17 | */ 18 | 19 | #ifndef TIMEVAL_H 20 | #define TIMEVAL_H 21 | 22 | #include 23 | 24 | void normalize_timeval( 25 | struct timeval *timeval); 26 | 27 | int compare_timeval( 28 | struct timeval a, 29 | struct timeval b); 30 | 31 | #endif 32 | -------------------------------------------------------------------------------- /ui/split.h: -------------------------------------------------------------------------------- 1 | /* 2 | mtr -- a network diagnostic tool 3 | 4 | split.h -- raw output (for inclusion in KDE Network Utilities) 5 | Copyright (C) 1998 Bertrand Leconte 6 | 7 | This program is free software; you can redistribute it and/or modify 8 | it under the terms of the GNU General Public License version 2 as 9 | published by the Free Software Foundation. 10 | 11 | This program is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | GNU General Public License for more details. 15 | 16 | You should have received a copy of the GNU General Public License along 17 | with this program; if not, write to the Free Software Foundation, Inc., 18 | 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 19 | */ 20 | 21 | /* Prototypes for split.c */ 22 | extern void split_open( 23 | void); 24 | extern void split_close( 25 | void); 26 | extern void split_redraw( 27 | struct mtr_ctl *ctl); 28 | extern int split_keyaction( 29 | void); 30 | -------------------------------------------------------------------------------- /packet/construct_unix.h: -------------------------------------------------------------------------------- 1 | /* 2 | mtr -- a network diagnostic tool 3 | Copyright (C) 2016 Matt Kimball 4 | 5 | This program is free software; you can redistribute it and/or modify 6 | it under the terms of the GNU General Public License version 2 as 7 | published by the Free Software Foundation. 8 | 9 | This program is distributed in the hope that it will be useful, 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | GNU General Public License for more details. 13 | 14 | You should have received a copy of the GNU General Public License along 15 | with this program; if not, write to the Free Software Foundation, Inc., 16 | 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 17 | */ 18 | 19 | #ifndef CONSTRUCT_H 20 | #define CONSTRUCT_H 21 | 22 | #include "probe.h" 23 | 24 | int construct_packet( 25 | const struct net_state_t *net_state, 26 | int *packet_socket, 27 | struct probe_t *probe, 28 | char *packet_buffer, 29 | int packet_buffer_size, 30 | const struct probe_param_t *param); 31 | 32 | #endif 33 | -------------------------------------------------------------------------------- /ui/mtr-curses.h: -------------------------------------------------------------------------------- 1 | /* 2 | mtr -- a network diagnostic tool 3 | Copyright (C) 1997,1998 Matt Kimball 4 | 5 | This program is free software; you can redistribute it and/or modify 6 | it under the terms of the GNU General Public License version 2 as 7 | published by the Free Software Foundation. 8 | 9 | This program is distributed in the hope that it will be useful, 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | GNU General Public License for more details. 13 | 14 | You should have received a copy of the GNU General Public License along 15 | with this program; if not, write to the Free Software Foundation, Inc., 16 | 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 17 | */ 18 | 19 | /* Prototypes for curses.c */ 20 | extern void mtr_curses_open( 21 | struct mtr_ctl *ctl); 22 | extern void mtr_curses_close( 23 | void); 24 | extern void mtr_curses_redraw( 25 | struct mtr_ctl *ctl); 26 | extern int mtr_curses_keyaction( 27 | struct mtr_ctl *ctl); 28 | extern void mtr_curses_clear( 29 | struct mtr_ctl *ctl); 30 | -------------------------------------------------------------------------------- /ui/mtr-gtk.h: -------------------------------------------------------------------------------- 1 | /* 2 | mtr -- a network diagnostic tool 3 | Copyright (C) 1997,1998 Matt Kimball 4 | 5 | This program is free software; you can redistribute it and/or modify 6 | it under the terms of the GNU General Public License version 2 as 7 | published by the Free Software Foundation. 8 | 9 | This program is distributed in the hope that it will be useful, 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | GNU General Public License for more details. 13 | 14 | You should have received a copy of the GNU General Public License along 15 | with this program; if not, write to the Free Software Foundation, Inc., 16 | 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 17 | */ 18 | 19 | /* Prototypes for gtk.c */ 20 | extern int gtk_detect( 21 | int *argc, 22 | char ***argv); 23 | extern void gtk_open( 24 | struct mtr_ctl *ctl); 25 | extern void gtk_close( 26 | void); 27 | extern void gtk_redraw( 28 | struct mtr_ctl *ctl); 29 | extern int gtk_keyaction( 30 | void); 31 | extern void gtk_loop( 32 | struct mtr_ctl *ctl); 33 | -------------------------------------------------------------------------------- /ui/asn.h: -------------------------------------------------------------------------------- 1 | /* 2 | mtr -- a network diagnostic tool 3 | Copyright (C) 1997,1998 Matt Kimball 4 | 5 | This program is free software; you can redistribute it and/or modify 6 | it under the terms of the GNU General Public License version 2 as 7 | published by the Free Software Foundation. 8 | 9 | This program is distributed in the hope that it will be useful, 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | GNU General Public License for more details. 13 | 14 | You should have received a copy of the GNU General Public License along 15 | with this program; if not, write to the Free Software Foundation, Inc., 16 | 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 17 | */ 18 | 19 | #include "mtr.h" 20 | 21 | extern void asn_open( 22 | struct mtr_ctl *ctl); 23 | extern void asn_close( 24 | struct mtr_ctl *ctl); 25 | extern char *fmt_ipinfo( 26 | struct mtr_ctl *ctl, 27 | ip_t * addr); 28 | extern ATTRIBUTE_CONST size_t get_iiwidth_len( 29 | void); 30 | extern ATTRIBUTE_CONST int get_iiwidth( 31 | int ipinfo_no); 32 | extern int is_printii( 33 | struct mtr_ctl *ctl); 34 | -------------------------------------------------------------------------------- /ui/raw.h: -------------------------------------------------------------------------------- 1 | /* 2 | mtr -- a network diagnostic tool 3 | Copyright (C) 1998 R.E.Wolff@BitWizard.nl 4 | 5 | raw.h -- raw output (for logging for later analysis) 6 | 7 | This program is free software; you can redistribute it and/or modify 8 | it under the terms of the GNU General Public License version 2 as 9 | published by the Free Software Foundation. 10 | 11 | This program is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | GNU General Public License for more details. 15 | 16 | You should have received a copy of the GNU General Public License along 17 | with this program; if not, write to the Free Software Foundation, Inc., 18 | 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 19 | */ 20 | 21 | /* Prototypes for raw.c */ 22 | extern void raw_rawxmit( 23 | int host, 24 | int seq); 25 | extern void raw_rawping( 26 | struct mtr_ctl *ctl, 27 | int host, 28 | int msec, 29 | int seq); 30 | extern void raw_rawhost( 31 | struct mtr_ctl *ctl, 32 | int host, 33 | ip_t *addr, 34 | struct mplslen *mpls); 35 | -------------------------------------------------------------------------------- /portability/error.c: -------------------------------------------------------------------------------- 1 | /* 2 | Linux error(3) function go around for systems that has err(3) and 3 | warn(3), but no error(3). MacOS is good example of such. 4 | 5 | The GNU C Library is free software; you can redistribute it and/or 6 | modify it under the terms of the GNU Lesser General Public 7 | License as published by the Free Software Foundation version 2. 8 | 9 | The GNU C Library is distributed in the hope that it will be useful, 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | Lesser General Public License for more details. 13 | 14 | You should have received a copy of the GNU Lesser General Public 15 | License along with this library; if not, write to the Free Software 16 | Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 17 | 02110-1301 USA. 18 | */ 19 | 20 | #include 21 | #include 22 | 23 | void error(int status, int errnum, const char *format, ...) { 24 | va_list arg; 25 | 26 | va_start(arg, format); 27 | if (errnum == 0) { 28 | if (status == 0) 29 | vwarnx(format, arg); 30 | else 31 | verrx(status, format, arg); 32 | } else { 33 | if (status == 0) 34 | vwarn(format, arg); 35 | else 36 | verr(status, format, arg); 37 | } 38 | va_end(arg); 39 | } 40 | -------------------------------------------------------------------------------- /ui/report.h: -------------------------------------------------------------------------------- 1 | /* 2 | mtr -- a network diagnostic tool 3 | Copyright (C) 1997,1998 Matt Kimball 4 | 5 | This program is free software; you can redistribute it and/or modify 6 | it under the terms of the GNU General Public License version 2 as 7 | published by the Free Software Foundation. 8 | 9 | This program is distributed in the hope that it will be useful, 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | GNU General Public License for more details. 13 | 14 | You should have received a copy of the GNU General Public License along 15 | with this program; if not, write to the Free Software Foundation, Inc., 16 | 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 17 | */ 18 | 19 | /* Prototypes for report.h */ 20 | 21 | extern void report_open( 22 | void); 23 | extern void report_close( 24 | struct mtr_ctl *ctl); 25 | extern void txt_open( 26 | void); 27 | extern void txt_close( 28 | struct mtr_ctl *ctl); 29 | extern void json_open( 30 | void); 31 | extern void json_close( 32 | struct mtr_ctl *ctl); 33 | extern void xml_open( 34 | void); 35 | extern void xml_close( 36 | struct mtr_ctl *ctl); 37 | extern void csv_open( 38 | void); 39 | extern void csv_close( 40 | struct mtr_ctl *ctl, 41 | time_t now); 42 | -------------------------------------------------------------------------------- /packet/platform.h: -------------------------------------------------------------------------------- 1 | /* 2 | mtr -- a network diagnostic tool 3 | Copyright (C) 2016 Matt Kimball 4 | 5 | This program is free software; you can redistribute it and/or modify 6 | it under the terms of the GNU General Public License version 2 as 7 | published by the Free Software Foundation. 8 | 9 | This program is distributed in the hope that it will be useful, 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | GNU General Public License for more details. 13 | 14 | You should have received a copy of the GNU General Public License along 15 | with this program; if not, write to the Free Software Foundation, Inc., 16 | 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 17 | */ 18 | 19 | #ifndef PLATFORM_H 20 | #define PLATFORM_H 21 | 22 | /* 23 | Determine the most appropriate PLATFORM_* define for our 24 | current target. 25 | */ 26 | 27 | #if defined(__CYGWIN__) 28 | 29 | #define PLATFORM_CYGWIN 30 | 31 | #elif defined(__APPLE__) && defined(__MACH__) 32 | 33 | #define PLATFORM_OS_X 34 | 35 | #elif defined(__gnu_linux__) 36 | 37 | #define PLATFORM_LINUX 38 | 39 | #elif defined (__FreeBSD__) 40 | 41 | #define PLATFORM_FREEBSD 42 | 43 | #elif defined(__unix__) 44 | 45 | #define PLATFORM_UNIX_UNKNOWN 46 | 47 | #else 48 | 49 | #error Unsupported platform 50 | 51 | #endif 52 | 53 | #endif 54 | -------------------------------------------------------------------------------- /ui/dns.h: -------------------------------------------------------------------------------- 1 | /* 2 | mtr -- a network diagnostic tool 3 | Copyright (C) 1997,1998 Matt Kimball 4 | 5 | This program is free software; you can redistribute it and/or modify 6 | it under the terms of the GNU General Public License version 2 as 7 | published by the Free Software Foundation. 8 | 9 | This program is distributed in the hope that it will be useful, 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | GNU General Public License for more details. 13 | 14 | You should have received a copy of the GNU General Public License along 15 | with this program; if not, write to the Free Software Foundation, Inc., 16 | 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 17 | */ 18 | 19 | #include 20 | #include 21 | #include 22 | 23 | /* Prototypes for dns.c */ 24 | 25 | extern void dns_open( 26 | void); 27 | extern int dns_waitfd( 28 | void); 29 | extern void dns_ack( 30 | struct mtr_ctl *ctl); 31 | #ifdef ENABLE_IPV6 32 | extern int dns_waitfd6( 33 | void); 34 | extern void dns_ack6( 35 | void); 36 | #endif 37 | 38 | extern char *dns_lookup( 39 | struct mtr_ctl *ctl, 40 | ip_t * address); 41 | extern char *dns_lookup2( 42 | struct mtr_ctl *ctl, 43 | ip_t * address); 44 | extern char *strlongip( 45 | sa_family_t family, 46 | ip_t * ip); 47 | 48 | extern void addr2ip6arpa( 49 | ip_t * ip, 50 | char *buf); 51 | extern struct hostent *addr2host( 52 | const char *addr, 53 | int type); 54 | -------------------------------------------------------------------------------- /ui/utils.h: -------------------------------------------------------------------------------- 1 | /* 2 | mtr -- a network diagnostic tool 3 | Copyright (C) 1997,1998 Matt Kimball 4 | Copyright (C) 2005 R.E.Wolff@BitWizard.nl 5 | 6 | This program is free software; you can redistribute it and/or modify 7 | it under the terms of the GNU General Public License version 2 as 8 | published by the Free Software Foundation. 9 | 10 | This program is distributed in the hope that it will be useful, 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | GNU General Public License for more details. 14 | 15 | You should have received a copy of the GNU General Public License along 16 | with this program; if not, write to the Free Software Foundation, Inc., 17 | 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 18 | */ 19 | 20 | enum { 21 | STRTO_INT, 22 | STRTO_U32INT 23 | }; 24 | 25 | extern char *trim( 26 | char *s, 27 | const char c); 28 | extern int strtonum_or_err( 29 | const char *str, 30 | const char *errmesg, 31 | const int type); 32 | extern float strtofloat_or_err( 33 | const char *str, 34 | const char *errmesg); 35 | 36 | /* Like strncpy(3) but ensure null termination. */ 37 | static inline void xstrncpy( 38 | char *dest, 39 | const char *src, 40 | size_t n) 41 | { 42 | strncpy(dest, src, n - 1); 43 | dest[n - 1] = 0; 44 | } 45 | 46 | extern void *xmalloc( 47 | const size_t size); 48 | extern char *xstrdup( 49 | const char *str); 50 | 51 | extern void close_stdout( 52 | void); 53 | 54 | extern const char *iso_time( 55 | const time_t * t); 56 | -------------------------------------------------------------------------------- /packet/command.h: -------------------------------------------------------------------------------- 1 | /* 2 | mtr -- a network diagnostic tool 3 | Copyright (C) 2016 Matt Kimball 4 | 5 | This program is free software; you can redistribute it and/or modify 6 | it under the terms of the GNU General Public License version 2 as 7 | published by the Free Software Foundation. 8 | 9 | This program is distributed in the hope that it will be useful, 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | GNU General Public License for more details. 13 | 14 | You should have received a copy of the GNU General Public License along 15 | with this program; if not, write to the Free Software Foundation, Inc., 16 | 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 17 | */ 18 | 19 | #ifndef COMMAND_H 20 | #define COMMAND_H 21 | 22 | #include "probe.h" 23 | 24 | #define COMMAND_BUFFER_SIZE 4096 25 | 26 | /* Storage for incoming commands, prior to command parsing */ 27 | struct command_buffer_t { 28 | /* The file descriptor of the incoming command stream */ 29 | int command_stream; 30 | 31 | /* Storage to read commands into */ 32 | char incoming_buffer[COMMAND_BUFFER_SIZE]; 33 | 34 | /* The number of bytes read so far in incoming_buffer */ 35 | int incoming_read_position; 36 | }; 37 | 38 | void init_command_buffer( 39 | struct command_buffer_t *command_buffer, 40 | int command_stream); 41 | 42 | int read_commands( 43 | struct command_buffer_t *buffer); 44 | 45 | void dispatch_buffer_commands( 46 | struct command_buffer_t *buffer, 47 | struct net_state_t *net_state); 48 | 49 | #endif 50 | -------------------------------------------------------------------------------- /packet/sockaddr.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | 6 | void *sockaddr_addr_offset(const void *x) 7 | { 8 | if( x == NULL ) 9 | return NULL; 10 | 11 | if( ((struct sockaddr *)(x))->sa_family == AF_INET ) 12 | { 13 | return ((void *)(x) + offsetof(struct sockaddr_in, sin_addr)); 14 | }else 15 | if( ((struct sockaddr *)(x))->sa_family == AF_INET6 ) 16 | { 17 | return ((void *)(x) + offsetof(struct sockaddr_in6, sin6_addr)); 18 | } 19 | 20 | return NULL; 21 | } 22 | 23 | unsigned int sockaddr_addr_size(const void *x) 24 | { 25 | if( x == NULL ) 26 | return 0; 27 | if( ((struct sockaddr *)(x))->sa_family == AF_INET ) 28 | { 29 | return sizeof(struct in_addr); 30 | }else 31 | if( ((struct sockaddr *)(x))->sa_family == AF_INET6 ) 32 | { 33 | return sizeof(struct in6_addr); 34 | } 35 | return 0; 36 | } 37 | 38 | 39 | unsigned int sockaddr_size(const void *x) 40 | { 41 | if( x == NULL ) 42 | return 0; 43 | if( ((struct sockaddr *)(x))->sa_family == AF_INET ) 44 | { 45 | return sizeof(struct sockaddr_in); 46 | }else 47 | if( ((struct sockaddr *)(x))->sa_family == AF_INET6 ) 48 | { 49 | return sizeof(struct sockaddr_in6); 50 | } 51 | return 0; 52 | } 53 | 54 | in_port_t *sockaddr_port_offset(const void *x) 55 | { 56 | if( x == NULL ) 57 | return NULL; 58 | 59 | if( ((struct sockaddr *)(x))->sa_family == AF_INET ) 60 | { 61 | return ((void *)(x) + offsetof(struct sockaddr_in, sin_port)); 62 | }else 63 | if( ((struct sockaddr *)(x))->sa_family == AF_INET6 ) 64 | { 65 | return ((void *)(x) + offsetof(struct sockaddr_in6, sin6_port)); 66 | } 67 | 68 | return NULL; 69 | } 70 | -------------------------------------------------------------------------------- /BSDCOPYING: -------------------------------------------------------------------------------- 1 | Portions of this software have the following copyright. 2 | 3 | -- 4 | 5 | Copyright (c) 1991, 1993 6 | The Regents of the University of California. All rights reserved. 7 | 8 | Redistribution and use in source and binary forms, with or without 9 | modification, are permitted provided that the following conditions 10 | are met: 11 | 1. Redistributions of source code must retain the above copyright 12 | notice, this list of conditions and the following disclaimer. 13 | 2. Redistributions in binary form must reproduce the above copyright 14 | notice, this list of conditions and the following disclaimer in the 15 | documentation and/or other materials provided with the distribution. 16 | 4. Neither the name of the University nor the names of its contributors 17 | may be used to endorse or promote products derived from this software 18 | without specific prior written permission. 19 | 20 | THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 21 | ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 22 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 23 | ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 24 | FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 25 | DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 26 | OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 27 | HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 28 | LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 29 | OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 30 | SUCH DAMAGE. 31 | -------------------------------------------------------------------------------- /packet/cmdparse.h: -------------------------------------------------------------------------------- 1 | /* 2 | mtr -- a network diagnostic tool 3 | Copyright (C) 2016 Matt Kimball 4 | 5 | This program is free software; you can redistribute it and/or modify 6 | it under the terms of the GNU General Public License version 2 as 7 | published by the Free Software Foundation. 8 | 9 | This program is distributed in the hope that it will be useful, 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | GNU General Public License for more details. 13 | 14 | You should have received a copy of the GNU General Public License along 15 | with this program; if not, write to the Free Software Foundation, Inc., 16 | 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 17 | */ 18 | 19 | #ifndef CMDPARSE_H 20 | #define CMDPARSE_H 21 | 22 | enum { 23 | MAX_COMMAND_ARGUMENTS = 16, 24 | MAX_COMMAND_TOKENS = MAX_COMMAND_ARGUMENTS * 2 + 2 25 | }; 26 | 27 | /* Parsed commands, or command replies, ready for semantic interpretation */ 28 | struct command_t { 29 | /* A unique value for matching command requests with replies */ 30 | int token; 31 | 32 | /* Text indiciating the command type, or reply type */ 33 | char *command_name; 34 | 35 | /* The number of key, value argument pairs used */ 36 | int argument_count; 37 | 38 | /* Names for each argument */ 39 | char *argument_name[MAX_COMMAND_ARGUMENTS]; 40 | 41 | /* Values for each argument, parallel to the argument_name array */ 42 | char *argument_value[MAX_COMMAND_ARGUMENTS]; 43 | }; 44 | 45 | int parse_command( 46 | struct command_t *command, 47 | char *command_string); 48 | 49 | #endif 50 | -------------------------------------------------------------------------------- /packet/deconstruct_unix.h: -------------------------------------------------------------------------------- 1 | /* 2 | mtr -- a network diagnostic tool 3 | Copyright (C) 2016 Matt Kimball 4 | 5 | This program is free software; you can redistribute it and/or modify 6 | it under the terms of the GNU General Public License version 2 as 7 | published by the Free Software Foundation. 8 | 9 | This program is distributed in the hope that it will be useful, 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | GNU General Public License for more details. 13 | 14 | You should have received a copy of the GNU General Public License along 15 | with this program; if not, write to the Free Software Foundation, Inc., 16 | 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 17 | */ 18 | 19 | #ifndef DECONSTRUCT_H 20 | #define DECONSTRUCT_H 21 | 22 | #include "probe.h" 23 | 24 | typedef void ( 25 | *received_packet_func_t) ( 26 | struct net_state_t * net_state, 27 | const struct sockaddr_storage * remote_addr, 28 | const void *packet, 29 | int packet_length, 30 | struct timeval * timestamp); 31 | 32 | void handle_received_ip4_packet( 33 | struct net_state_t *net_state, 34 | const struct sockaddr_storage *remote_addr, 35 | const void *packet, 36 | int packet_length, 37 | struct timeval *timestamp); 38 | 39 | void handle_received_ip6_packet( 40 | struct net_state_t *net_state, 41 | const struct sockaddr_storage *remote_addr, 42 | const void *packet, 43 | int packet_length, 44 | struct timeval *timestamp); 45 | 46 | void handle_error_queue_packet( 47 | struct net_state_t *net_state, 48 | const struct sockaddr_storage *remote_addr, 49 | int icmp_result, 50 | int proto, 51 | char *packet, 52 | int packet_length, 53 | struct timeval *timestamp); 54 | 55 | #endif 56 | -------------------------------------------------------------------------------- /packet/wait_cygwin.c: -------------------------------------------------------------------------------- 1 | /* 2 | mtr -- a network diagnostic tool 3 | Copyright (C) 2016 Matt Kimball 4 | 5 | This program is free software; you can redistribute it and/or modify 6 | it under the terms of the GNU General Public License version 2 as 7 | published by the Free Software Foundation. 8 | 9 | This program is distributed in the hope that it will be useful, 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | GNU General Public License for more details. 13 | 14 | You should have received a copy of the GNU General Public License along 15 | with this program; if not, write to the Free Software Foundation, Inc., 16 | 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 17 | */ 18 | 19 | #include "wait.h" 20 | 21 | #include 22 | #include 23 | #include 24 | 25 | #include "command.h" 26 | 27 | /* 28 | Wait for either a request from the command stream or 29 | for the probe results to be passed from the ICMP service 30 | thread. 31 | */ 32 | void wait_for_activity( 33 | struct command_buffer_t *command_buffer, 34 | struct net_state_t *net_state) 35 | { 36 | int nfds; 37 | fd_set read_set; 38 | int ready_count; 39 | 40 | FD_ZERO(&read_set); 41 | 42 | FD_SET(command_buffer->command_stream, &read_set); 43 | nfds = command_buffer->command_stream + 1; 44 | 45 | FD_SET(net_state->platform.thread_out_pipe_read, &read_set); 46 | if (net_state->platform.thread_out_pipe_read >= nfds) { 47 | nfds = net_state->platform.thread_out_pipe_read + 1; 48 | } 49 | 50 | while (true) { 51 | ready_count = 52 | select(nfds, &read_set, NULL, NULL, NULL); 53 | 54 | if (ready_count != -1) { 55 | return; 56 | } 57 | 58 | /* 59 | EINTR and EAGAIN simply mean that the select should 60 | be retried. 61 | */ 62 | if (errno != EINTR && errno != EAGAIN) { 63 | error(EXIT_FAILURE, errno, "unexpected select error"); 64 | } 65 | } 66 | } 67 | -------------------------------------------------------------------------------- /bash-completion/mtr: -------------------------------------------------------------------------------- 1 | _mtr_module() 2 | { 3 | local cur prev OPTS 4 | COMPREPLY=() 5 | cur="${COMP_WORDS[COMP_CWORD]}" 6 | prev="${COMP_WORDS[COMP_CWORD-1]}" 7 | case $prev in 8 | '-F'|'--filename') 9 | local IFS=$'\n' 10 | compopt -o filenames 11 | COMPREPLY=( $(compgen -f -- $cur) ) 12 | return 0 13 | ;; 14 | '-a'|'--address') 15 | COMPREPLY=( $(compgen -W "ADDRESS" -- $cur) ) 16 | return 0 17 | ;; 18 | '-f'|'--first-ttl'|'-m'|'--max-ttl'|'-m'|'--max-unknown'|'-B'|'--bitpattern'|'-Q'|'--tos'|'-c'|'--report-cycles') 19 | COMPREPLY=( $(compgen -W "NUMBER" -- $cur) ) 20 | return 0 21 | ;; 22 | '-P'|'--port'|'-L'|'--localport') 23 | COMPREPLY=( $(compgen -W "PORT" -- $cur) ) 24 | return 0 25 | ;; 26 | '-s'|'--psize') 27 | COMPREPLY=( $(compgen -W "SIZE" -- $cur) ) 28 | return 0 29 | ;; 30 | '-i'|'--interval'|'-G'|'--gracetime'|'-Z'|'--timeout') 31 | COMPREPLY=( $(compgen -W "SECONDS" -- $cur) ) 32 | return 0 33 | ;; 34 | '-M'|'--mark') 35 | COMPREPLY=( $(compgen -W "MARK" -- $cur) ) 36 | return 0 37 | ;; 38 | '--displaymode') 39 | COMPREPLY=( $(compgen -W "{0..2}" -- $cur) ) 40 | return 0 41 | ;; 42 | '-y'|'--ipinfo') 43 | COMPREPLY=( $(compgen -W "{0..4}" -- $cur) ) 44 | return 0 45 | ;; 46 | '-o'|'--order') 47 | COMPREPLY=( $(compgen -W "LDRSNBAWVGJMXI" -- $cur) ) 48 | return 0 49 | ;; 50 | esac 51 | case $cur in 52 | -*) 53 | OPTS=' 54 | --filename --inet --inet6 --udp --tcp --address --first-ttl 55 | --max-ttl --max-unknown --port --localport --psize --bitpattern 56 | --interval --gracetime --tos --mpls --timeout --mark --report 57 | --report-wide --report-cycles --json --xml --csv --raw --split 58 | --curses --displaymode --gtk --no-dns --show-ips --order --ipinfo 59 | --aslookup --help --version 60 | ' 61 | COMPREPLY=( $(compgen -W "${OPTS[*]}" -- $cur) ) 62 | return 0 63 | ;; 64 | esac 65 | COMPREPLY=( $(compgen -W "ip_address hostname" -- $cur) ) 66 | return 0 67 | } 68 | complete -F _mtr_module mtr 69 | -------------------------------------------------------------------------------- /packet/timeval.c: -------------------------------------------------------------------------------- 1 | /* 2 | mtr -- a network diagnostic tool 3 | Copyright (C) 2016 Matt Kimball 4 | 5 | This program is free software; you can redistribute it and/or modify 6 | it under the terms of the GNU General Public License version 2 as 7 | published by the Free Software Foundation. 8 | 9 | This program is distributed in the hope that it will be useful, 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | GNU General Public License for more details. 13 | 14 | You should have received a copy of the GNU General Public License along 15 | with this program; if not, write to the Free Software Foundation, Inc., 16 | 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 17 | */ 18 | 19 | #include "timeval.h" 20 | 21 | /* 22 | Ensure that a timevalue has a microsecond value in the range 23 | [0.0, 1.0e6) microseconds by converting microseconds to full seconds. 24 | */ 25 | void normalize_timeval( 26 | struct timeval *timeval) 27 | { 28 | int full_sec; 29 | 30 | /* 31 | If tv_usec has overflowed a full second, convert the overflow 32 | to tv_sec. 33 | */ 34 | full_sec = timeval->tv_usec / 1000000; 35 | timeval->tv_sec += full_sec; 36 | timeval->tv_usec -= 1000000 * full_sec; 37 | 38 | /* If tv_usec is negative, make it positive by rolling tv_sec back */ 39 | if (timeval->tv_usec < 0) { 40 | timeval->tv_sec--; 41 | timeval->tv_usec += 1000000; 42 | } 43 | 44 | /* If the entire time value is negative, clamp to zero */ 45 | if (timeval->tv_sec < 0) { 46 | timeval->tv_sec = 0; 47 | timeval->tv_usec = 0; 48 | } 49 | } 50 | 51 | /* 52 | Compare two time values. Return: 53 | 54 | -1 if a < b 55 | 0 if a == b 56 | 1 if a > b 57 | */ 58 | int compare_timeval( 59 | struct timeval a, 60 | struct timeval b) 61 | { 62 | if (a.tv_sec > b.tv_sec) { 63 | return 1; 64 | } 65 | if (a.tv_sec < b.tv_sec) { 66 | return -1; 67 | } 68 | 69 | if (a.tv_usec > b.tv_usec) { 70 | return 1; 71 | } 72 | if (a.tv_usec < b.tv_usec) { 73 | return -1; 74 | } 75 | 76 | return 0; 77 | } 78 | -------------------------------------------------------------------------------- /ui/cmdpipe.h: -------------------------------------------------------------------------------- 1 | /* 2 | mtr -- a network diagnostic tool 3 | Copyright (C) 2016 Matt Kimball 4 | 5 | This program is free software; you can redistribute it and/or modify 6 | it under the terms of the GNU General Public License version 2 as 7 | published by the Free Software Foundation. 8 | 9 | This program is distributed in the hope that it will be useful, 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | GNU General Public License for more details. 13 | 14 | You should have received a copy of the GNU General Public License along 15 | with this program; if not, write to the Free Software Foundation, Inc., 16 | 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 17 | */ 18 | 19 | #ifndef CMDPIPE_H 20 | #define CMDPIPE_H 21 | 22 | #include "mtr.h" 23 | 24 | #define COMMAND_BUFFER_SIZE 4096 25 | #define PACKET_REPLY_BUFFER_SIZE 4096 26 | 27 | /* We use a pipe to the mtr-packet subprocess to generate probes */ 28 | struct packet_command_pipe_t { 29 | /* the process id of mtr-packet */ 30 | pid_t pid; 31 | 32 | /* the end of the pipe we read for replies */ 33 | int read_fd; 34 | 35 | /* the end of the pipe we write for commands */ 36 | int write_fd; 37 | 38 | /* storage for incoming replies */ 39 | char reply_buffer[PACKET_REPLY_BUFFER_SIZE]; 40 | 41 | /* the number of bytes currently used in reply_buffer */ 42 | size_t reply_buffer_used; 43 | }; 44 | 45 | typedef 46 | void ( 47 | *probe_reply_func_t) ( 48 | struct mtr_ctl * ctl, 49 | int sequence, 50 | int err, 51 | struct mplslen * mpls, 52 | ip_t * addr, 53 | int round_trip_time); 54 | 55 | int open_command_pipe( 56 | struct mtr_ctl *ctl, 57 | struct packet_command_pipe_t *cmdpipe); 58 | 59 | void close_command_pipe( 60 | struct packet_command_pipe_t *cmdpipe); 61 | 62 | void send_probe_command( 63 | struct mtr_ctl *ctl, 64 | struct packet_command_pipe_t *cmdpipe, 65 | ip_t * address, 66 | ip_t * localaddress, 67 | int packet_size, 68 | int sequence, 69 | int time_to_live); 70 | 71 | void handle_command_replies( 72 | struct mtr_ctl *ctl, 73 | struct packet_command_pipe_t *cmdpipe, 74 | probe_reply_func_t reply_func); 75 | 76 | #endif 77 | -------------------------------------------------------------------------------- /ui/raw.c: -------------------------------------------------------------------------------- 1 | /* 2 | mtr -- a network diagnostic tool 3 | Copyright (C) 1998 R.E.Wolff@BitWizard.nl 4 | 5 | raw.c -- raw output (for logging for later analysis) 6 | 7 | This program is free software; you can redistribute it and/or modify 8 | it under the terms of the GNU General Public License version 2 as 9 | published by the Free Software Foundation. 10 | 11 | This program is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | GNU General Public License for more details. 15 | 16 | You should have received a copy of the GNU General Public License along 17 | with this program; if not, write to the Free Software Foundation, Inc., 18 | 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 19 | */ 20 | 21 | #include "config.h" 22 | 23 | #include 24 | #include 25 | #include 26 | #include 27 | #include 28 | #include 29 | #include 30 | 31 | #include "mtr.h" 32 | #include "raw.h" 33 | #include "net.h" 34 | #include "dns.h" 35 | 36 | 37 | /* Log an echo request, or a "ping" */ 38 | void raw_rawxmit( 39 | int host, 40 | int seq) 41 | { 42 | printf("x %d %d\n", host, seq); 43 | fflush(stdout); 44 | } 45 | 46 | /* Log an echo reply, or a "pong" */ 47 | void raw_rawping( 48 | struct mtr_ctl *ctl, 49 | int host, 50 | int msec, 51 | int seq) 52 | { 53 | static int havename[MaxHost]; 54 | char *name; 55 | 56 | if (ctl->dns && !havename[host]) { 57 | name = dns_lookup2(ctl, net_addr(host)); 58 | if (name) { 59 | havename[host]++; 60 | printf("d %d %s\n", host, name); 61 | } 62 | } 63 | printf("p %d %d %d\n", host, msec, seq); 64 | fflush(stdout); 65 | } 66 | 67 | void raw_rawhost( 68 | struct mtr_ctl *ctl, 69 | int host, 70 | ip_t *ip_addr, 71 | struct mplslen *mpls) 72 | { 73 | printf("h %d %s\n", host, strlongip(ctl->af, ip_addr)); 74 | if (ctl->enablempls) { 75 | int k; 76 | for (k = 0; k < mpls->labels; k++) 77 | printf("m %d %lu %u %u %u\n", 78 | host, mpls->label[k], mpls->tc[k], mpls->s[k], mpls->ttl[k]); 79 | } 80 | 81 | fflush(stdout); 82 | } 83 | -------------------------------------------------------------------------------- /ui/display.h: -------------------------------------------------------------------------------- 1 | /* 2 | mtr -- a network diagnostic tool 3 | Copyright (C) 1997,1998 Matt Kimball 4 | 5 | This program is free software; you can redistribute it and/or modify 6 | it under the terms of the GNU General Public License version 2 as 7 | published by the Free Software Foundation. 8 | 9 | This program is distributed in the hope that it will be useful, 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | GNU General Public License for more details. 13 | 14 | You should have received a copy of the GNU General Public License along 15 | with this program; if not, write to the Free Software Foundation, Inc., 16 | 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 17 | */ 18 | 19 | #include 20 | 21 | /* Don't put a trailing comma in enumeration lists. Some compilers 22 | (notably the one on Irix 5.2) do not like that. */ 23 | enum { ActionNone, ActionQuit, ActionReset, ActionDisplay, 24 | ActionClear, ActionPause, ActionResume, ActionMPLS, ActionDNS, 25 | #ifdef HAVE_IPINFO 26 | ActionII, ActionAS, 27 | #endif 28 | ActionScrollDown, ActionScrollUp 29 | }; 30 | 31 | enum { 32 | DisplayReport, 33 | #ifdef HAVE_CURSES 34 | DisplayCurses, 35 | #endif 36 | #ifdef HAVE_GTK 37 | DisplayGTK, 38 | #endif 39 | DisplaySplit, 40 | DisplayRaw, 41 | DisplayXML, 42 | DisplayCSV, 43 | DisplayTXT, 44 | #ifdef HAVE_JANSSON 45 | DisplayJSON, 46 | #endif 47 | }; 48 | 49 | enum { 50 | DisplayModeDefault, 51 | DisplayModeBlockmap, 52 | DisplayModeBlockmapScale, 53 | DisplayModeMAX /* this must be the last DisplayMode entry */ 54 | }; 55 | 56 | /* Prototypes for display.c */ 57 | extern void display_detect( 58 | struct mtr_ctl *ctl, 59 | int *argc, 60 | char ***argv); 61 | extern void display_open( 62 | struct mtr_ctl *ctl); 63 | extern void display_close( 64 | struct mtr_ctl *ctl); 65 | extern void display_redraw( 66 | struct mtr_ctl *ctl); 67 | extern void display_rawxmit( 68 | struct mtr_ctl *ctl, 69 | int hostnum, 70 | int seq); 71 | extern void display_rawping( 72 | struct mtr_ctl *ctl, 73 | int hostnum, 74 | int msec, 75 | int seq); 76 | extern void display_rawhost( 77 | struct mtr_ctl *ctl, 78 | int hostnum, 79 | ip_t *ip_addr, 80 | struct mplslen *mpls); 81 | extern int display_keyaction( 82 | struct mtr_ctl *ctl); 83 | extern void display_loop( 84 | struct mtr_ctl *ctl); 85 | extern void display_clear( 86 | struct mtr_ctl *ctl); 87 | extern char *host_error_to_string( 88 | int err); 89 | -------------------------------------------------------------------------------- /SECURITY: -------------------------------------------------------------------------------- 1 | SECURITY ISSUES RELATED TO MTR 2 | 3 | mtr invokes a sub-process, mtr-packet, which requires extra privileges 4 | to send custom packets, and there are security implications from 5 | granting this. 6 | 7 | There are several different ways to provide the privileges: 8 | 9 | 1. Add limited privileges on systems that support this. (Preferred.) 10 | 2. Run mtr as the root user. 11 | 3. Make mtr-packet a setuid-root binary. 12 | 13 | Details: 14 | 15 | 1. Add limited privileges on systems that support this. 16 | 17 | Some operating systems allow binaries to be run with only the subset 18 | of security privileges that are actually needed. 19 | 20 | Linux: 21 | On Linux, privileges are known as capabilities. The only additional 22 | capability that mtr-packet needs is cap_net_raw. To give this 23 | capability to the mtr-packet binary, run the following command as root: 24 | 25 | # setcap cap_net_raw+ep mtr-packet 26 | 27 | 28 | 2. Run mtr as the root user. 29 | 30 | You can limit mtr usage to the root user by not putting a setuid bit 31 | on the mtr-packet binary. In that case, the security implications are 32 | minimal. 33 | 34 | 35 | 3. Make mtr-packet a setuid-root binary. 36 | 37 | The mtr-packet binary can be made setuid-root, which is what "make install" 38 | does only if using setcap (above) fails. Using setcap is tried first. 39 | 40 | When mtr-packet is installed as suid-root, some concern over security is 41 | justified. mtr-packet does the following two things after it is launched: 42 | 43 | * mtr-packet open sockets for sending raw packets and for receiving 44 | ICMP packets. 45 | * mtr-packet drops root privileges by setting the effective uid to 46 | match uid or the user calling mtr. 47 | * If capabilities support is available, mtr-packet drops all privileged 48 | capabilities. 49 | 50 | See main() in packet.c and init_net_state_privileged() in probe_unix.c 51 | for the details of this process. 52 | 53 | This should limit the possibilities of using mtr to breach system security. 54 | The worst case scenario is as follows: 55 | 56 | Due to some oversight in the mtr-packet code, a malicious user is able to 57 | overrun one of mtr-packets's internal buffers with binary code that is 58 | eventually executed. The malicious user is still not able to read 59 | from or write to any system files other than those normally accessible 60 | by the user running mtr. The only privileges gained are access to the raw 61 | socket, which would allow the malicious user to listen to all ICMP packets 62 | arriving at the system, and to send forged packets with arbitrary contents. 63 | 64 | 65 | If you have further questions or comments about security issues, 66 | please see the README file for details on how to submit them. 67 | -------------------------------------------------------------------------------- /AUTHORS: -------------------------------------------------------------------------------- 1 | 2 | Matt Kimball is the primary author of mtr. 3 | 4 | Roger Wolff is currently maintaining mtr. 5 | 6 | 7 | Bug reports and feature requests should be sent as described in 8 | the README file. 9 | 10 | Thanks to everyone who has provided feedback on mtr. 11 | 12 | Thanks especially to those of you who have sent code: 13 | (Reverse alphabetical order, and sometimes I just add people at 14 | the end... ) 15 | 16 | Bohdan Vlasyuk 17 | Evgeniy Tretyak 18 | John Thacker 19 | Juha Takala 20 | David Sward 21 | David Stone 22 | Andrew Stesin 23 | Greg Stark 24 | Robert Sparks 25 | Mike Simons 26 | Aaron Scarisbrick 27 | Craig Milo Rogers 28 | Antonio Querubin 29 | Russell Nelson 30 | Davin Milun 31 | Josh Martin 32 | Alexander V. Lukyanov 33 | Charles Levert 34 | Bertrand Leconte 35 | Anand Kumria 36 | Olav Kvittem 37 | Adam Kramer 38 | Philip Kizer 39 | Simon Kirby 40 | Sami Kerola 41 | Christophe Kalt 42 | Steve Kann 43 | Brett Johnson 44 | Roland Illig 45 | Damian Gryski 46 | Rob Foehl 47 | Mircea Damian 48 | Cougar 49 | Travis Cross 50 | Brian Casey 51 | Andrew Brown 52 | Bill Bogstad 53 | Marc Bejarano 54 | Moritz Barsnick 55 | Thomas Klausner 56 | Roderick Groesbeek 57 | Kyle J. McKay 58 | Joseph Carter 59 | Thales 60 | "Min" 61 | Vaibhav Bajpai 62 | Jürgen Schönwälder 63 | 64 | and anyone who has slipped through the cracks of my mail file. 65 | 66 | Authors: If you want your Email mentioned here, send it to me. 67 | If you don't want your Email mentioned here, tell me. 68 | 69 | -- REW 70 | -------------------------------------------------------------------------------- /test/param.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | # 3 | # mtr -- a network diagnostic tool 4 | # Copyright (C) 2016 Matt Kimball 5 | # 6 | # This program is free software; you can redistribute it and/or modify 7 | # it under the terms of the GNU General Public License version 2 as 8 | # published by the Free Software Foundation. 9 | # 10 | # This program is distributed in the hope that it will be useful, 11 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | # GNU General Public License for more details. 14 | # 15 | # You should have received a copy of the GNU General Public License along 16 | # with this program; if not, write to the Free Software Foundation, Inc., 17 | # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 18 | # 19 | 20 | '''Test probe customization parameters''' 21 | 22 | import sys 23 | import unittest 24 | 25 | import mtrpacket 26 | 27 | 28 | @unittest.skipIf(sys.platform == 'cygwin', 'No Cygwin test') 29 | class TestParameters(mtrpacket.MtrPacketTest): 30 | 'Use parameter arguments to mtr-packet and examine the resulting packet' 31 | 32 | def test_size(self): 33 | 'Test probes sent with an explicit packet size' 34 | 35 | with mtrpacket.PacketListen('-4') as listen: 36 | cmd = '20 send-probe ip-4 127.0.0.1 size 512' 37 | 38 | self.write_command(cmd) 39 | 40 | self.assertEqual(listen.attrib['size'], '512') 41 | 42 | def test_pattern(self): 43 | 'Test probes are filled with the requested bit pattern' 44 | 45 | with mtrpacket.PacketListen('-4') as listen: 46 | cmd = '20 send-probe ip-4 127.0.0.1 bit-pattern 44' 47 | 48 | self.write_command(cmd) 49 | 50 | self.assertEqual(listen.attrib['bitpattern'], '44') 51 | 52 | def test_tos(self): 53 | 'Test setting the TOS field' 54 | 55 | with mtrpacket.PacketListen('-4') as listen: 56 | cmd = '20 send-probe ip-4 127.0.0.1 tos 62' 57 | 58 | self.write_command(cmd) 59 | 60 | self.assertEqual(listen.attrib['tos'], '62') 61 | 62 | 63 | @unittest.skipIf(sys.platform == 'cygwin', 'No Cygwin test') 64 | class TestIPv6Parameters(mtrpacket.MtrPacketTest): 65 | 'Test packet parameter customization for IPv6' 66 | 67 | @unittest.skipUnless(mtrpacket.HAVE_IPV6, 'No IPv6') 68 | def test_param(self): 69 | 'Test a variety of packet parameters' 70 | 71 | with mtrpacket.PacketListen('-6') as listen: 72 | param = 'size 256 bit-pattern 51 tos 77' 73 | cmd = '20 send-probe ip-6 ::1 ' + param 74 | 75 | self.write_command(cmd) 76 | 77 | self.assertEqual(listen.attrib['size'], '256') 78 | self.assertEqual(listen.attrib['bitpattern'], '51') 79 | 80 | 81 | if __name__ == '__main__': 82 | mtrpacket.check_running_as_root() 83 | unittest.main() 84 | -------------------------------------------------------------------------------- /ui/net.h: -------------------------------------------------------------------------------- 1 | /* 2 | mtr -- a network diagnostic tool 3 | Copyright (C) 1997,1998 Matt Kimball 4 | 5 | This program is free software; you can redistribute it and/or modify 6 | it under the terms of the GNU General Public License version 2 as 7 | published by the Free Software Foundation. 8 | 9 | This program is distributed in the hope that it will be useful, 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | GNU General Public License for more details. 13 | 14 | You should have received a copy of the GNU General Public License along 15 | with this program; if not, write to the Free Software Foundation, Inc., 16 | 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 17 | */ 18 | 19 | /* Prototypes for functions in net.c */ 20 | #include 21 | #include 22 | #include 23 | #include 24 | #include 25 | #include 26 | #ifdef ENABLE_IPV6 27 | #include 28 | #endif 29 | 30 | #include 31 | 32 | #include "mtr.h" 33 | 34 | extern int net_open( 35 | struct mtr_ctl *ctl, 36 | struct addrinfo *res); 37 | extern void net_reopen( 38 | struct mtr_ctl *ctl, 39 | struct addrinfo *res); 40 | extern void net_reset( 41 | struct mtr_ctl *ctl); 42 | extern void net_close( 43 | void); 44 | extern int net_waitfd( 45 | void); 46 | extern void net_process_return( 47 | struct mtr_ctl *ctl); 48 | extern void net_harvest_fds( 49 | struct mtr_ctl *ctl); 50 | 51 | extern int net_max( 52 | struct mtr_ctl *ctl); 53 | extern int net_min( 54 | struct mtr_ctl *ctl); 55 | extern int net_last( 56 | int at); 57 | extern ip_t *net_addr( 58 | int at); 59 | extern int net_err( 60 | int at); 61 | extern struct mplslen *net_mpls( 62 | int at); 63 | extern struct mplslen *net_mplss( 64 | int, 65 | int); 66 | extern int net_loss( 67 | int at); 68 | extern int net_drop( 69 | int at); 70 | extern int net_best( 71 | int at); 72 | extern int net_worst( 73 | int at); 74 | extern int net_avg( 75 | int at); 76 | extern int net_gmean( 77 | int at); 78 | extern int net_stdev( 79 | int at); 80 | extern int net_jitter( 81 | int at); 82 | extern int net_jworst( 83 | int at); 84 | extern int net_javg( 85 | int at); 86 | extern int net_jinta( 87 | int at); 88 | extern ip_t *net_addrs( 89 | int at, 90 | int i); 91 | extern char *net_localaddr( 92 | void); 93 | extern char *net_remoteaddr( 94 | void); 95 | 96 | extern int net_send_batch( 97 | struct mtr_ctl *ctl); 98 | extern void net_end_transit( 99 | void); 100 | 101 | extern int calc_deltatime( 102 | float WaitTime); 103 | 104 | extern int net_returned( 105 | int at); 106 | extern int net_xmit( 107 | int at); 108 | 109 | extern int net_up( 110 | int at); 111 | 112 | extern int *net_saved_pings( 113 | int at); 114 | extern void net_save_xmit( 115 | int at); 116 | extern void net_save_return( 117 | int at, 118 | int seq, 119 | int ms); 120 | 121 | extern int addrcmp( 122 | void *a, 123 | void *b, 124 | int af); 125 | 126 | extern void net_add_fds( 127 | fd_set * writefd, 128 | int *maxfd); 129 | -------------------------------------------------------------------------------- /packet/probe_cygwin.h: -------------------------------------------------------------------------------- 1 | /* 2 | mtr -- a network diagnostic tool 3 | Copyright (C) 2016 Matt Kimball 4 | 5 | This program is free software; you can redistribute it and/or modify 6 | it under the terms of the GNU General Public License version 2 as 7 | published by the Free Software Foundation. 8 | 9 | This program is distributed in the hope that it will be useful, 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | GNU General Public License for more details. 13 | 14 | You should have received a copy of the GNU General Public License along 15 | with this program; if not, write to the Free Software Foundation, Inc., 16 | 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 17 | */ 18 | 19 | #ifndef PROBE_CYGWIN_H 20 | #define PROBE_CYGWIN_H 21 | 22 | #include 23 | #include 24 | #include 25 | #include 26 | 27 | /* 28 | This should be in the Windows headers, but is missing from 29 | Cygwin's Windows headers. 30 | */ 31 | typedef struct icmpv6_echo_reply_lh { 32 | /* 33 | Although Windows uses an IPV6_ADDRESS_EX here, we are using uint8_t 34 | fields to avoid structure padding differences between gcc and 35 | Visual C++. (gcc wants to align the flow info to a 4 byte boundary, 36 | and Windows uses it unaligned.) 37 | */ 38 | uint8_t PortBits[2]; 39 | uint8_t FlowInfoBits[4]; 40 | uint8_t AddressBits[16]; 41 | uint8_t ScopeIdBits[4]; 42 | 43 | ULONG Status; 44 | unsigned int RoundTripTime; 45 | } ICMPV6_ECHO_REPLY, 46 | *PICMPV6_ECHO_REPLY; 47 | 48 | /* 49 | Windows requires an echo reply structure for each in-flight 50 | ICMP probe. 51 | */ 52 | struct probe_platform_t { 53 | /* 54 | We need a backpointer to the net_state because of the way 55 | IcmpSendEcho2 passes our context. 56 | */ 57 | struct net_state_t *net_state; 58 | 59 | /* IP version (4 or 6) used for the probe */ 60 | int ip_version; 61 | }; 62 | 63 | /* A Windows HANDLE for the ICMP session */ 64 | struct net_state_platform_t { 65 | HANDLE icmp4; 66 | HANDLE icmp6; 67 | bool ip4_socket_raw; 68 | bool ip6_socket_raw; 69 | 70 | HANDLE thread_in_pipe_read_handle; 71 | int thread_in_pipe_read, thread_in_pipe_write; 72 | int thread_out_pipe_read, thread_out_pipe_write; 73 | }; 74 | 75 | /* 76 | A request object passed between the main thread and the ICMP 77 | service thread representing an outstanding probe. 78 | */ 79 | struct icmp_thread_request_t { 80 | /* 81 | net_state and probe are const to avoid race conditions between 82 | the main thread and the ICMP service thread. They are to be 83 | considered read-only on the ICMP service thread. 84 | */ 85 | const struct net_state_t *net_state; 86 | const struct probe_t *probe; 87 | 88 | /* Parameters for the probe request */ 89 | int ip_version; 90 | int ttl; 91 | int timeout; 92 | int packet_size; 93 | int bit_pattern; 94 | 95 | /* Source and destination for the probe */ 96 | struct sockaddr_storage dest_sockaddr; 97 | struct sockaddr_storage src_sockaddr; 98 | 99 | /* Scratch space used by the ICMP.DLL API */ 100 | union { 101 | ICMP_ECHO_REPLY *reply4; 102 | ICMPV6_ECHO_REPLY *reply6; 103 | }; 104 | 105 | /* Probe results */ 106 | int icmp_type; 107 | int reply_status; 108 | int round_trip_us; 109 | 110 | /* The remote address responding to the probe */ 111 | struct sockaddr_storage remote_addr; 112 | }; 113 | 114 | #endif 115 | -------------------------------------------------------------------------------- /FORMATS: -------------------------------------------------------------------------------- 1 | 2 | The "split" format is for a separating the gui from the main program. 3 | The main program can be installed setuid, and you don't want to link a 4 | gui-library with a setuid program. 5 | 6 | 7 | The split format is: 8 | 9 | 10 | 11 | 12 | The "raw" format is: 13 | 14 | hostline|xmitline|pingline|dnsline|timestampline|mplsline 15 | 16 | hostline: 17 | h 18 | 19 | xmitline: 20 | x 21 | 22 | pingline: 23 | p 24 | 25 | dnsline: 26 | d 27 | 28 | timestampline: 29 | t 30 | 31 | mplsline: 32 | m