/*
 *  1/7/92:  Modified to include a new option for MTU discovery.
 *           This option will send out packets with the don't
 *           fragment bit set in order to determine the MTU
 *           of the path being traceroute'd.  Only decreases
 *           in MTU will be detected, and the MTU will initially
 *           be set to the interface MTU which is used for
 *           routing.  In the event of an MTU decrease in the
 *           path, the output will include a message of the
 *           form MTU=#### with the new MTU for the latest
 *           hop.  This option is invoked with "-M".
 *                            Jamshid Mahdavi,   PSC.
 */

/*
 * 4/12/93:  Modified to include new option (-Q) that will report on
 *           percentage packet loss* in addition to the usual
 *           min/avg/max delay.  When -Q is invoked, delay per packet
 *           reporting is turned off.  Also ^C aborts further packets
 *           sent on that ttl and goes on to the next -- two
 *           consecutive ^Cs will terminate the traceroute entirely.
 *           [modified code rom Matt Mathis' uping.c code]
 *                          Jon Boone,  PSC.
 */

/*
 * 4/23/93:  Added support for a "-a" switch which will support
 *           automatic cutoff after a certain number of dropped
 *           packets in a row
 *                          Jon Boone, PSC.
 */

/*
 * 10/21/93: (JM) Fixed SGI version, changed the packet sizing scheme
 *           to a saner system based on total packet size (which
 *           also fixed several bugs in the old code w.r.t.
 *           size of packets).  Added fast timers.  Added network
 *           owner lookup.  Plan to add AS path lookup eventually...
 */

/*
 * 05/20/95: (Ehud Gavron, gavron@aces.com) Added in the following:
 *              1. -A now looks up ASs
 *              2. When nprobes = 1 it doesn't give up after one hop
 *              3. Fixed in-addr searches to try progressively larger blocks
 *                 since MCI's backbone uses one SOA for a 256-class-c block
 *              4. It now works under VMS
 *              5. Miscellaneous casts to make ANSI compilers happy
 *              6. Changes #ifdef'd as MAY95
 */

/*
 * 07/20/95: (Ehud Gavron, gavron@aces.com)
 *           1. Added in a fix to correct for an occasional hang.
 *           2. Fixed minor ANSI compiler things so SunOS likes it
 *
 *           The code, from Steffen Baur (baur@noc.dfn.de) is described by
 *           him as follows.
 *
 *           I've discovered another bug in traceroute. Sometimes traceroute
 *           seem to 'hang' if there's no response for a probe.
 *
 *           The problem is, that all icmp messages (even responses for other
 *           ping or traceroute tasks) are copied to the input socket. After
 *           every receive (even on messages for other tasks), traceroute
 *           waits for another timeout intervall. So, if there is much icmp
 *           traffic on the host, the socket always receives an icmp message
 *           for another task before the timeout occurs.
 *
 *           I introduced a kind of deadline in wait_for_reply().
 */

/*
 * 07/20/95: (Ehud Gavron, gavron@aces.com)
 *              More minor fixes.  Now compiles cleanly on Solaris as well.
 */

/*
 * 09/04/95: (Ehud Gavron, gavron@aces.com)
 *              Now uses VMS command language definition module if available
 *              Cleaned up code a bit...
 */

/*
 * 10/04/95: (Ehud Gavron, gavron@aces.com)
 *              It used to be that everyone only had one RADB entry, so that
 *              finding the AS given the net was easy.
 *              Then it turns out that lots of people now have multiple
 *              entries.
 *
 *              Here's the solution:
 *              1) Use the most specific entries in RADB
 *              2) Where entries are equally specific yet list different
 *                 ASs, list all ASs separated by /.
 *              3) Have a beer
 */

/*
 * 10/15/95: (Ehud Gavron, gavron@aces.com)
 *              1) Joey@teleport.com reports that not terminating reply[]
 *                 is a poor idea ;-)  Corrected.
 *              2) Scott Bradner reports it doesn't work on big-endians.
 *                 Disabled new_packet_ok stuff for now
 *              3) Fixed to use correct offsets.  Removed ntohs() stuff
 *                 since buffer must be in n order (duh).
 *              4) Added in stuff so it will build on Suns without the UCB
 *                 optional compiler /usr/ucb/cc.  (-DSUN_WO_UCB)
 *              5) Added in a diagnostic to check for ip version == 4!
 *              6) Made it work with freebsd by modifying send_probe()
 *                 to fill in ip->ip_v and ip->ip_hl.
 */
/*
 * 11/22/95 Ehud Gavron
 *              bcopy doesn't exist on some systems (Suns without UCB)
 *              but we can't use strncpy since it stops on a 0 byte,
 *              which screws up get_origin since whois.ra.net currently
 *              is blah.blah.0.blah :-)
 */

/*
 * 03/28/96 Ehud Gavron
 *              New Cisco code ignores closely-separated packets that
 *              should generate ICMP errors.  As a result, what used
 *              to be !H !H !H now is !H * !H, and of course delay
 *              stats _to_ a Cisco now show 50% loss.
 *
 *              Modify code to check for unreachable+loss.  This mod
 *              is in under the cisco_icmp ifdef.
 *
 */

/*
 * 12/17/96 Ehud Gavron
 *              If we make the terminator flexible, we can do live HTML
 *              (www.opus1.com/www/traceroute.html) instead of waiting
 *              for the whole thing to be done and then displaying it.
 *              Use -Tterminator in printf() parser format.
 */

/*
 * 01/18/97 Ehud Gavron
 *              MCI administratively prohibits some packets from crossing
 *              routers.  (traceroute www.mci.net).  Check for ICMP type
 *              13 (undefined in include files here :() and display !A
 *
 * 02/11/97     Change random mishmash of printf, Printf, fprintf(stdout,
 *              fprintf(stderr, into consistent usage of err for errors
 *              and verbosity and stdout for everything else.
 */

/*
 * 05/05/98     Ehud Gavron     gavron@aces.com
 *
 *              1) Make SOLARIS a define that automatically sets
 *                 'SUN_WO_UCB' for Sun without UCB compiler addons and
 *                 'POSIX' to fix the bullshit in RESOLV.H (__res_send)
 *
 *              2) Make defines for
 *                 'STRING'  system should use <string.h> not <strings.h>
 *                 'NOINDEX' system should use strchr(), not index()
 *                 'NOBZERO' system should use memset() not bzero, and memcpy()
 *                           not bcopy()
 *
 *              3) Add function prototypes.  They can be removed via
 *                 'NO_PROTOTYPES'
 *
 *              4) Based on Pansiot and Grad's wanting to ignore loss,
 *                 add -U flag.  (/HURRY on VMS).  This one will only
 *                 sit on a hop until it gets a satisfactory response.
 *                 That way hops with loss will get up to -n probes,
 *                 and hops with no loss will get just one.
 *
 *              5) Recoded some passing of parameters to make ansi-compliant
 *                 compilers even happier.
 */

/*
 * 06/30/98     Ehud Gavron     gavron@aces.com
 *
 *              V2.8.1  Added -P  (/PING) to help out sites that are smurf-safe
 *                      by blocking ICMP ECHO reply.
 *                      This will do the same as 1 probe, timeout 3, ttl 64
 *                      and return a status of 1 (success) or 0 (failure)
 */

/*
 * 01/05/1999   Ehud Gavron     gavron@aces.com
 *              V2.8.2  Added in Brian Murphy's linux code.  His comments:
 * 12/31/98 (Brian Murphy, murphy@u.arizona.edu)
 *      Ported to linux.  Tested on Red Hat 5.0 with the 2.1.128 kernel.
 *
 * 01/01/98
 *      Removed trust from getenv() that could lead to a buffer overflow.
 */

/*
 * 01/06/1999   Ehud Gavron     gavron@aces.com
 *              V2.8.3  Added in Craig Watkins <Craig.Watkins@innosoft.com>
 *                      fix to make SolX86 work (missing htons() in ip_len)
 * 01/08/1999   V2.8.4  Added in Richard Irving <rirving@onecall.net> nit-fixes
 *                      to check for null parameters, as well as cast some math
 *                      into proper ints.
 * 02/26/1999   V2.9.0  Craig Watkings suggested sending all probes out at
 *                      once. What a great idea!  -P for parallel probing of
 *                      all TTLs.  Messy on output if we don't want to sit
 *                      and definitely wait it out, but useful!  -$ for the
 *                      old 'ping style' behavior.
 * 02/27/1999   V2.9.1  Allow more than one probe per hop, display last one to
 *                      successfully return.  Fix so all packets returning will
 *                      override the max-wait timer.  Fix so we check the TTL
 *                      and make sure our packets (even out of order) are ok.
 *                      pretty up the output.  Remove magic number "3" for
 *                      ICMP_UNREACH_PORT.
 * 03/01/1999   V2.9.2  Freebsd seems to get packets that generate indices
 *                      which are outside the array (line 1299).  This segfault
 *                      is corrected by a bounds check on line 1298.
 * 03/03/1999   V2.9.3  Make printing the header and time difference standard
 *                      callable routines (print_from, print_time).  Make the
 *                      last address be a struct sockaddr_in instead of u_long
 *                      since that's the right way to do it.  Make the code
 *                      in packet_ok() and send_probe() conditional on spray
 *                      mode so we don't jabber all over the data cells!
 * 09/30/1999   V2.9.4  Added "FORCE_NATURAL_MASK" in lookup_as() so that if
 *                      necessary, old-style lookups would still work.  Now,
 *                      the -A option will use the address as is.
 * 11/15/1999   V6.0    Renumber to Version 6.0 and rename to TrACESroute
 *                      to avoid 'confusion' with vj/lbl traceroute 2.9.x.
 *                      Of course this makes us much more advanced than
 *                      Netscape 4.8, I.E. 5.0, or The New AOL 5.0. ;-)
 * 01/18/2000   V6.1    Dan Cohn <dan@internap.com> provided mods to make
 *                      spray mode as functional as normal mode, both in
 *                      terms of missing packets and in multiple probes.
 * 04/29/2000   V6.1.1  As per Thomas Erskine, add info for -A where the
 *                      route is not in the RR server queried.
 *
 * 06/05/2001   V6.1.2  When using -A, get_origin() returns 0 for ASs not
 *                      found in your particular RA_SERVER.  This, passed
 *                      to printf(%s) ended up as <Null> on Linux, and a
 *                      coredump on Solaris... fixed by adding a nullstring
 *                      <NONE> and checking for zero result from get_origin.
 *                      Thanks to Richard Wright for pointing it out and
 *                      assisting in the debug.
 * 06/16/2001   emf_prototrace 0.2
 *                      Added rudimentary support for generic protocol type
 *                      scan via -I option.  It's really really rough right
 *                      now, but it gives me enough ammunition to tell
 *                      some feeb where my packets are stopping.   I
 *                      generally use this with -I 50 to check for IPSec
 *                      VPN functionality.  (You'd be completely amazed at
 *                      how many people claim their firewall isn't
 *                      interfering with their VPN clients. Sheesh)
 *
 * 10/27/2001   V6.1.3  Disallow max_ttl*nprobes>spraymax. Raise spraymax.
 *
 * 02/05/2002	V6.1.4	Simon Leinen <simon@limmat.switch.ch> provided some
 *			nice code to check TOS changes in the encapsulated
 *			header from its original value ... use -t TOS to set.
 * 04/12/2002           Updated comment above
 *
 * 07/23/2002   V6.2.0  Various sources report that the -T terminator can
 *                      be exploited to run malicious code.  This is due
 *                      to sloppy coding on my part when writing it.
 *                      Fixed. In this version FIXT defines that code, and
 *                      assuming it works everywhere, will be mainline code
 *                      in the next minor release.
 *
 * 10/12/2002   V6.2.1  Daniel Kobras reports a slew of poor coding on
 *   			my part in get_origin(), as well as included Colin
 *    			Phipps code in one nice easy fun patch.  Better
 *			code for better living!
 *
 * 11/28/2002	V6.2.2  Benjamin Zwittnig from ARNES provided more fine
 *                      tuning of the accept logic on incoming ICMP packets
 *                      which reduces false results on machines with high
 *                      received ICMP traffic.  Patch submitted by Simon 
 *  			Leinen at Switch.
 *
 * 02/11/2003	V6.3.0	Three changes.  First, Martin Godisch's patches
 *    			to allow this to run under Debian.  Second, 
 *			Graeme Hewson's patches to fix ICMP traceroute,
 *			and clean up preprocessor inefficiency. Finally,
 *			add Terry Kennedy's fixes for broken raw ip.
 * 
 * 02/24/2003	V6.3.2  Make MTU discovery work the RFC 1191 way.  Also
 *                      make MTU discovery work on little endian machines.
 *                      Also makes -U actually terminate faster.
 *                      Code from and kudos to Graeme Hewson @oracle.com
 *
 * 03/10/2003	V6.3.3	Decode ICMP extension headers as per Jorge Boncompte,
 *			who even supplied the decoding routine!
 *
 * 03/21/2003	V6.3.4	Jorge fixed the decoding for nonzero headers
 *
 * 03/31/2003	V6.3.5	Graeme provided misc bugfixes -- THANKS!!!
 *
 *
 * 05/22/2003	V6.3.6	Marco Steinacher points out some RAs delimit data 
 *			with tabs (0x09) instead of spaces (0x20).  Fixed
 *			get_origin ASN lookup code to also check for tabs.
 *
 * 07/07/2003	V6.3.7	Martin Godisch fixed automatic mode.
 *
 * 07/11/2003	V6.3.8	Martin Godisch provided a fix for Debian bug report
 *			200875 (Integer overflow).
 *
 * 07/15/2003	V6.3.9	Matt Zimmerman <mdz@debian.org> provided bugfixes
 *			for same in Spray mode and other enhancements. 
 *
 * 12/05/2003   V6.3.10 Colin Gibbs reports bad padding between IP and UDPHDR
 *                      is causing unpredictable results.  He suggests fix.
 *
 * 11/06/2005   V6.4.0  Georg Schwarz provided more bugfixes for sloppy code.
 *
 * 12/16/2005   V6.4.1  Added bounds checking on min_ttl and max_ttl
 *
 * 06/06/2006   V6.4.2  Changed nprobes to not be limited to SPRAYMAX if not
 *                      running in parallel mode, and prevent parallel mode
 *                      where nprobes >=SPRAYMAX with a warning to the user.
 */
