diff -c traceroute-951024/Makefile.ORG traceroute-951024/Makefile
*** traceroute-951024/Makefile.ORG	Wed Oct 25 07:55:43 1995
--- traceroute-951024/Makefile	Fri May 10 13:23:59 1996
***************
*** 23,29 ****
  #endif
   
  #if defined(solaris) && You do not want to use BSD compatibility mode
! SYSDEFS = -DSYSV
  #endif
   
  #if defined(solaris) && You are using its default broken resolver library
--- 23,29 ----
  #endif
   
  #if defined(solaris) && You do not want to use BSD compatibility mode
! SYSDEFS = -DSVR4
  #endif
   
  #if defined(solaris) && You are using its default broken resolver library
***************
*** 34,41 ****
  SYSDEFS = -DSOLARIS
  #endif
  
! SYSDEFS =
  
  # ----------------------------------------------------------------------
  # Configuration definitions.
  # See also conf.h and aslookup.h for more configuration definitions.
--- 34,45 ----
  SYSDEFS = -DSOLARIS
  #endif
  
! #if you are not using libresolv.a
! SYSDEFS = -DNO_RESOLV
! #endif
  
+ SYSDEFS = -DSVR4
+ 
  # ----------------------------------------------------------------------
  # Configuration definitions.
  # See also conf.h and aslookup.h for more configuration definitions.
***************
*** 87,92 ****
--- 91,98 ----
  # ----------------------------------------------------------------------
  
  RES = ../res/libresolv.a
+ RES =					# if you define NO_RESOLV
+ RES =					# for IRIX 5.x
  RES = -lresolv
  
  COMPLIB = ../compat/lib/lib44bsd.a
***************
*** 94,100 ****
  COMPLIB =
  
  LIBS = -lsocket -lnsl			#if defined(solaris) && not BSD
! LIBS =
  
  LIBRARIES = $(RES) $(COMPLIB) $(LIBS)
  
--- 100,107 ----
  COMPLIB =
  
  LIBS = -lsocket -lnsl			#if defined(solaris) && not BSD
! LIBS =					# for IRIX 5.x
! LIBS = -lsocket -lnsl			# for SVR4 based os
  
  LIBRARIES = $(RES) $(COMPLIB) $(LIBS)
  
***************
*** 107,112 ****
--- 114,120 ----
  MAKE = make $(MFLAGS)
  
  # This assumes the BSD install.
+ INSTALL = /usr/ucb/install -c		# for SunOS 5.x (aka Soalris 2.x)
  INSTALL = install -c
  
  # Grrr
***************
*** 147,153 ****
  	$(CC) $(LDFLAGS) -o $(PROG) $(OBJS) $(LIBRARIES)
  
  install: $(PROG)
! 	$(INSTALL) -m 4755 -o root -g network -s $(PROG) $(BINDIR)
  
  man: $(MANS)
  	$(INSTALL) -m 444 traceroute.8 $(MANDIR)
--- 155,161 ----
  	$(CC) $(LDFLAGS) -o $(PROG) $(OBJS) $(LIBRARIES)
  
  install: $(PROG)
! 	$(INSTALL) -m 4755 -o root -g bin -s $(PROG) $(BINDIR)
  
  man: $(MANS)
  	$(INSTALL) -m 444 traceroute.8 $(MANDIR)
diff -c traceroute-951024/README.SVR4.ORG traceroute-951024/README.SVR4
*** traceroute-951024/README.SVR4.ORG	Tue Jan  9 10:56:30 1996
--- traceroute-951024/README.SVR4	Mon Aug  4 10:32:10 1997
***************
*** 0 ****
--- 1,25 ----
+ 
+ This is a patched version of traceroute (ver. 951024) for SVR4 based
+ machines. 
+ 
+ Please set SYSDEFS, RES and LIBS in ./Makefile appropriately.
+ 
+   OS 			Make option
+   --------------------  -------------------
+   SUN SunOS 5.[34]     	SYSDEFS="-DSVR4 -DNO_RAW_IP"
+   SONY NEWS-OS 6.1	SYSDEFS="-DSVR4 -DBIND_RECV_SOCK -DSHORT_IPOPT_LEN"
+   NEC EWS-UX/V Rel.4.2	SYSDEFS="-DSVR4 -DBIND_RECV_SOCK -DSHORT_IPOPT_LEN"
+   SGI IRIX 5.[23]	SYSDEFS=-DSVR4 RES= LIBS=
+ 
+ The proper SYSDEFS is supposed to be automatically figured out by port.h.
+ 
+ 						    January 9, 1996
+ 
+ Changes:
+     Buffer overrun vulnerability related to gethostbyaddr and
+     getnetbyaddr fixed.
+ 
+ 						    August 4, 1997
+ 
+ 			Hiroshi Nakano <nakano@rins.ryukoku.ac.jp>
+ 			Ryukoku Univ., Seta, Otsu, Japan
diff -c traceroute-951024/aslookup.c.ORG traceroute-951024/aslookup.c
*** traceroute-951024/aslookup.c.ORG	Sun Oct  8 07:14:38 1995
--- traceroute-951024/aslookup.c	Mon Aug  4 09:52:04 1997
***************
*** 733,740 ****
  		naddrs = 1;
  
  		hp = gethostbyaddr((char *)&inaddr[0], INADDRSZ, AF_INET);
! 		if (hp != NULL)
! 			host = strcpy(hostbuf, hp->h_name);
  	}
  
  /*
--- 733,742 ----
  		naddrs = 1;
  
  		hp = gethostbyaddr((char *)&inaddr[0], INADDRSZ, AF_INET);
! 		if (hp != NULL) {
! 			host = strncpy(hostbuf, hp->h_name, sizeof(hostbuf));
! 			hostbuf[sizeof(hostbuf)-1] = '\0';
! 		}
  	}
  
  /*
***************
*** 754,760 ****
  
  		printf("%s (%s)", host, inet_ntoa(inaddr[i]));
  		if (np != NULL)
! 			printf(" (%s)", np->n_name);
  		if (asnumber != NULL)
  			printf(" [%s]", asnumber);
  		printf("\n");
--- 756,762 ----
  
  		printf("%s (%s)", host, inet_ntoa(inaddr[i]));
  		if (np != NULL)
! 			printf(" (%.256s)", np->n_name);
  		if (asnumber != NULL)
  			printf(" [%s]", asnumber);
  		printf("\n");
diff -c traceroute-951024/port.h.ORG traceroute-951024/port.h
*** traceroute-951024/port.h.ORG	Sun Oct  8 07:28:40 1995
--- traceroute-951024/port.h	Tue Jan  9 10:52:30 1996
***************
*** 4,9 ****
--- 4,17 ----
  **	@(#)port.h              e07@nikhef.nl (Eric Wassenaar) 951007
  */
  
+ #if !defined(SVR4) && (defined(__svr4) || defined(__svr4__) || defined(__SVR4) || defined(_SYSTYPE_SVR4))
+ #define SVR4
+ #endif
+ 
+ #if !defined(SYSV) && defined(SVR4)
+ #define SYSV
+ #endif
+ 
  #if defined(SYSV) || defined(SVR4)
  #define SYSV_MEMSET
  #define SYSV_STRCHR
***************
*** 28,45 ****
  ** For systems that do not support IPPROTO_RAW manipulation.
  */
  
  #if defined(__hpux) || defined(hpux)
  #define NO_RAW_IP
  #endif
  
  /*
  ** On some platforms IP_HDRINCL interferes with LSRR options.
  */
  
! #if defined(NO_RAW_IP) || defined(sgi)
  #undef IP_HDRINCL
  #endif
  
  /*
  ** On some platforms a raw IP packet must be in network byte order.
  **
--- 36,93 ----
  ** For systems that do not support IPPROTO_RAW manipulation.
  */
  
+ #ifndef NO_RAW_IP
+ 
  #if defined(__hpux) || defined(hpux)
  #define NO_RAW_IP
  #endif
  
+ #if defined(SYSV) && (defined(sun) || defined(__sun) || defined(__sun__))
+ #define NO_RAW_IP
+ #endif
+ 
+ #endif /*NO_RAW_IP*/
+ 
  /*
  ** On some platforms IP_HDRINCL interferes with LSRR options.
  */
  
! #if defined(NO_RAW_IP) || defined(sgi) || defined(__sgi)
  #undef IP_HDRINCL
  #endif
  
+ #if defined(nec_ews_svr4) || defined(_nec_ews_svr4)
+ #undef IP_HDRINCL
+ #endif
+ 
+ /*
+ ** On some platforms IP_OPTIONS length must be shorter.
+ */
+ 
+ #ifndef SHORT_IPOPT_LEN
+ 
+ #if defined(SVR4) && (defined(sony_news) || defined(__sony_news))
+ #define SHORT_IPOPT_LEN
+ #endif
+ 
+ #if defined(nec_ews_svr4) || defined(_nec_ews_svr4)
+ #define SHORT_IPOPT_LEN
+ #endif
+ 
+ #endif /*SHORT_IPOPT_LEN*/
+ 
+ /*
+ ** On some platforms we must bind recvsock.
+ */
+ 
+ #if defined(SVR4) && (defined(sony_news) || defined(__sony_news))
+ #define BIND_RECV_SOCK
+ #endif
+ 
+ #if defined(nec_ews_svr4) || defined(_nec_ews_svr4)
+ #define BIND_RECV_SOCK
+ #endif
+ 
  /*
  ** On some platforms a raw IP packet must be in network byte order.
  **
diff -c traceroute-951024/traceroute.c.ORG traceroute-951024/traceroute.c
*** traceroute-951024/traceroute.c.ORG	Wed Oct 18 06:03:44 1995
--- traceroute-951024/traceroute.c	Mon Aug  4 10:00:40 1997
***************
*** 261,269 ****
--- 261,275 ----
  #include <netinet/ip_icmp.h>
  #include <netinet/udp.h>
  
+ #if (defined(mips) || defined(_mips)) && (defined(nec_ews_svr4) || defined(_nec_ews_svr4))
+ #define BIT_ZERO_ON_LEFT	/* used in <arpa/nameser.h> */
+ #endif
+ 
  #undef NOERROR			/* in <sys/streams.h> on solaris 2.x */
+ #ifndef NO_RESOLV
  #include <arpa/nameser.h>
  #include <resolv.h>
+ #endif
  
  #include "port.h"		/* various portability definitions */
  #include "conf.h"		/* various configuration definitions */
***************
*** 362,369 ****
  int nprobes = 3;		/* -q  number of probe packets to send */
  int maxquit = 5;		/* -Q  quit after this consecutive timeouts */
  
! int waitsecs = 3;		/* -w  time to wait for response (seconds) */
! int stopsecs = 0;		/* -c  time to wait between probes (seconds) */
  bool verbose = FALSE;		/* -v  print additional information */
  bool numeric = FALSE;		/* -n  print addresses numerically */
  bool ttlflag = FALSE;		/* -l  print ttl values */
--- 368,375 ----
  int nprobes = 3;		/* -q  number of probe packets to send */
  int maxquit = 5;		/* -Q  quit after this consecutive timeouts */
  
! int waitmsecs = 3000;		/* -w*1000 time to wait for response (msec) */
! int stopmsecs = 0;		/* -c*1000 time to wait between probes (msec) */
  bool verbose = FALSE;		/* -v  print additional information */
  bool numeric = FALSE;		/* -n  print addresses numerically */
  bool ttlflag = FALSE;		/* -l  print ttl values */
***************
*** 446,458 ****
--- 452,474 ----
  #define assert(condition)
  #endif
  
+ #ifdef NO_RAW_IP
  char Usage[] =
  "\
  Usage: %s [-g gateway] [-m maxhops] [-q nqueries] host [packetsize]\n\
+ Flags: [-a] [-i initial_ttl] [-l] [-n] [-Q maxquit] [-r] [-S] [-v]\n\
+ Other: [-c stoptime] [-p port] [-s source_addr] [-t tos] [-w waittime]\n\
+ ASnum: [-A] [-h server] [-k] [-N]\
+ ";
+ #else
+ char Usage[] =
+ "\
+ Usage: %s [-g gateway] [-m maxhops] [-q nqueries] host [packetsize]\n\
  Flags: [-a] [-f] [-i initial_ttl] [-l] [-n] [-Q maxquit] [-r] [-S] [-v]\n\
  Other: [-c stoptime] [-p port] [-s source_addr] [-t tos] [-w waittime]\n\
  ASnum: [-A] [-h server] [-k] [-N]\
  ";
+ #endif /*NO_RAW_IP*/
  
  /*
  ** MAIN -- Start of program traceroute
***************
*** 489,498 ****
--- 505,516 ----
   */
  	linebufmode(stdout);
  
+ #ifndef NO_RESOLV
  /*
   * Initialize resolver. Shorter timeout values are set later.
   */
  	(void) res_init();
+ #endif
  
  /*
   * Check command line options.
***************
*** 530,536 ****
  
  		    case 'c':
  			/* time to delay between probes to cisco */
! 			stopsecs = getval(argv[2], "stoptime value", 0, MAXSECS);
  			argc--, argv++;
  			break;
  
--- 548,555 ----
  
  		    case 'c':
  			/* time to delay between probes to cisco */
! 			stopmsecs
! 			    = getmsec(argv[2], "stoptime value", 0, MAXSECS);
  			argc--, argv++;
  			break;
  
***************
*** 539,549 ****
  			sockopts |= SO_DEBUG;
  			break;
  
  		    case 'f':
  			/* prevent fragmentation */
  			dontfrag = IP_DF;
  			break;
! 
  		    case 'g':
  			/* loose source route gateway address */
  			if (argv[2] == NULL || argv[2][0] == '-')
--- 558,569 ----
  			sockopts |= SO_DEBUG;
  			break;
  
+ #ifndef NO_RAW_IP
  		    case 'f':
  			/* prevent fragmentation */
  			dontfrag = IP_DF;
  			break;
! #endif
  		    case 'g':
  			/* loose source route gateway address */
  			if (argv[2] == NULL || argv[2][0] == '-')
***************
*** 644,650 ****
  
  		    case 'w':
  			/* timeout to wait for replies */
! 			waitsecs = getval(argv[2], "waittime value", 1, MAXSECS);
  			argc--, argv++;
  			break;
  
--- 664,671 ----
  
  		    case 'w':
  			/* timeout to wait for replies */
! 			   waitmsecs
! 			       = getmsec(argv[2], "waittime value", 1, MAXSECS);
  			argc--, argv++;
  			break;
  
***************
*** 679,685 ****
  			exit(EX_NOHOST);
  		}
  
! 		hostname = strcpy(hostnamebuf, hp->h_name);
  		for (i = 0; i < MAXADDRS && hp->h_addr_list[i]; i++)
  		{
  			bcopy(hp->h_addr_list[i], (char *)&inaddr, INADDRSZ);
--- 700,708 ----
  			exit(EX_NOHOST);
  		}
  
! 		hostname = strncpy(hostnamebuf, hp->h_name,
! 				   sizeof(hostnamebuf));
! 		hostnamebuf[sizeof(hostnamebuf)-1] = '\0';
  		for (i = 0; i < MAXADDRS && hp->h_addr_list[i]; i++)
  		{
  			bcopy(hp->h_addr_list[i], (char *)&inaddr, INADDRSZ);
***************
*** 694,702 ****
  		else
  			hp = gethostbyaddr((char *)&inaddr, INADDRSZ, AF_INET);
  		if (hp != NULL)
! 			hostname = strcpy(hostnamebuf, hp->h_name);
  		else
! 			hostname = strcpy(hostnamebuf, hostname);
  		hostaddr[0] = addr;
  		naddrs = 1;
  	}
--- 717,728 ----
  		else
  			hp = gethostbyaddr((char *)&inaddr, INADDRSZ, AF_INET);
  		if (hp != NULL)
! 			hostname = strncpy(hostnamebuf, hp->h_name,
! 					   sizeof(hostnamebuf));
  		else
! 			hostname = strncpy(hostnamebuf, hostname,
! 					   sizeof(hostnamebuf));
! 		hostnamebuf[sizeof(hostnamebuf)-1] = '\0';
  		hostaddr[0] = addr;
  		naddrs = 1;
  	}
***************
*** 721,729 ****
--- 747,757 ----
  	if (((int)port + ((max_ttl - min_ttl + 1)*nprobes)) > MAXINT16)
  		fatal("Destination port value overflow");
  
+ #ifndef NO_RESOLV
  	/* set shorter nameserver timeout */
  	_res.retry = 2;		/* number  of retries, default = 4 */
  	_res.retrans = 3;	/* timeout in seconds, default = 5 or 6 */
+ #endif
  
  /*
   * Allocate IP output socket and ICMP input socket.
***************
*** 922,927 ****
--- 950,989 ----
  	return(optvalue);
  }
  
+ int
+ getmsec(optstring, optname, minvalue, maxvalue)
+ char *optstring;			/* parameter from command line */
+ char *optname;				/* descriptive name of option */
+ int minvalue;				/* minimum value for option */
+ int maxvalue;				/* maximum value for option */
+ {
+ 	EXTERN double atof();
+ 	double optvalue;
+ 
+ 	if (optstring == NULL || optstring[0] == '-')
+ 		fatal("Missing %s", optname);
+ 	optvalue = atof(optstring);
+ 	if (optvalue == 0.0 && optstring[0] != '0')
+ 		fatal("Invalid %s %s", optname, optstring);
+ 	if (optvalue < minvalue)
+ 		fatal("Minimum %s %s", optname, itoa(minvalue));
+ 	if (maxvalue > 0 && optvalue > maxvalue)
+ 		fatal("Maximum %s %s", optname, itoa(maxvalue));
+ 	return (int)(1000.0 * optvalue);
+ }
+ 
+ void
+ msleep(msec)
+ unsigned msec;
+ {
+ 	struct timeval w;
+ 
+ 	w.tv_sec = msec / 1000;
+ 	w.tv_usec = msec % 1000 * 1000;
+ 
+ 	(void) select (0, (fd_set *)0, (fd_set *)0, (fd_set *)0, &w);
+ }
+ 
  /*
  ** FATAL -- Abort program when illegal option encountered
  ** ------------------------------------------------------
***************
*** 1068,1073 ****
--- 1130,1149 ----
  		(void) setsockopt(recvsock, SOL_SOCKET, SO_DONTROUTE,
  			(char *)&on, sizeof(on));
  
+ #ifdef BIND_RECV_SOCK
+ 	{
+ 		bzero((char *)me, sizeof(struct sockaddr_in));
+ 		me->sin_family = AF_INET;
+ 		me->sin_addr.s_addr = INADDR_ANY;
+ 		me->sin_port = 0;
+ 
+ 		if (bind(recvsock, (struct sockaddr *)me,
+ 		    sizeof(struct sockaddr_in)) < 0) {
+ 			perror("bind");
+ 			exit(EX_OSERR);
+ 		}
+ 	}
+ #endif
  /*
   * Allocate output socket to send probe packets.
   */
***************
*** 1100,1107 ****
  	if (setsockopt(sendsock, IPPROTO_IP, IP_HDRINCL,
  		(char *)&on, sizeof(on)) < 0)
  	{
! 		perror("setsockopt: IP_HDRINCL");
! 		exit(EX_OSERR);
  	}
  #endif
  
--- 1176,1183 ----
  	if (setsockopt(sendsock, IPPROTO_IP, IP_HDRINCL,
  		(char *)&on, sizeof(on)) < 0)
  	{
! 	    perror("setsockopt: IP_HDRINCL");
! 	    exit(EX_OSERR);
  	}
  #endif
  
***************
*** 1177,1185 ****
--- 1253,1263 ----
  	optbuf = ipoptbuf;
  	optlen = ipopt - ipoptbuf;
  
+ #ifndef SHORT_IPOPT_LEN
  	/* to keep certain platforms happy */
  	if (optlen < sizeof(ipoptbuf))
  		optlen = sizeof(ipoptbuf);
+ #endif
  
  /*
   * Announce the use of the ip options. They will be automatically
***************
*** 1292,1299 ****
  			struct timeval waittime, nexttime;
  
  			/* initialize maximum timeout */
! 			waittime.tv_sec = waitsecs;
! 			waittime.tv_usec = 0;
  
  		/*
  		 * Send probe packet. Decrease packet size if it is too long.
--- 1370,1377 ----
  			struct timeval waittime, nexttime;
  
  			/* initialize maximum timeout */
! 			waittime.tv_sec = waitmsecs / 1000;
! 			waittime.tv_usec = waitmsecs % 1000;
  
  		/*
  		 * Send probe packet. Decrease packet size if it is too long.
***************
*** 1468,1475 ****
  			(void) fflush(stdout);
  
  			/* optionally pause between probes */
! 			if (stopsecs != 0)
! 				(void) sleep((unsigned)stopsecs);
  
  		} /* for probe < nprobes */
  
--- 1546,1553 ----
  			(void) fflush(stdout);
  
  			/* optionally pause between probes */
! 			if (stopmsecs != 0)
! 				msleep((unsigned)stopmsecs);
  
  		} /* for probe < nprobes */
  
***************
*** 1968,1974 ****
  		np = getnetbyaddr(inet_netof(inaddr), AF_INET);
  
  	if (np != NULL)
! 		printf(" (%s)", np->n_name);
  
  	if (lookupas)
  	{
--- 2046,2052 ----
  		np = getnetbyaddr(inet_netof(inaddr), AF_INET);
  
  	if (np != NULL)
! 		printf(" (%.256s)", np->n_name);
  
  	if (lookupas)
  	{
***************
*** 2014,2022 ****
   * Construct the proper address representation.
   */
  	if (hp != NULL)
! 		(void) strcpy(buf, hp->h_name);
  	else
! 		(void) strcpy(buf, inet_ntoa(inaddr));
  	return(buf);
  }
  
--- 2092,2101 ----
   * Construct the proper address representation.
   */
  	if (hp != NULL)
! 		(void) strncpy(buf, hp->h_name, sizeof(buf));
  	else
! 		(void) strncpy(buf, inet_ntoa(inaddr), sizeof(buf));
! 	buf[sizeof(buf)-1] = '\0';
  	return(buf);
  }
  
***************
*** 2069,2075 ****
  			hp = gethostbyaddr((char *)&inaddr, INADDRSZ, AF_INET);
  		if (hp != NULL)
  		{
! 			host = strcpy(hostbuf, hp->h_name);
  			hp = gethostbyname(host);
  		}
  	}
--- 2148,2155 ----
  			hp = gethostbyaddr((char *)&inaddr, INADDRSZ, AF_INET);
  		if (hp != NULL)
  		{
! 			host = strncpy(hostbuf, hp->h_name, sizeof(hostbuf));
! 			hostbuf[sizeof(hostbuf)-1] = '\0';
  			hp = gethostbyname(host);
  		}
  	}
