Subject: lib/1108: compile warnings in packet filter library
To: None <gnats-admin@sun-lamp.cs.berkeley.edu>
From: Thorsten Lockert <tholo@SigmaSoft.COM>
List: netbsd-bugs
Date: 06/03/1995 23:20:02
>Number:         1108
>Category:       lib
>Synopsis:       compile warnings in packet filter library
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    lib-bug-people (Library Bug People)
>State:          open
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Sat Jun  3 23:20:01 1995
>Originator:     Thorsten Lockert
>Organization:
SigmaSoft, Th. Lockert
>Release:        May 28, 1995
>Environment:
	
System: NetBSD gandalf.sigmasoft.com 1.0A NetBSD 1.0A (GANDALF) #1: Sun May 7 21:49:27 PDT 1995 tholo@gandalf.sigmasoft.com:/usr/src/sys/arch/i386/compile/GANDALF i386


>Description:
	There are compile warnings in the packet filter library when
	compiled with -Wall -Wstrict-prototypes

>How-To-Repeat:
	Compile src/lib/libpcap with -Wall -Wstrict-prototypes

>Fix:
	Apply the following patches:

diff -c src/lib/libpcap.orig/gencode.c src/lib/libpcap/gencode.c
*** src/lib/libpcap.orig/gencode.c	Sat Jun  3 23:05:07 1995
--- src/lib/libpcap/gencode.c	Sat Jun  3 23:08:52 1995
***************
*** 1339,1354 ****
  }
  
  struct arth *
! gen_load(proto, index, size)
  	int proto;
! 	struct arth *index;
  	int size;
  {
  	struct slist *s, *tmp;
  	struct block *b;
  	int regno = alloc_reg();
  
! 	free_reg(index->regno);
  	switch (size) {
  
  	default:
--- 1339,1354 ----
  }
  
  struct arth *
! gen_load(proto, idx, size)
  	int proto;
! 	struct arth *idx;
  	int size;
  {
  	struct slist *s, *tmp;
  	struct block *b;
  	int regno = alloc_reg();
  
! 	free_reg(idx->regno);
  	switch (size) {
  
  	default:
***************
*** 1371,1380 ****
  		bpf_error("unsupported index operation");
  
  	case Q_LINK:
! 		s = xfer_to_x(index);
  		tmp = new_stmt(BPF_LD|BPF_IND|size);
  		sappend(s, tmp);
! 		sappend(index->s, s);
  		break;
  
  	case Q_IP:
--- 1371,1380 ----
  		bpf_error("unsupported index operation");
  
  	case Q_LINK:
! 		s = xfer_to_x(idx);
  		tmp = new_stmt(BPF_LD|BPF_IND|size);
  		sappend(s, tmp);
! 		sappend(idx->s, s);
  		break;
  
  	case Q_IP:
***************
*** 1385,1400 ****
  	case Q_MOPRC:
  	case Q_MOPDL:
  		/* XXX Note that we assume a fixed link link header here. */
! 		s = xfer_to_x(index);
  		tmp = new_stmt(BPF_LD|BPF_IND|size);
  		tmp->s.k = off_nl;
  		sappend(s, tmp);
! 		sappend(index->s, s);
  
  		b = gen_proto_abbrev(proto);
! 		if (index->b)
! 			gen_and(index->b, b);
! 		index->b = b;
  		break;
  
  	case Q_TCP:
--- 1385,1400 ----
  	case Q_MOPRC:
  	case Q_MOPDL:
  		/* XXX Note that we assume a fixed link link header here. */
! 		s = xfer_to_x(idx);
  		tmp = new_stmt(BPF_LD|BPF_IND|size);
  		tmp->s.k = off_nl;
  		sappend(s, tmp);
! 		sappend(idx->s, s);
  
  		b = gen_proto_abbrev(proto);
! 		if (idx->b)
! 			gen_and(idx->b, b);
! 		idx->b = b;
  		break;
  
  	case Q_TCP:
***************
*** 1402,1426 ****
  	case Q_ICMP:
  		s = new_stmt(BPF_LDX|BPF_MSH|BPF_B);
  		s->s.k = off_nl;
! 		sappend(s, xfer_to_a(index));
  		sappend(s, new_stmt(BPF_ALU|BPF_ADD|BPF_X));
  		sappend(s, new_stmt(BPF_MISC|BPF_TAX));
  		sappend(s, tmp = new_stmt(BPF_LD|BPF_IND|size));
  		tmp->s.k = off_nl;
! 		sappend(index->s, s);
  
  		gen_and(gen_proto_abbrev(proto), b = gen_ipfrag());
! 		if (index->b)
! 			gen_and(index->b, b);
! 		index->b = b;
  		break;
  	}
! 	index->regno = regno;
  	s = new_stmt(BPF_ST);
  	s->s.k = regno;
! 	sappend(index->s, s);
  
! 	return index;
  }
  
  struct block *
--- 1402,1426 ----
  	case Q_ICMP:
  		s = new_stmt(BPF_LDX|BPF_MSH|BPF_B);
  		s->s.k = off_nl;
! 		sappend(s, xfer_to_a(idx));
  		sappend(s, new_stmt(BPF_ALU|BPF_ADD|BPF_X));
  		sappend(s, new_stmt(BPF_MISC|BPF_TAX));
  		sappend(s, tmp = new_stmt(BPF_LD|BPF_IND|size));
  		tmp->s.k = off_nl;
! 		sappend(idx->s, s);
  
  		gen_and(gen_proto_abbrev(proto), b = gen_ipfrag());
! 		if (idx->b)
! 			gen_and(idx->b, b);
! 		idx->b = b;
  		break;
  	}
! 	idx->regno = regno;
  	s = new_stmt(BPF_ST);
  	s->s.k = regno;
! 	sappend(idx->s, s);
  
! 	return idx;
  }
  
  struct block *
diff -c src/lib/libpcap.orig/grammar.y src/lib/libpcap/grammar.y
*** src/lib/libpcap.orig/grammar.y	Sat Jun  3 23:05:07 1995
--- src/lib/libpcap/grammar.y	Sat Jun  3 23:12:43 1995
***************
*** 43,48 ****
--- 43,54 ----
  
  #include "gencode.h"
  
+ #ifndef YYBISON
+ int pcap_parse __P((void));
+ int yyparse __P((void));
+ int yylex __P((void));
+ #endif
+ 
  #define QSET(q, p, d, a) (q).proto = (p),\
  			 (q).dir = (d),\
  			 (q).addr = (a)
***************
*** 60,65 ****
--- 66,72 ----
  }
  
  #ifndef YYBISON
+ int
  pcap_parse()
  {
  	return (yyparse());
diff -c src/lib/libpcap.orig/inet.c src/lib/libpcap/inet.c
*** src/lib/libpcap.orig/inet.c	Sat Jun  3 23:05:07 1995
--- src/lib/libpcap/inet.c	Sat Jun  3 23:08:02 1995
***************
*** 155,161 ****
  	register char *errbuf;
  {
  	register int fd;
! 	register struct sockaddr_in *sin;
  	struct ifreq ifr;
  
  	fd = socket(AF_INET, SOCK_DGRAM, 0);
--- 155,161 ----
  	register char *errbuf;
  {
  	register int fd;
! 	register struct sockaddr_in *sinp;
  	struct ifreq ifr;
  
  	fd = socket(AF_INET, SOCK_DGRAM, 0);
***************
*** 170,177 ****
  		(void)close(fd);
  		return (-1);
  	}
! 	sin = (struct sockaddr_in *)&ifr.ifr_addr;
! 	*netp = sin->sin_addr.s_addr;
  	if (ioctl(fd, SIOCGIFNETMASK, (char *)&ifr) < 0) {
  		(void)sprintf(errbuf, "SIOCGIFNETMASK: %s: %s",
  		    device, pcap_strerror(errno));
--- 170,177 ----
  		(void)close(fd);
  		return (-1);
  	}
! 	sinp = (struct sockaddr_in *)&ifr.ifr_addr;
! 	*netp = sinp->sin_addr.s_addr;
  	if (ioctl(fd, SIOCGIFNETMASK, (char *)&ifr) < 0) {
  		(void)sprintf(errbuf, "SIOCGIFNETMASK: %s: %s",
  		    device, pcap_strerror(errno));
***************
*** 179,185 ****
  		return (-1);
  	}
  	(void)close(fd);
! 	*maskp = sin->sin_addr.s_addr;
  	if (*maskp == 0) {
  		if (IN_CLASSA(*netp))
  			*maskp = IN_CLASSA_NET;
--- 179,185 ----
  		return (-1);
  	}
  	(void)close(fd);
! 	*maskp = sinp->sin_addr.s_addr;
  	if (*maskp == 0) {
  		if (IN_CLASSA(*netp))
  			*maskp = IN_CLASSA_NET;
diff -c src/lib/libpcap.orig/optimize.c src/lib/libpcap/optimize.c
*** src/lib/libpcap.orig/optimize.c	Sat Jun  3 23:05:08 1995
--- src/lib/libpcap/optimize.c	Sat Jun  3 23:09:52 1995
***************
*** 1636,1644 ****
  {
  	struct block *p;
  	int i, j;
! 	int done;
   top:
! 	done = 1;
  	for (i = 0; i < n_blocks; ++i)
  		blocks[i]->link = 0;
  
--- 1636,1644 ----
  {
  	struct block *p;
  	int i, j;
! 	int idone;
   top:
! 	idone = 1;
  	for (i = 0; i < n_blocks; ++i)
  		blocks[i]->link = 0;
  
***************
*** 1662,1676 ****
  		if (JT(p) == 0)
  			continue;
  		if (JT(p)->link) {
! 			done = 0;
  			JT(p) = JT(p)->link;
  		}
  		if (JF(p)->link) {
! 			done = 0;
  			JF(p) = JF(p)->link;
  		}
  	}
! 	if (!done)
  		goto top;
  }
  
--- 1662,1676 ----
  		if (JT(p) == 0)
  			continue;
  		if (JT(p)->link) {
! 			idone = 0;
  			JT(p) = JT(p)->link;
  		}
  		if (JF(p)->link) {
! 			idone = 0;
  			JF(p) = JF(p)->link;
  		}
  	}
! 	if (!idone)
  		goto top;
  }
  
diff -c src/lib/libpcap.orig/pcap-bpf.c src/lib/libpcap/pcap-bpf.c
*** src/lib/libpcap.orig/pcap-bpf.c	Sat Jun  3 23:05:08 1995
--- src/lib/libpcap/pcap-bpf.c	Sat Jun  3 23:06:13 1995
***************
*** 30,35 ****
--- 30,36 ----
  #include <ctype.h>
  #include <signal.h>
  #include <errno.h>
+ #include <unistd.h>
  #include <sys/param.h>			/* optionally get BSD define */
  #include <sys/time.h>
  #include <sys/timeb.h>
diff -c src/lib/libpcap.orig/pcap.c src/lib/libpcap/pcap.c
*** src/lib/libpcap.orig/pcap.c	Sat Jun  3 23:05:08 1995
--- src/lib/libpcap/pcap.c	Sat Jun  3 23:07:00 1995
***************
*** 40,45 ****
--- 40,46 ----
  
  #include <sys/types.h>
  
+ #include <stdlib.h>
  #include <string.h>
  #include <unistd.h>
  
diff -c src/lib/libpcap.orig/scanner.l src/lib/libpcap/scanner.l
*** src/lib/libpcap.orig/scanner.l	Sat Jun  3 23:05:08 1995
--- src/lib/libpcap/scanner.l	Sat Jun  3 23:15:04 1995
***************
*** 49,63 ****
  #define YY_INPUT(buf, result, max)\
   {\
  	char *src = in_buffer;\
! 	int i;\
  \
  	if (*src == 0)\
  		result = YY_NULL;\
  	else {\
! 		for (i = 0; *src && i < max; ++i)\
! 			buf[i] = *src++;\
! 		in_buffer += i;\
! 		result = i;\
  	}\
   }
  #else
--- 49,63 ----
  #define YY_INPUT(buf, result, max)\
   {\
  	char *src = in_buffer;\
! 	int cnt;\
  \
  	if (*src == 0)\
  		result = YY_NULL;\
  	else {\
! 		for (cnt = 0; *src && cnt < max; ++cnt)\
! 			buf[cnt] = *src++;\
! 		in_buffer += cnt;\
! 		result = cnt;\
  	}\
   }
  #else
>Audit-Trail:
>Unformatted: