From paul@wau.mis.ah.nl  Tue Jan 12 03:27:14 1999
Return-Path: <paul@wau.mis.ah.nl>
Received: from janux.wau.mis.ah.nl (mail@ahwau.xs4all.nl [194.109.102.29])
	by uno.slctech.org (8.9.0/8.9.0) with ESMTP id DAA25111
	for <mackay@uno.slctech.org>; Tue, 12 Jan 1999 03:27:10 -0500
Received: from paul by janux.wau.mis.ah.nl with local (Exim 2.02 #1 (Debian))
	id 0zzz5t-000839-00; Tue, 12 Jan 1999 09:22:33 +0100
Date: Tue, 12 Jan 1999 09:22:33 +0100
From: Paul Slootman <paul@debian.org>
To: mackay@uno.slctech.org
Subject: netwatch 0.8a 64-bit patches
Message-ID: <19990112092232.A30917@janux>
Mime-Version: 1.0
Content-Type: multipart/mixed; boundary="J2SCkAp4GZ/dPZZf"
X-Mailer: Mutt 0.94.15i
Sender: Paul Slootman <paul@wau.mis.ah.nl>
Status: RO
X-Status: 


--J2SCkAp4GZ/dPZZf
Content-Type: text/plain; charset=us-ascii

I went ahead and fixed netwatch for the Alpha. I've also just verified
that this still works on i386 as well.  I've also made some other fixes
to ensure a clean compile (missing include files, unused variables).

Please look the patch over and and it to the mainstream distribution;
64 bit platforms are becoming more and more popular!

Thanks,
Paul Slootman
-- 
home: paul@wurtel.demon.nl | work: paul@murphy.nl | debian: paul@debian.org
http://www.wurtel.demon.nl | Murphy Software,   Enschede,   the Netherlands

--J2SCkAp4GZ/dPZZf
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment; filename="netwatch.diff"

diff -ru netwatch0.8a/dispdata.c netwatch0.8a.64bitclean/dispdata.c
--- netwatch0.8a/dispdata.c	Sun Oct 18 03:04:09 1998
+++ netwatch0.8a.64bitclean/dispdata.c	Mon Jan 11 21:07:21 1999
@@ -25,6 +25,8 @@
 
 #include <signal.h>
 #include <unistd.h>
+#include <string.h>
+#include <ctype.h>
 
 #define MAXREFRESH 15
 #define ROUTERSTATSMAX 60
@@ -83,12 +85,12 @@
 extern int magnaoffs;
 extern char magnamatch[RESOLVE_MAX];
 extern HOSTINFO *magnaspot;
-extern unsigned long int magnakey;
+extern u_int32_t magnakey;
 extern int magnaphys;
 extern int magnafirst;
 extern int magnafull;
 extern HOSTINFO *magnacomhost;
-extern unsigned long int magnacomkey;
+extern u_int32_t magnacomkey;
 
 
 unsigned char *ttp;
@@ -198,7 +200,6 @@
   static unsigned long int use;
   double fuse;
   extern unsigned long int routeruse;
-  extern int bugfix;
 
   int lcnt = 0;
   int rcnt = 0;
@@ -210,7 +211,6 @@
   unsigned char *pc;
   extern int help;
   extern int watch;
-  extern int wai;
   extern int llockout;
   extern int rlockout;
   extern int lydisp;
@@ -227,8 +227,6 @@
   extern unsigned long routeruse;
   static unsigned long orouterto = 0;
   static unsigned long orouterfrom = 0;
-  static unsigned long orouteruse = 0;
-  unsigned long wrouteto, wroutefrom, wrouteuse;
   int localbypass = FALSE;
   int remotebypass = FALSE;
   time_t mnew;
@@ -656,11 +654,11 @@
 		  strncpy (thost, current->name, curshosttrim);
 		  if (selectchange && selecthost && numselect + 4 == yact)
 		    {
-		      magnakey = *((unsigned long *) current->addr);
+		      magnakey = *((u_int32_t *) current->addr);
 		      strncpy (magnamatch, current->name, RESOLVE_MAX);
 		      magnaspot = current;
 		      magnacomhost = NULL;
-		      magnacomkey = *((unsigned long *) current->othaddr);
+		      magnacomkey = *((u_int32_t *) current->othaddr);
 		      magnafirst = TRUE;
 		      selectchange = FALSE;
 		    }
@@ -694,15 +692,15 @@
 		  switch (dispopt)
 		    {
 		    case DISP_TX_RC:
-		      sprintf (ttt, "%*s %6d %6d", -curshosttrim - 1, thost,
+		      sprintf (ttt, "%*s %6ld %6ld", -curshosttrim - 1, thost,
 			       current->pktcntsend, current->pktcntrec);
 		      break;
 		    case DISP_INTTXRCP:
-		      sprintf (ttt, "%*s %6d %6d", -curshosttrim - 1, thost,
+		      sprintf (ttt, "%*s %6ld %6ld", -curshosttrim - 1, thost,
 			     current->intpktcntsend, current->intpktcntrec);
 		      break;
 		    case DISP_EXTTXRCP:
-		      sprintf (ttt, "%*s %6d %6d", -curshosttrim - 1, thost,
+		      sprintf (ttt, "%*s %6ld %6ld", -curshosttrim - 1, thost,
 			     current->extpktcntsend, current->extpktcntrec);
 		      break;
 		    case DISP_IPPROTO:
@@ -852,11 +850,11 @@
 		  strncpy (thost, current->name, curshosttrim);
 		  if (selectchange && selecthost && numselect + 4 == yact)
 		    {
-		      magnakey = *((unsigned long *) current->addr);
+		      magnakey = *((u_int32_t *) current->addr);
 		      strncpy (magnamatch, current->name, RESOLVE_MAX);
 		      magnaspot = current;
 		      magnacomhost = NULL;
-		      magnacomkey = *((unsigned long *) current->othaddr);
+		      magnacomkey = *((u_int32_t *) current->othaddr);
 		      magnafirst = TRUE;
 		      selectchange = FALSE;
 		    }
@@ -895,7 +893,7 @@
 		    case DISP_TX_RC:
 		    case DISP_INTTXRCP:
 		    case DISP_EXTTXRCP:
-		      sprintf (ttt, "%*s %6d %6d", -curshosttrim - 1, thost,
+		      sprintf (ttt, "%*s %6ld %6ld", -curshosttrim - 1, thost,
 			       current->pktcntsend, current->pktcntrec);
 		      break;
 		    case DISP_IPPROTO:
diff -ru netwatch0.8a/gh.c netwatch0.8a.64bitclean/gh.c
--- netwatch0.8a/gh.c	Tue Oct 20 03:10:13 1998
+++ netwatch0.8a.64bitclean/gh.c	Mon Jan 11 21:19:30 1999
@@ -18,7 +18,9 @@
 #endif
 #include <netdb.h>
 #include <stdio.h>
+#include <unistd.h>
 #include <stdlib.h>
+#include <string.h>
 
 #define MAGIC_PORT 20200
 
@@ -45,7 +47,6 @@
   FILE *pp;
   int i;
   struct sockaddr_in name;
-  struct hostent *hp, *gethostbyaddr ();
   struct hostent *mh;
   char maddr[40];
   char saddr[256];
diff -ru netwatch0.8a/netresolv.c netwatch0.8a.64bitclean/netresolv.c
--- netwatch0.8a/netresolv.c	Sun Oct 18 03:04:09 1998
+++ netwatch0.8a.64bitclean/netresolv.c	Mon Jan 11 21:20:40 1999
@@ -1,5 +1,11 @@
 #include "config.h"
+#include <unistd.h>
+#include <stdlib.h>
+#include <string.h>
 #include <stdio.h>
+#ifdef NETINET_SUPP_in
+#include <netinet/in.h>
+#endif
 #include <netdb.h>
 #include <setjmp.h>
 #include <fcntl.h>
@@ -62,7 +68,7 @@
 #define MAXENTRIES 400
 struct resolvaddr entries[MAXENTRIES];
 
-char *dbgaddr(unsigned long val)
+char *dbgaddr(u_int32_t val)
 {
 	unsigned char *p;
 	static char buf[40];  /* Worst case scenario for %u conversions */
@@ -79,7 +85,7 @@
 	fprintf(dfp,"Adding entry...netresolv... \n");
 	fflush(dfp);
 #endif
-	place = (struct nqueue *)malloc(sizeof(*place));
+	place = malloc(sizeof(*place));
 	place->resentry = *entry;
 #ifdef DEBUG
 	fprintf(dfp,"Added entry...netresolv... %s\n",dbgaddr(entry->inetaddr));
@@ -146,8 +152,6 @@
 
 void sigtimecatch(int sig)
 {
-	struct resolvaddr entry;
-
 	signal(SIGALRM, sigincatch);
 #ifdef DEBUG
 	fprintf(dfp,"TIMEOUT SIGNAL CAUGHT\n");
@@ -169,7 +173,6 @@
 	struct gotname finalentry;
 	struct hostent *res;
 	unsigned char *p;
-	char addrchar[20];
 	int i;
 
 #ifdef DEBUG
@@ -213,7 +216,7 @@
 #endif
 				
 				res = gethostbyaddr(p,
-					sizeof(unsigned long int),AF_INET);
+					sizeof(struct in_addr),AF_INET);
 				alarm(0);
 				/* Build return entry... */
 				if (res)
diff -ru netwatch0.8a/netresolv.h netwatch0.8a.64bitclean/netresolv.h
--- netwatch0.8a/netresolv.h	Sun Oct 18 03:04:09 1998
+++ netwatch0.8a.64bitclean/netresolv.h	Mon Jan 11 21:02:36 1999
@@ -5,7 +5,7 @@
 struct resolvaddr 
 {
 	pid_t pid;
-	unsigned long inetaddr;
+	u_int32_t inetaddr;
 	char *where;
 };
 
diff -ru netwatch0.8a/netwatch.c netwatch0.8a.64bitclean/netwatch.c
--- netwatch0.8a/netwatch.c	Tue Oct 20 03:41:54 1998
+++ netwatch0.8a.64bitclean/netwatch.c	Mon Jan 11 21:18:18 1999
@@ -70,6 +70,7 @@
 #endif
 #endif
 
+#include <stdlib.h>
 #include <unistd.h>
 #include <sys/types.h>
 /*
@@ -265,12 +266,12 @@
 int magnaoffs = MAGNAOFFS;
 char magnamatch[RESOLVE_MAX];
 HOSTINFO *magnaspot;
-unsigned long int magnakey;
+u_int32_t magnakey;
 int magnaphys = 0;
 int magnafirst = TRUE;
 int magnafull = FALSE;
 HOSTINFO *magnacomhost = NULL;
-unsigned long int magnacomkey;
+u_int32_t magnacomkey;
 
 double maxburst = 0.0;
 unsigned char netmask[4] =
@@ -382,8 +383,9 @@
 void handle_frame (unsigned char *buf, int length, struct sockaddr *saddr);
 void handle_ip (struct ip *buf, int length);
 void processinetrc (unsigned char *netmask, unsigned char *local, int *peth);
-
-
+int doeth(void);
+int gh(int);
+int dokeyin(void);
 
 typedef void (*sigfunc) (int);
 
@@ -444,7 +446,7 @@
   struct resolvaddr one;
 
   one.pid = mypid;
-  one.inetaddr = *(unsigned long *) p;
+  one.inetaddr = *(u_int32_t *) p;
   one.where = where;
   write (msocket[1], &one, sizeof (one));
   kill (child, SIGUSR1);
@@ -768,10 +770,9 @@
   static char dumbuf[80];
   char dum;
   int n;
-  long int cmset, rset, cset, eset;
+  long int rset, cset, eset;
   int maxfd;
   int tfd = 0;
-  static int fair = 0;
   struct timeval seltime;
 
 
@@ -867,11 +868,9 @@
 }
 
 
-
+int
 main (int argc, char *argv[])
 {
-  int dum;
-  char *device = ETH;
 
   {				/*
 				 * Compound statement to make initializers 
@@ -904,7 +903,7 @@
 	dup2 (osocket[1], 1);
 	close (osocket[1]);
 	execlp ("netresolv", "netresolv", NULL);
-	perror ("NETRESOLV");
+	perror ("exec netresolv");
 	exit (1);
       }
     close (msocket[0]);
@@ -1212,24 +1211,24 @@
 }
 
 int
-  tlocal (unsigned long *addr)
+  tlocal (u_int32_t *addr)
 {
   static unsigned char lhost[] =
   {127, 0, 0, 1};
-  unsigned long *k = (unsigned long *) netmask;
-  unsigned long reslocal, restest;
-  if (*addr == *(unsigned long *) lhost)
+  u_int32_t *k = (u_int32_t *) netmask;
+  u_int32_t reslocal, restest;
+  if (*addr == *(u_int32_t *) lhost)
     return (TRUE);
   restest = *addr & *k;
-  reslocal = *(unsigned long *) localaddr & *k;
+  reslocal = *(u_int32_t *) localaddr & *k;
   return (restest == reslocal);
 }
 
 void
-  searchforinsertion (unsigned long key, HOSTINFO * first)
+  searchforinsertion (u_int32_t key, HOSTINFO * first)
 {
   current = first->flink;
-  while (current != first && key < (unsigned long) ntohl (*(unsigned long *) current->addr))
+  while (current != first && key < (u_int32_t) ntohl (*(u_int32_t *) current->addr))
     current = current->flink;
 }
 
@@ -1286,7 +1285,6 @@
   getlastname (char *dest, int max)
 {
   char *p;
-  char *origdest = dest;
   int i = 0;
 
 /*
@@ -1321,13 +1319,13 @@
   updatecurrent (HOSTINFO * work, struct ip *buf, int length, int opt, int destlocal, int orglocal)
 {
   int x;
-  unsigned long wlen;
+  int wlen;
   static char tpr[30];
 /*
  * static unsigned char finpk[] = { 206, 248, 7, 5 };  
  */
 
-  wlen = (unsigned long) ntohs (buf->tot_len);
+  wlen = ntohs (buf->tot_len);
 /*
  * Update current entries 
  */
@@ -1444,16 +1442,14 @@
 static char ftpversion[256];
 
 void
-  addtolocallist (unsigned long *key, unsigned long *okey, struct ip *buf, int length, int opt)
+  addtolocallist (u_int32_t *key, u_int32_t *okey, struct ip *buf, int length, int opt)
 {
-  static int mcnt = 0;
-  static int ncnt = 0;
   unsigned char *pk = (unsigned char *) key;
-  unsigned long wlen;
+  int wlen;
   char *ss;
   static struct hostent *phost;
 
-  wlen = (unsigned long) ntohs (buf->tot_len);
+  wlen = ntohs (buf->tot_len);
 
   if (fish == NULL && !fishlen)
     {
@@ -1504,16 +1500,16 @@
 /*
  * } if (fishlen == 30000) fclose(fish);   
  */
-  searchforinsertion ((unsigned long) ntohl (*key), lfirst);
-  if (*(unsigned long *) current->addr != *key)
+  searchforinsertion ((u_int32_t) ntohl (*key), lfirst);
+  if (*(u_int32_t *) current->addr != *key)
     {
-      work = (HOSTINFO *) malloc (sizeof (*work));
+      work = malloc (sizeof (*work));
       previous = current->blink;
 /*
  * Init values to ZERO for 1st entry.... 
  */
       clearentry (work);
-      *(unsigned long *) work->addr = *key;
+      *(u_int32_t *) work->addr = *key;
 /*
  * work->disprow = previous->disprow + 1; 
  */
@@ -1624,7 +1620,7 @@
     {
       magnacomhost = work;
     }
-  *(unsigned long *) work->othaddr = *okey;
+  *(u_int32_t *) work->othaddr = *okey;
 
   if (tlocal (okey))
     updatecurrent (work, buf, length, opt, LOCUPDATE, LOCUPDATE);
@@ -1633,22 +1629,19 @@
 }
 
 void
-  addtoremotelist (unsigned long *key, unsigned long *okey, struct ip *buf, int length, int opt)
+  addtoremotelist (u_int32_t *key, u_int32_t *okey, struct ip *buf, int length, int opt)
 {
   unsigned char *pk = (unsigned char *) key;
 
-  int x;
-  int dzero = 0;
-  char star = '*';
-  unsigned long wlen;
+  int wlen;
   char *ss;
 
-  wlen = (unsigned long) ntohs (buf->tot_len);
+  wlen = ntohs (buf->tot_len);
 
-  searchforinsertion ((unsigned long) ntohl (*key), rfirst);
-  if (*(unsigned long *) current->addr != *key)
+  searchforinsertion ((u_int32_t) ntohl (*key), rfirst);
+  if (*(u_int32_t *) current->addr != *key)
     {
-      work = (HOSTINFO *) malloc (sizeof (*work));
+      work = malloc (sizeof (*work));
       previous = current->blink;
 /*
  * Init values to ZERO for 1st entry.... 
@@ -1660,7 +1653,7 @@
       work->update = 1;
       work->telnet_in = 0;
       remoteupdate = 1;
-      *(unsigned long *) work->addr = *key;
+      *(u_int32_t *) work->addr = *key;
       memcpy (work->badmac, fillmac, sizeof (fillmac));
       if (!opt)
 	{			/*
@@ -1792,7 +1785,7 @@
     {
       magnacomhost = work;
     }
-  *(unsigned long *) work->othaddr = *okey;
+  *(u_int32_t *) work->othaddr = *okey;
   if (tlocal (okey))
     updatecurrent (work, buf, length, opt, LOCUPDATE, REMUPDATE);
   else
@@ -1801,17 +1794,14 @@
 }
 
 void
-  handle_ip (struct ip *buf, int length)
+  handle_ip (struct ip *argbuf, int length)
 {
-  static int x;
-  long sourcel;
-  long destl;
-  struct hostent *hostent;
-  unsigned long wlen;
-
+  int wlen;
+  struct ip bufstruct, *buf = &bufstruct;
 
+  memcpy(buf, argbuf, sizeof(struct ip));	/* to fix unaligned accesses */
   new = time (0);
-  wlen = (unsigned long) ntohs (buf->tot_len);
+  wlen = ntohs (buf->tot_len);
   selprob = 40;
   if (buf->ip_p <= SN_MAX_IP_PORT)
     {				/*
@@ -1822,19 +1812,19 @@
     }				/*
 				 * if IP protocol type is to be tallied 
 				 */
-  if (tlocal ((long int *) &buf->saddr))
-    addtolocallist ((unsigned long int *) &buf->saddr, (unsigned long int *) &buf->daddr, buf, length, 0);
+  if (tlocal ((u_int32_t *) &buf->saddr))
+    addtolocallist ((u_int32_t *) &buf->saddr, (u_int32_t *) &buf->daddr, buf, length, 0);
   else
     {
-      addtoremotelist ((unsigned long int *) &buf->saddr, (unsigned long int *) &buf->daddr, buf, length, 0);
+      addtoremotelist ((u_int32_t *) &buf->saddr, (u_int32_t *) &buf->daddr, buf, length, 0);
       routeruse += wlen;
       routerfrom += wlen;
     }
-  if (tlocal ((long int *) &buf->daddr))
-    addtolocallist ((unsigned long int *) &buf->daddr, (unsigned long int *) &buf->saddr, buf, length, 1);
+  if (tlocal ((u_int32_t *) &buf->daddr))
+    addtolocallist ((u_int32_t *) &buf->daddr, (u_int32_t *) &buf->saddr, buf, length, 1);
   else
     {
-      addtoremotelist ((unsigned long int *) &buf->daddr, (unsigned long int *) &buf->saddr, buf, length, 1);
+      addtoremotelist ((u_int32_t *) &buf->daddr, (u_int32_t *) &buf->saddr, buf, length, 1);
       routeruse += wlen;
       routerto += wlen;
     }
@@ -1843,9 +1833,6 @@
 void
   handle_frame (unsigned char *buf, int length, struct sockaddr *saddr)
 {
-  int prot_int;
-  int search_int;
-  int prot_now;
   struct ip *ip_ptr;
 
   ip_ptr = (struct ip *) ((void *) buf + ETH_HLEN);
@@ -1963,9 +1950,10 @@
   if (length)
     {
       handle_frame (buf, length, &saddr);
+      return 0; /* XXX-PS: wasn't here, but then there's no return... */
     }
   else
-    return (0);
+    return (-1); /* XXX-PS: used to be return 0, but elsewhere failure is tested */
 
 }
 
@@ -2188,7 +2176,7 @@
 	       * In child process... to handle stats... 
 	       */
 	      gostats ();
-	      exit ();
+	      exit (0);
 
 	    }
 	  break;
diff -ru netwatch0.8a/processinetrc.c netwatch0.8a.64bitclean/processinetrc.c
--- netwatch0.8a/processinetrc.c	Sun Oct 18 03:04:09 1998
+++ netwatch0.8a.64bitclean/processinetrc.c	Mon Jan 11 21:19:03 1999
@@ -4,8 +4,10 @@
 	
 	Copyright G. MacKay under the GNU GPL 
 */
+#include <stdlib.h>
 #include <stdio.h>
 #include <string.h>
+#include <ctype.h>
 
 FILE *fp;
 extern char configfile[];
@@ -92,7 +94,7 @@
 			rest);
 	  if (!strcmp (ethdevname, devname))
 	    {
-	      if (atoi (flags) & 1 == 1)  /* Thanks Dave...! */
+	      if ((atoi (flags) & 1) == 1)  /* Thanks Dave...! */
 		{
 		  cvhextohost (dest, local);
 		  cvhextohost (mask, netmask);
@@ -116,7 +118,6 @@
 {
 
   unsigned int hold[4];
-  long *netint;
   int ethere = 0;
   int netmaskglobal = 0;
   int ipglobal = 0;
@@ -126,7 +127,7 @@
 
 
   *ok = 0;
-  if (fp = fopen ("/proc/net/route", "r"))
+  if ((fp = fopen ("/proc/net/route", "r")))
     {
       processproc (fp, netmask, local, ok);
       fclose (fp);
diff -ru netwatch0.8a/services.c netwatch0.8a.64bitclean/services.c
--- netwatch0.8a/services.c	Sun Oct 18 03:04:09 1998
+++ netwatch0.8a.64bitclean/services.c	Mon Jan 11 21:07:40 1999
@@ -6,6 +6,9 @@
 /* This routine initializes the names for port numbers. */
 /* These are from RFC 1700, "Assigned Numbers", which are from hither and yon. */
 
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
 #include "netwatch.h"
 
 int hashport( int port, int hash)
@@ -48,15 +51,13 @@
 void addtolist(struct port_info *first[], int port, char *name, int hash)
 {
 	int spot;
-	struct port_info *current;
-	struct port_info *previous;
 	struct port_info *place;	
 		
 	spot = hashport(port,hash);
 
 	place = (struct port_info *)malloc(
 			sizeof(*first[spot]));
-	place->name = (char *) malloc(strlen(name)+1);
+	place->name = malloc(strlen(name)+1);
 	strcpy(place->name,name);
 	place->port = port;
 	if (first[spot])

--J2SCkAp4GZ/dPZZf--

