$NetBSD: patch-ac,v 1.5 2002/07/30 12:41:26 wiz Exp $

--- choparp.c.orig	Tue Oct  7 11:29:46 1997
+++ choparp.c
@@ -12,6 +12,9 @@
 #include <stdio.h>
 #include <unistd.h>
 #include <string.h>
+#ifdef __NetBSD__
+#  include <stdlib.h> /* malloc() */
+#endif
 #include <sys/types.h>
 #include <fcntl.h>
 #include <sys/time.h>
@@ -24,6 +27,7 @@
 #include <netinet/if_ether.h>
 #include <sys/param.h>
 #include <errno.h>
+#include <assert.h>
 
 #define	BPFFILENAME	"/dev/bpf%d"	/* bpf file template */
 #ifndef	NBPFILTER			/* number of available bpf */
@@ -180,7 +184,7 @@ checkarp(char *arpbuf){
 	fprintf(stderr,"checkarp: WARNING: received unknown type ARP request.\n");
 	return(0);
     }
-    target_ip = ntohl(*(u_long *)(arp->arp_tpa));
+    target_ip = ntohl(*(u_int32_t *)(arp->arp_tpa));
     if ((target_ip & target_mask) == target_net)
 	return(-1);		/* OK */
     return(0);
@@ -217,20 +221,35 @@ gen_arpreply(char *arpbuf, size_t *rlen)
 
 void
 loop(int fd, char *buf, size_t buflen){
-    size_t  rlen;
+    ssize_t  rlen;
     char    *p, *nextp;
     size_t  nextlen;
     char    *rframe;
     size_t  rframe_len;
     char    *sframe;
     size_t  sframe_len;
+    fd_set fdset;
+
+    FD_ZERO(&fdset);
+    FD_SET(fd,&fdset);
 
     for(;;){
-	if ((rlen = read(fd, buf, buflen)) <= 0){
-	    fprintf(stderr,"loop: read: %s\n", strerror(errno));
-	    /* XXX: restart itself if daemon mode */
-	    return;
-	}
+      int r;
+      r = select(fd+1,&fdset, 0, 0, 0);
+      if ((r < 0) && (errno == EINTR)) continue;
+      if (r < 0) {
+	perror("select");
+	return;
+      }
+      assert(r == 1);
+
+      rlen = read(fd, buf, buflen);
+      if ((rlen < 0) && (errno = EINTR)) continue;
+      if (rlen < 0) {
+	perror("loop: read");
+	return;
+      }
+
 	p = buf;
 	while((rframe = getarp(p, rlen, &nextp, &nextlen)) != NULL){
 	    if (checkarp(rframe)){
