]> git.pld-linux.org Git - packages/trafshow.git/blame - trafshow-2.0-pcap.patch
- updated to 5.2.3
[packages/trafshow.git] / trafshow-2.0-pcap.patch
CommitLineData
a5fd0114 1diff -ru -x trafshow-2.0/libpcap* trafshow-2.0.orig/Makefile trafshow-2.0/Makefile
2--- trafshow-2.0.orig/Makefile Tue Jan 16 14:28:26 1996
3+++ trafshow-2.0/Makefile Sun Apr 13 17:25:39 1997
4@@ -3,17 +3,19 @@
5 #
6
7 # This options intended for BSD/OS V2
8-CC = shlicc2
9+CC = gcc
10+ifndef FLAGS
11 FLAGS = -O2
12+endif
13 DEFINE =
14-LIB = ../lib/libbpft.a -lcurses -ltermcap -ll
15+LIB = ../lib/libbpft.a -L../libpcap -lncurses -ltermcap -lpcap
16
17 BINDIR = /usr/local/bin
18 MANDIR = /usr/local/man/man1
19 MODE = 750
20 GROUP = wheel
21
22-INCLUDE = -I../include
23+INCLUDE = -I../include -I../linux-include -I../libpcap/linux-include -I../libpcap -I../libpcap/bpf -I/usr/include/bsd
24 CFLAGS = $(FLAGS) $(INCLUDE) $(DEFINE)
25 DEPFLAGS= $(INCLUDE) $(DEFINE)
26 ARFLAGS = rc
27diff -ru -x trafshow-2.0/libpcap* trafshow-2.0.orig/include/interface.h trafshow-2.0/include/interface.h
28--- trafshow-2.0.orig/include/interface.h Fri Jun 9 19:25:48 1995
29+++ trafshow-2.0/include/interface.h Sun Apr 13 17:33:18 1997
30@@ -20,6 +20,7 @@
31 */
32
33 #include <machine/endian.h>
34+#include <pcap.h>
35
36 #ifdef __GNUC__
37 #define inline __inline
38@@ -39,8 +40,8 @@
39 extern char *program_name; /* used to generate self-identifying messages */
40
41 extern int link_type;
42-extern unsigned long netmask;
43-extern unsigned long localnet;
44+extern bpf_u_int32 netmask;
45+extern bpf_u_int32 localnet;
46 extern int snaplen;
47 /* global pointers to beginning and end of current packet */
48 extern unsigned char *packetp;
49diff -ru -x trafshow-2.0/libpcap* trafshow-2.0.orig/lib/Makefile trafshow-2.0/lib/Makefile
50--- trafshow-2.0.orig/lib/Makefile Wed Jan 10 15:51:15 1996
51+++ trafshow-2.0/lib/Makefile Sun Apr 13 17:25:39 1997
52@@ -3,21 +3,23 @@
53 #
54
55 LIB = libbpft.a
56-SRC = addrtoname.c bpf.c bpf_dump.c bpf_filter.c bpf_image.c etherent.c \
57- gencode.c inet.c interfaces.c nametoaddr.c optimize.c util.c \
58- version.c tcpgram.y tcplex.l
59-OBJ = addrtoname.o bpf.o bpf_dump.o bpf_filter.o bpf_image.o etherent.o \
60- gencode.o inet.o interfaces.o nametoaddr.o optimize.o util.o \
61- version.o tcpgram.o tcplex.o
62+#SRC = addrtoname.c bpf.c bpf_dump.c bpf_filter.c bpf_image.c etherent.c \
63+# gencode.c inet.c interfaces.c nametoaddr.c optimize.c util.c \
64+# version.c tcpgram.y tcplex.l
65+#OBJ = addrtoname.o bpf.o bpf_dump.o bpf_filter.o bpf_image.o etherent.o \
66+# gencode.o inet.o interfaces.o nametoaddr.o optimize.o util.o \
67+# version.o tcpgram.o tcplex.o
68+SRC = addrtoname.c bpf_dump.c etherent.c util.c
69+OBJ = $(SRC:.c=.o)
70
71-CC = gcc
72-FLAGS = -g
73-DEFINE =
74-
75-INCLUDE = -I../include
76-CFLAGS = $(FLAGS) $(INCLUDE) $(DEFINE)
77-DEPFLAGS= $(INCLUDE) $(DEFINE)
78-ARFLAGS = rc
79+#CC = gcc
80+#FLAGS = -g
81+#DEFINE =
82+#
83+#INCLUDE = -I../include
84+#CFLAGS = $(FLAGS) $(INCLUDE) $(DEFINE)
85+#DEPFLAGS= $(INCLUDE) $(DEFINE)
86+#ARFLAGS = rc
87
88 $(LIB): $(OBJ)
89 rm -f $(LIB)
90diff -ru -x trafshow-2.0/libpcap* trafshow-2.0.orig/lib/addrtoname.c trafshow-2.0/lib/addrtoname.c
91--- trafshow-2.0.orig/lib/addrtoname.c Fri Jan 12 12:42:37 1996
92+++ trafshow-2.0/lib/addrtoname.c Sun Apr 13 17:26:02 1997
93@@ -468,8 +468,10 @@
94 char *device;
95 int fflag;
96 {
97+#if 0 /* netmask MUST be initialized */
98 if (netmask == 0) /* if was not initialized */
99 lookup_net(device);
100+#endif
101
102 if (fflag) {
103 f_localnet = localnet;
104diff -ru -x trafshow-2.0/libpcap* trafshow-2.0.orig/trafshow/Makefile trafshow-2.0/trafshow/Makefile
105--- trafshow-2.0.orig/trafshow/Makefile Mon Jan 15 11:44:09 1996
106+++ trafshow-2.0/trafshow/Makefile Sun Apr 13 17:25:39 1997
107@@ -5,14 +5,14 @@
108 PROG = trafshow
109 SRC = main.c show.c keyb.c
110 OBJ = $(SRC:.c=.o)
111-LIB = ../lib/libbpft.a -lcurses -ltermcap -ll
112-CC = gcc
113-FLAGS = -g
114-DEFINE =
115-
116-INCLUDE = -I../include
117-CFLAGS = $(FLAGS) $(INCLUDE) $(DEFINE)
118-DEPFLAGS= $(INCLUDE) $(DEFINE)
119+#LIB = ../lib/libbpft.a -lcurses -ltermcap -ll
120+#CC = gcc
121+#FLAGS = -g
122+#DEFINE =
123+#
124+#INCLUDE = -I../include
125+#CFLAGS = $(FLAGS) $(INCLUDE) $(DEFINE)
126+#DEPFLAGS= $(INCLUDE) $(DEFINE)
127
128 $(PROG): $(OBJ)
129 $(CC) $(OBJ) $(LIB) -o $(PROG)
130diff -ru -x trafshow-2.0/libpcap* trafshow-2.0.orig/trafshow/main.c trafshow-2.0/trafshow/main.c
131--- trafshow-2.0.orig/trafshow/main.c Mon Jan 15 17:10:42 1996
132+++ trafshow-2.0/trafshow/main.c Sun Apr 13 17:37:29 1997
133@@ -11,6 +11,8 @@
134 * THIS SOFTWARE IS PROVIDED ``AS IS'' WITHOUT ANY WARRANTIES OF ANY KIND.
135 */
136
137+char *version = "2.0s";
138+
139 #include <curses.h>
140 #include <stdlib.h>
141 #include <signal.h>
142@@ -37,20 +39,24 @@
143 int scr_interval = DEFAULT_SCR; /* screen refresh interval in seconds */
144 int snaplen = DEFAULT_SNAPLEN; /* length of saved portion of packet */
145
146+bpf_u_int32 localnet, netmask;
147+
148 void
149 main(argc, argv)
150 int argc;
151 char **argv;
152 {
153- struct bpf_program *parse();
154- void bpf_dump(), usage(), onterm(), onalarm();
155-
156- int op, cnt = -1, fflag = 0, if_fd = -1;
157- struct bpf_program *fcode;
158- char *infile = 0;
159+ int op, cnt = -1, fflag = 0;
160+ struct bpf_program fcode;
161+ char *infile = NULL;
162 char *cmdbuf;
163 extern char *optarg;
164 extern int optind, opterr;
165+ char errbuf[PCAP_ERRBUF_SIZE];
166+ pcap_t *pcap;
167+ void usage(), onterm(), onalarm();
168+ void show_callback(u_char *, const struct pcap_pkthdr *,
169+ const u_char *);
170
171 program_name = stripdir(argv[0]);
172
173@@ -101,25 +107,55 @@
174 }
175
176 /* Find network interface */
177- if (device_name == 0)
178- if ((device_name = getenv("IFF_LISTEN")) == NULL)
179- if ((device_name = lookup_device()) == 0)
180- error("can't find any interfaces");
181-
182- /* Attach bpf interface to the network interface */
183- if_fd = bpf_init(device_name, pflag);
184+ if (device_name == NULL) {
185+ device_name = pcap_lookupdev(errbuf);
186+ if (device_name == NULL) {
187+ fputs(errbuf, stderr);
188+ exit(10);
189+ }
190+ }
191
192- if (infile)
193+ if (infile != NULL) {
194+ pcap = pcap_open_offline(infile, errbuf);
195+ localnet = 0;
196+ netmask = 0;
197+ if (fflag != 0) {
198+ fputs("-f and -r options are incompatible", stderr);
199+ exit(14);
200+ }
201+ }else {
202+ pcap = pcap_open_live(device_name, snaplen, !pflag, 1000, errbuf);
203+ }
204+ if (pcap == NULL) {
205+ fputs(errbuf, stderr);
206+ exit(11);
207+ }
208+ if (pcap_lookupnet(device_name, &localnet, &netmask, errbuf) < 0) {
209+ fputs(errbuf, stderr);
210+ exit(12);
211+ }
212+
213+ if (infile != NULL)
214 cmdbuf = read_infile(infile);
215 else
216 cmdbuf = copy_argv(&argv[optind]);
217
218- fcode = parse(cmdbuf, Oflag);
219+ if (pcap_compile(pcap, &fcode, cmdbuf, Oflag, netmask) < 0) {
220+ fputs(pcap_geterr(pcap), stderr);
221+ exit(13);
222+ }
223+ init_addrtoname(device_name, fflag);
224+
225 if (dflag) {
226- bpf_dump(fcode, dflag);
227+ bpf_dump(&fcode, dflag);
228 exit(0);
229 }
230
231+ if (pcap_setfilter(pcap, &fcode) < 0) {
232+ fputs(pcap_geterr(pcap), stderr);
233+ exit(15);
234+ }
235+
236 initterm();
237 signal(SIGHUP, onterm);
238 signal(SIGINT, onterm);
239@@ -128,7 +164,8 @@
240 signal(SIGTSTP, SIG_IGN);
241 signal(SIGALRM, onalarm);
242 traf_init(fflag);
243- bpf_readloop(cnt, if_fd, fcode);
244+ if (pcap_loop(pcap, cnt, &show_callback, NULL) < 0)
245+ pcap_perror(pcap, argv[0]);
246 onterm();
247 }
248
249@@ -161,7 +198,7 @@
250 {
251 puts(NICECOLOR);
252 COLS = 80;
253- if (initscr() == ERR) exit(1);
254+ initscr();
255 if (LINES < 20) {
256 addstr("Must more LINES on term");
257 onterm();
258@@ -189,8 +226,6 @@
259 void
260 usage()
261 {
262- extern char version[];
263-
264 fprintf(stderr, "trafshow v%s - full screen show network traffic\n", version);
265 fprintf(stderr,
266 "Usage: %s [-dfknNOp -c num -i name -r sec -t sec] [-F file | expr]\n\
267diff -ru -x trafshow-2.0/libpcap* trafshow-2.0.orig/trafshow/show.c trafshow-2.0/trafshow/show.c
268--- trafshow-2.0.orig/trafshow/show.c Mon Jan 15 17:00:25 1996
269+++ trafshow-2.0/trafshow/show.c Sun Apr 13 17:25:39 1997
270@@ -27,7 +27,9 @@
271 #include <netinet/udp_var.h>
272 #include <netinet/tcp.h>
273 #include <netinet/tcpip.h>
274+#include <netinet/if_ether.h>
275
276+#include <pcap.h>
277 #include "addrtoname.h"
278 #include "trafshow.h"
279
280@@ -56,6 +58,8 @@
281 int page_size;
282 int l_nflag;
283
284+u_char *snapend;
285+
286 extern void onterm();
287
288 traf_init(fflag)
289@@ -361,6 +365,20 @@
290
291 return;
292 }
293+
294+
295+void show_callback(u_char *dummy, const struct pcap_pkthdr *pkt,
296+ const u_char *data)
297+{
298+ const struct ether_header *p;
299+ if (pkt->caplen < sizeof(struct ether_header)) return;
300+ p = (struct ether_header *)data;
301+ snapend = (u_char *) (data + pkt->caplen);
302+ if (ntohs(p->ether_type) != ETHERTYPE_IP) return;
303+ processing_ip((struct ip *) (data + sizeof(struct ether_header)),
304+ pkt->len - sizeof(struct ether_header));
305+}
306+
307
308 int
309 inputchar()
This page took 0.092292 seconds and 4 git commands to generate.