Sami Kerola [Sun, 4 Sep 2016 16:20:55 +0000 (17:20 +0100)]
cleanup: set variable only if it is used
Variable introduction needs to be same way preprocessor conditional as the
related code. This is a minor clean up, because modern compilers should
remove these types of variables automatically.
Sami Kerola [Sun, 4 Sep 2016 16:08:17 +0000 (17:08 +0100)]
cleanup: remove more/bottom labels header separation from mpls
Commit a932cb2abc85651ca6f33a06d7b64448c1d27f65 added this separation, but
after five years and a bit the printouts has not become different. It is
time to remove this todo item.
Sami Kerola [Sun, 4 Sep 2016 08:30:25 +0000 (09:30 +0100)]
cleanup: make unused and const attributes to look the same
Definition CONST was already reserved in net.h to mean 'const' as a variable
attribute, so function attribute got a ATTRIBUTE_ prefix to separate them.
This change unifies unused to look the same.
Sami Kerola [Sun, 4 Sep 2016 00:12:08 +0000 (01:12 +0100)]
crash fix: ctl->iiwidth_len was not initialized correctly
It was a mistake to add iiwidth_len to struct mtr_ctl. First of all the
value needed in that field was never set, and that resulted to crash when
running command with --csv option.
Secondly adding the field was bad idea to begin with. Number of array
elements is known only within context of asn.c file, so it is better to add
interface to query it rather than try to set value to a structure. Later
design is prone to cause futher bugs, if/when execution flow is not as one
might assume.
Sami Kerola [Sat, 3 Sep 2016 22:25:17 +0000 (23:25 +0100)]
crash fix: add ctl structure to gtk Pause_clicked() handler
Without this handler net_max() will crash with SIGSEGV at line 1209. gdb
backtrace gave clear hint what was the problem, and where it needs to be
fixed.
#0 0x4109db in net_max /home/src/mtr/net.c:1209
#1 0x42478e in gtk_redraw /home/src/mtr/gtk.c:508
#2 0x422fc7 in Pause_clicked /home/src/mtr/gtk.c:121
Sami Kerola [Sat, 3 Sep 2016 07:02:09 +0000 (08:02 +0100)]
cleanup: merge two trim functions to one
As a minor improvement make the trimmed string to stay at same start
address, so that trims can be safely done to pointers that are allocated and
need to be free'd later on. There is no such case in this code, but it is
good idea to write functions the way they will not cause memory issues
if/when such use case happens.
Sami Kerola [Sun, 4 Sep 2016 15:33:25 +0000 (16:33 +0100)]
bug fix: long option --gracetime is correct, --graceperiod is not
Commit 5dbeb8f1b4084c38103e92dbd028da2762c1f0a9 introduced new long option
--gracetime, that was documented as --graceperiod. Only one or the other
can be correct, so pick the --gracetime and update documentation to tell
this is, the expected long option.
Sami Kerola [Mon, 29 Aug 2016 11:42:59 +0000 (12:42 +0100)]
cleanup: remove commented out includes in dns.c
Thees have been two years commented out, and if someone really has to fiddle
around with comments that is a failure of autotools usage and needs to be
addressed by getting the autoconf to do the right things.
Sami Kerola [Mon, 29 Aug 2016 09:54:55 +0000 (10:54 +0100)]
warnings: avoid vla when malloc() is more appropriate
Assuming allocatin failure will happen use of vla will cause very strange
looking error. In this occasion it is better to use malloc, and check it
was successful. Found with smatch scan.
Sami Kerola [Sun, 28 Aug 2016 19:12:58 +0000 (20:12 +0100)]
data types: move rest of the global variables to control structures
Many of these variables seem to related to printing. One can reasonably
assume the control structure will need to be split to a library and
none-library parts.
Sami Kerola [Sun, 28 Aug 2016 09:51:33 +0000 (10:51 +0100)]
data types: move global data to control structures
This is a big and pretty messy change, but unfortunately there is no nice
way to move variables from global scope to input argument scope. But that
does not explain why this is needed, so let me try to do that.
Variables in global scope make lousy api. In order to separate tracing
functionality from various display interfaces making api cleaner is a must.
Further goal of clean api with aim publishing it as libmtr library. Such
library needs to be fully documented, and it can even provide python
bindings for people and organizations who happen to need such. Please keep
this plan as a git commit log hush-hush secret. It might take more than a
moment to get all the necessary changes done to reach fully working, decent,
understandable, documented library similar to libabc.
Sami Kerola [Mon, 22 Aug 2016 21:40:50 +0000 (22:40 +0100)]
warnings: fix use of uninitialized warning
clang claims: variable 'port' is used uninitialized whenever switch default
is taken. And that is a lie, but error() is not marked as function that
never returns, because it can also be used when printing warning. So the
compiler is guessing wrong, but the easiest fix is to initialize the
variable rather than educate compiler.
Sami Kerola [Sun, 21 Aug 2016 19:33:43 +0000 (20:33 +0100)]
build-sys: tell function locality explicitly
Most of the function prototypes in header files are indeed external, with
few exceptions that can be set to local scope with static key word.
Additionally get rid of net_duplicate() prototype that does not exist
anywhere.
Sami Kerola [Sun, 21 Aug 2016 17:13:53 +0000 (18:13 +0100)]
usage: use error(3) error-reporting function
There are two benefits of using error(3). First of all this function
unifies error printing nice way, and when done this way a programmer cannot
accidentally mix stderr and stdout error print outs. Secondly the error(3)
appends program name to errors, making it clear what printed an error. To
demonstrate this see below for old and new output, in which the old error
could have in theory been reported by sudo(8).
$ sudo mtr -u -T # old
-u , -T and -S are mutually exclusive.
$ sudo ./mtr -u -T # new
./mtr: -u , -T and -S are mutually exclusive
Sami Kerola [Sun, 21 Aug 2016 09:00:11 +0000 (10:00 +0100)]
usage: reflect ./configure choices in available command line options
Features that are turned off should not be available to users as an options.
This commit also ensures matching long and short options, and makes the
long-only --displaymode option to be totally unreachable with short options.
Sami Kerola [Sat, 20 Aug 2016 08:17:06 +0000 (09:17 +0100)]
cleanup: remove obsolete herror() function
Applications should use getaddrinfo(3), getnameinfo(3), and gai_strerror(3)
instead. Systems without getaddrinfo() are from now on considered too
broken to be supported. These include for example platforms: HP-UX 11.11,
IRIX 6.5, OSF/1 5.1, Solaris 7, Cygwin 1.5.x, mingw, MSVC 9, Interix 3.5,
and BeOS.
Sami Kerola [Thu, 18 Aug 2016 21:36:18 +0000 (22:36 +0100)]
cleanup: remove NO_SPLIT preprocessor check
Apparently ./configure --without-split was planned to be added in commit 433bf6c22ce90e25f3ffb0b4852631e5724ac608 but that has not happen in 17
years. Time has come to get rid of a half implemented idea.
The bug in automake does not create a vulnerable distirbution. It
allows local attackers that are logged in (or running in the
background) when a distributer types "make distcheck" to possibly gain
root access on the build system. This is NOT creating a vulnerable
distribution. The fact that automake has a vulnerability does not
warrant build failures on older systems.
Add include <strings.h> to avoid implicit declaration of built-in functions,
replace bzero() with memset(), mark function argument unused, and use %zu to
print size_t data type.
Sami Kerola [Tue, 16 Aug 2016 10:02:43 +0000 (11:02 +0100)]
build-sys: improve configure.am
Unify indentation, use strict quoting, and use appropriate macros. Add few
comments that can be found from ./configure script so that one has some idea
what macros are generating the lines one is looking.
Sami Kerola [Tue, 16 Aug 2016 09:34:01 +0000 (10:34 +0100)]
build-sys: use build version script from gnulib
This makes distribution tar-balls from snapshot to indicate they are
snapshot versions. Additionally the version markup ends up in config.h
correct way, so earlier code that was specific to this project can be
removed.
Sami Kerola [Mon, 15 Aug 2016 20:52:05 +0000 (21:52 +0100)]
warnings: multiply timeval seconds only when the value is small
It should be safe to multiply timeval seconds by million after substracting
sequence timestamp from now. The reason to postpone multiply operation is
to ensure there is smallest possible change for interger overflow to happen.
Sami Kerola [Sun, 14 Aug 2016 20:40:33 +0000 (21:40 +0100)]
cleanup: remove unnecessary null check
The fmt_ipinfo() returns variable from stack. In order a stack variable to
point to NULL there has to go so much things wrong that the program cannot
run - effectively this can happen when system memory is so low that even
global variables cannot be allocated.