dma: rework config parsing
[dragonfly.git] / contrib / ipfilter / ipsd / slinux.c
blobaf6cf5b0d87bd874598c0b9d91df23795eb419e9
1 /*
2 * (C)opyright 1992-1998 Darren Reed. (from tcplog)
4 * See the IPFILTER.LICENCE file for details on licencing.
6 * The author of this software makes no garuntee about the
7 * performance of this package or its suitability to fulfill any purpose.
9 */
11 #include <stdio.h>
12 #include <netdb.h>
13 #include <ctype.h>
14 #include <signal.h>
15 #include <errno.h>
16 #include <sys/types.h>
17 #include <sys/time.h>
18 #include <sys/timeb.h>
19 #include <sys/socket.h>
20 #include <sys/file.h>
21 #include <sys/ioctl.h>
22 #include <sys/dirent.h>
23 #include <linux/netdevice.h>
24 #include <net/if.h>
25 #include <netinet/in.h>
26 #include <netinet/ip.h>
27 #include <netinet/tcp.h>
28 #include "ip_compat.h"
29 #include "tcpip.h"
31 #ifndef lint
32 static const char sccsid[] = "@(#)slinux.c 1.1 12/3/95 (C) 1995 Darren Reed";
33 #endif
35 #define BUFSPACE 32768
38 * Be careful to only include those defined in the flags option for the
39 * interface are included in the header size.
42 static int timeout;
43 static char *eth_dev = NULL;
46 int ack_recv(bp)
47 char *bp;
49 struct tcpip tip;
50 tcphdr_t *tcp;
51 ip_t *ip;
53 ip = (struct ip *)&tip;
54 tcp = (tcphdr_t *)(ip + 1);
56 bcopy(bp, (char *)&tip, sizeof(tip));
57 bcopy(bp + (ip.ip_hl << 2), (char *)tcp, sizeof(*tcp));
58 if (0 == detect(ip, tcp))
59 return 1;
60 return 0;
64 void readloop(fd, port, dst)
65 int fd, port;
66 struct in_addr dst;
68 static u_char buf[BUFSPACE];
69 struct sockaddr dest;
70 register u_char *bp = buf;
71 register int cc;
72 int dlen, done = 0;
73 time_t now = time(NULL);
75 do {
76 fflush(stdout);
77 dlen = sizeof(dest);
78 bzero((char *)&dest, dlen);
79 cc = recvfrom(fd, buf, BUFSPACE, 0, &dest, &dlen);
80 if (!cc)
81 if ((time(NULL) - now) > timeout)
82 return done;
83 else
84 continue;
86 if (bp[12] != 0x8 || bp[13] != 0)
87 continue; /* not ip */
90 * get rid of non-tcp or fragmented packets here.
92 if (cc >= sizeof(struct tcpiphdr))
94 if (((bp[14+9] != IPPROTO_TCP) &&
95 (bp[14+9] != IPPROTO_UDP)) ||
96 (bp[14+6] & 0x1f) || (bp[14+6] & 0xff))
97 continue;
98 done += ack_recv(bp + 14);
100 } while (cc >= 0);
101 perror("read");
102 exit(-1);
105 int initdevice(dev, tout)
106 char *dev;
107 int tout;
109 int fd;
111 eth_dev = strdup(dev);
112 if ((fd = socket(AF_INET, SOCK_PACKET, htons(ETHERTYPE_IP))) == -1)
114 perror("socket(SOCK_PACKET)");
115 exit(-1);
118 return fd;