1 - small code cleanup, 2 - waittime and first TTL issue

2:
for example:
  mtr -f16 japan-guide.com

In my case,
  numhosts 17 and intervaltime ~60 msec (ping ~150msec in my case)
  but actually hosts 2 only (i.e. intervaltime must be 500 msec).

  In the result the last ping is always -1 ('?' in display mode).
Graph in case unsent packets (saved = -2)
graphcairo readme in brief
TCP mode fails on BSD (and OpenSolaris)

Looks like the same issue:
https://github.com/traviscross/mtr/issues/28
https://bugs.launchpad.net/mtr/+bug/1273486
https://bugs.launchpad.net/mtr/+bug/1327036

 % uname -srm; mtr -r --tcp localhost
 FreeBSD 10.0-RELEASE-p4 amd64
 Start: Fri Jun  6 22:20:00 2014
 bind(): Invalid argument
 %

 % uname -srm; mtr -r --tcp localhost
 NetBSD 6.1.3_PATCH i386
 Start: Fri Jun  6 22:23:13 2014
 bind(): Invalid argument
 %

 % uname -a; % mtr -r --tcp localhost
 SunOS opensolaris 5.11 oi_151a9 i86pc i386 i86pc
 Start: Wed Jun 11 19:49:28 2014
 bind(): Invalid argument
 %

OpenSolaris/OI: compile fails with FIONBIO

Looks like the same issue:
https://github.com/traviscross/mtr/issues/27
https://github.com/traviscross/mtr/issues/35
https://bugs.launchpad.net/mtr/+bug/1273486

 % make
 make  all-recursive
 Making all in img
 depbase=`echo net.o | sed 's|[^/]*$|.deps/&|;s|\.o$||'`;\
 gcc -DHAVE_CONFIG_H  -I.       -g -O2 -Wall -MT net.o -MD -MP -MF $depbase.Tpo -c -o net.o net.c &&\
 mv -f $depbase.Tpo $depbase.Po
 net.c: In function `net_send_tcp':
 net.c:360: error: `FIONBIO' undeclared (first use in this function)
 net.c:360: error: (Each undeclared identifier is reported only once
 net.c:360: error: for each function it appears in.)
 *** Error code 1

fix: #define BSD_COMP
TCP mode: MTR terminated with signal SIGPIPE

Looks like the same issue at the bottom of this report:
https://github.com/traviscross/mtr/issues/28

 % uname -a; ./mtr -rT localhost; echo $?
 Start: Thu Jun 12 17:09:11 2014
 SunOS opensolaris 5.11 oi_151a9 i86pc i386 i86pc
 141

 % uname -srm; ./mtr -4rT localhost; echo $?
 NetBSD 6.1.3_PATCH i386
 Start: Thu Jun 12 16:14:47 2014
 141

 % gdb ./mtr
 (gdb) set args -4rT localhost
 (gdb) r
 Start: Thu Jun 12 16:15:36 2014
 Program received signal SIGPIPE, Broken pipe.
 [Switching to LWP 1]
 0xbb767387 in write () from /usr/lib/libc.so.12

 (gdb) bt
 #0  0xbb767387 in write () from /usr/lib/libc.so.12
 #1  0xbb470263 in write () from /usr/lib/libpthread.so.1
 #2  0x0804fea6 in net_process_fds (writefd=0xbfbfeaac) at net.c:1542
 #3  0x080544a7 in select_loop () at select.c:264
 #4  0x0804d5ee in main (argc=3, argv=0xbfbfec58) at mtr.c:719

 (gdb) list net.c:1541,1543
 1541        if (fd > 0 && FD_ISSET(fd, writefd)) {
 1542          r = write(fd, "G", 1);
 1543          /* if write was successful, or connection refused we have
 (gdb)

fix:
 If the socket is connected, getpeername() will return 0.
 Else getpeername() will return ENOTCONN, and read(,,1) will produce the right errno.
 This is a combination of suggestions from Douglas C. Schmidt and Ken Keys.
Display mode and first TTL issue

for example:

mtr -t -f25 gnail.com

Host                                                            Loss%   Snt   Last   Avg  Best  Wrst StDev
25. 61.49.44.122                                                 11.8%    18  446.5 448.6 446.4 463.4   4.3
26. ???
27. 123.196.119.29                                               11.8%    17  440.2 440.4 439.9 441.0   0.0
28. 219.234.92.18                                                11.8%    17  446.6 453.3 445.9 508.1  18.8
29. 203.158.16.2                                                 12.5%    17  441.9 441.3 441.0 442.0   0.0

after pressing `d' key:
                             Last  78 pings
 1. ???
 2. ???
 3. ???
 4. ???
 5. ???
 6. ???
 7. ???
 8. ???
 9. ???
10. ???
11. ???
12. ???
13. ???
14. ???
15. ???
16. ???
17. ???
18. ???
19. ???
20. ???
21. ???
22. ???
23. ???
24. ???
25. 61.49.44.122                                                         ................................??
26. ???                                                                  ??????????????????????????????????
27. 123.196.119.29                                                       ................................??
28. 219.234.92.18                                                        ....>..................>.......???
29. 203.158.16.2                                                         ...............................???
Scale:  .:441 ms  1:444 ms  2:451 ms  3:459 ms  a:471 ms  b:484 ms  c:500 ms