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