iptests.c revision 84843
1/*
2 * Copyright (C) 1993-1998 by Darren Reed.
3 *
4 * See the IPFILTER.LICENCE file for details on licencing.
5 */
6#include <stdio.h>
7#include <unistd.h>
8#include <stdlib.h>
9#include <string.h>
10#include <sys/types.h>
11#include <sys/time.h>
12#include <sys/param.h>
13#define _KERNEL
14#define KERNEL
15#if !defined(solaris) && !defined(linux) && !defined(__sgi)
16# include <sys/file.h>
17#else
18# ifdef solaris
19#  include <sys/dditypes.h>
20# endif
21#endif
22#undef  _KERNEL
23#undef  KERNEL
24#if !defined(solaris) && !defined(linux) && !defined(__sgi)
25# include <nlist.h>
26# include <sys/user.h>
27# include <sys/proc.h>
28#endif
29#if !defined(ultrix) && !defined(hpux) && !defined(linux) && !defined(__sgi)
30# include <kvm.h>
31#endif
32#ifndef	ultrix
33# include <sys/socket.h>
34#endif
35#if defined(solaris)
36# include <sys/stream.h>
37#endif
38#include <sys/socketvar.h>
39#ifdef sun
40#include <sys/systm.h>
41#include <sys/session.h>
42#endif
43#if BSD >= 199103
44# include <sys/sysctl.h>
45# include <sys/filedesc.h>
46# include <paths.h>
47#endif
48#include <netinet/in_systm.h>
49#include <sys/socket.h>
50#include <net/if.h>
51#if defined(linux) && (LINUX >= 0200)
52# include <asm/atomic.h>
53#endif
54#if !defined(linux)
55# include <net/route.h>
56#else
57# define __KERNEL__	/* because there's a macro not wrapped by this */
58# include <net/route.h>	/* in this file :-/ */
59#endif
60#include <netinet/in.h>
61#include <arpa/inet.h>
62#include <netinet/ip.h>
63#include <netinet/tcp.h>
64#include <netinet/udp.h>
65#include <netinet/ip_icmp.h>
66#ifndef linux
67# include <netinet/ip_var.h>
68# include <netinet/in_pcb.h>
69# include <netinet/tcp_timer.h>
70# include <netinet/tcp_var.h>
71#endif
72#if defined(__SVR4) || defined(__svr4__) || defined(__sgi)
73# include <sys/sysmacros.h>
74#endif
75#include "ipsend.h"
76
77#if 0
78#if !defined(lint)
79static const char sccsid[] = "%W% %G% (C)1995 Darren Reed";
80static const char rcsid[] = "@(#)$Id: iptests.c,v 2.1.4.2 2001/07/15 22:00:14 darrenr Exp $";
81#endif
82#endif
83
84__FBSDID("$FreeBSD: head/contrib/ipfilter/ipsend/iptests.c 84843 2001-10-12 15:05:00Z bde $");
85
86
87#define	PAUSE()	tv.tv_sec = 0; tv.tv_usec = 10000; \
88		  (void) select(0, NULL, NULL, NULL, &tv)
89
90
91void	ip_test1(dev, mtu, ip, gwip, ptest)
92char	*dev;
93int	mtu;
94ip_t	*ip;
95struct	in_addr	gwip;
96int	ptest;
97{
98	struct	timeval	tv;
99	udphdr_t *u;
100	int	nfd, i = 0, len, id = getpid();
101
102	ip->ip_hl = sizeof(*ip) >> 2;
103	ip->ip_v = IPVERSION;
104	ip->ip_tos = 0;
105	ip->ip_off = 0;
106	ip->ip_ttl = 60;
107	ip->ip_p = IPPROTO_UDP;
108	ip->ip_sum = 0;
109	u = (udphdr_t *)(ip + 1);
110	u->uh_sport = htons(1);
111	u->uh_dport = htons(9);
112	u->uh_sum = 0;
113	u->uh_ulen = htons(sizeof(*u) + 4);
114	ip->ip_len = sizeof(*ip) + ntohs(u->uh_ulen);
115	len = ip->ip_len;
116	nfd = initdevice(dev, u->uh_sport, 1);
117
118	if (!ptest || (ptest == 1)) {
119		/*
120		 * Part1: hl < len
121		 */
122		ip->ip_id = 0;
123		printf("1.1. sending packets with ip_hl < ip_len\n");
124		for (i = 0; i < ((sizeof(*ip) + ntohs(u->uh_ulen)) >> 2); i++) {
125			ip->ip_hl = i >> 2;
126			(void) send_ip(nfd, 1500, ip, gwip, 1);
127			printf("%d\r", i);
128			fflush(stdout);
129			PAUSE();
130		}
131		putchar('\n');
132	}
133
134	if (!ptest || (ptest == 2)) {
135		/*
136		 * Part2: hl > len
137		 */
138		ip->ip_id = 0;
139		printf("1.2. sending packets with ip_hl > ip_len\n");
140		for (; i < ((sizeof(*ip) * 2 + ntohs(u->uh_ulen)) >> 2); i++) {
141			ip->ip_hl = i >> 2;
142			(void) send_ip(nfd, 1500, ip, gwip, 1);
143			printf("%d\r", i);
144			fflush(stdout);
145			PAUSE();
146		}
147		putchar('\n');
148	}
149
150	if (!ptest || (ptest == 3)) {
151		/*
152		 * Part3: v < 4
153		 */
154		ip->ip_id = 0;
155		printf("1.3. ip_v < 4\n");
156		ip->ip_hl = sizeof(*ip) >> 2;
157		for (i = 0; i < 4; i++) {
158			ip->ip_v = i;
159			(void) send_ip(nfd, 1500, ip, gwip, 1);
160			printf("%d\r", i);
161			fflush(stdout);
162			PAUSE();
163		}
164		putchar('\n');
165	}
166
167	if (!ptest || (ptest == 4)) {
168		/*
169		 * Part4: v > 4
170		 */
171		ip->ip_id = 0;
172		printf("1.4. ip_v > 4\n");
173		for (i = 5; i < 16; i++) {
174			ip->ip_v = i;
175			(void) send_ip(nfd, 1500, ip, gwip, 1);
176			printf("%d\r", i);
177			fflush(stdout);
178			PAUSE();
179		}
180		putchar('\n');
181	}
182
183	if (!ptest || (ptest == 5)) {
184		/*
185		 * Part5: len < packet
186		 */
187		ip->ip_id = 0;
188		ip->ip_v = IPVERSION;
189		i = ip->ip_len + 1;
190		printf("1.5.0 ip_len < packet size (size++, long packets)\n");
191		for (; i < (ip->ip_len * 2); i++) {
192			ip->ip_id = htons(id++);
193			ip->ip_sum = 0;
194			ip->ip_sum = chksum((u_short *)ip, ip->ip_hl << 2);
195			(void) send_ether(nfd, (char *)ip, i, gwip);
196			printf("%d\r", i);
197			fflush(stdout);
198			PAUSE();
199		}
200		putchar('\n');
201		printf("1.5.1 ip_len < packet size (ip_len-, short packets)\n");
202		for (i = len; i > 0; i--) {
203			ip->ip_id = htons(id++);
204			ip->ip_len = i;
205			ip->ip_sum = 0;
206			ip->ip_sum = chksum((u_short *)ip, ip->ip_hl << 2);
207			(void) send_ether(nfd, (char *)ip, len, gwip);
208			printf("%d\r", i);
209			fflush(stdout);
210			PAUSE();
211		}
212		putchar('\n');
213	}
214
215	if (!ptest || (ptest == 6)) {
216		/*
217		 * Part6: len > packet
218		 */
219		ip->ip_id = 0;
220		printf("1.6.0 ip_len > packet size (increase ip_len)\n");
221		for (i = len + 1; i < (len * 2); i++) {
222			ip->ip_id = htons(id++);
223			ip->ip_len = i;
224			ip->ip_sum = 0;
225			ip->ip_sum = chksum((u_short *)ip, ip->ip_hl << 2);
226			(void) send_ether(nfd, (char *)ip, len, gwip);
227			printf("%d\r", i);
228			fflush(stdout);
229			PAUSE();
230		}
231		putchar('\n');
232		ip->ip_len = len;
233		printf("1.6.1 ip_len > packet size (size--, short packets)\n");
234		for (i = len; i > 0; i--) {
235			ip->ip_id = htons(id++);
236			ip->ip_sum = 0;
237			ip->ip_sum = chksum((u_short *)ip, ip->ip_hl << 2);
238			(void) send_ether(nfd, (char *)ip, i, gwip);
239			printf("%d\r", i);
240			fflush(stdout);
241			PAUSE();
242		}
243		putchar('\n');
244	}
245
246	if (!ptest || (ptest == 7)) {
247		/*
248		 * Part7: 0 length fragment
249		 */
250		printf("1.7.0 Zero length fragments (ip_off = 0x2000)\n");
251		ip->ip_id = 0;
252		ip->ip_len = sizeof(*ip);
253		ip->ip_off = htons(IP_MF);
254		(void) send_ip(nfd, mtu, ip, gwip, 1);
255		fflush(stdout);
256		PAUSE();
257
258		printf("1.7.1 Zero length fragments (ip_off = 0x3000)\n");
259		ip->ip_id = 0;
260		ip->ip_len = sizeof(*ip);
261		ip->ip_off = htons(IP_MF);
262		(void) send_ip(nfd, mtu, ip, gwip, 1);
263		fflush(stdout);
264		PAUSE();
265
266		printf("1.7.2 Zero length fragments (ip_off = 0xa000)\n");
267		ip->ip_id = 0;
268		ip->ip_len = sizeof(*ip);
269		ip->ip_off = htons(0xa000);
270		(void) send_ip(nfd, mtu, ip, gwip, 1);
271		fflush(stdout);
272		PAUSE();
273
274		printf("1.7.3 Zero length fragments (ip_off = 0x0100)\n");
275		ip->ip_id = 0;
276		ip->ip_len = sizeof(*ip);
277		ip->ip_off = htons(0x0100);
278		(void) send_ip(nfd, mtu, ip, gwip, 1);
279		fflush(stdout);
280		PAUSE();
281	}
282
283	if (!ptest || (ptest == 8)) {
284		struct	timeval	tv;
285
286		gettimeofday(&tv, NULL);
287		srand(tv.tv_sec ^ getpid() ^ tv.tv_usec);
288		/*
289		 * Part8.1: 63k packet + 1k fragment at offset 0x1ffe
290		 * Mark it as being ICMP (so it doesn't get junked), but
291		 * don't bother about the ICMP header, we're not worrying
292		 * about that here.
293		 */
294		ip->ip_p = IPPROTO_ICMP;
295		ip->ip_off = htons(IP_MF);
296		u->uh_dport = htons(9);
297		ip->ip_id = htons(id++);
298		printf("1.8.1 63k packet + 1k fragment at offset 0x1ffe\n");
299		ip->ip_len = 768 + 20 + 8;
300		(void) send_ip(nfd, mtu, ip, gwip, 1);
301		printf("%d\r", i);
302
303		ip->ip_len = MIN(768 + 20, mtu - 68);
304		i = 512;
305		for (; i < (63 * 1024 + 768); i += 768) {
306			ip->ip_off = htons(IP_MF | (i >> 3));
307			(void) send_ip(nfd, mtu, ip, gwip, 1);
308			printf("%d\r", i);
309			fflush(stdout);
310			PAUSE();
311		}
312		ip->ip_len = 896 + 20;
313		ip->ip_off = htons(i >> 3);
314		(void) send_ip(nfd, mtu, ip, gwip, 1);
315		printf("%d\r", i);
316		putchar('\n');
317		fflush(stdout);
318
319		/*
320		 * Part8.2: 63k packet + 1k fragment at offset 0x1ffe
321		 * Mark it as being ICMP (so it doesn't get junked), but
322		 * don't bother about the ICMP header, we're not worrying
323		 * about that here.  (Lossage here)
324		 */
325		ip->ip_p = IPPROTO_ICMP;
326		ip->ip_off = htons(IP_MF);
327		u->uh_dport = htons(9);
328		ip->ip_id = htons(id++);
329		printf("1.8.2 63k packet + 1k fragment at offset 0x1ffe\n");
330		ip->ip_len = 768 + 20 + 8;
331		if ((rand() & 0x1f) != 0) {
332			(void) send_ip(nfd, mtu, ip, gwip, 1);
333			printf("%d\r", i);
334		} else
335			printf("skip 0\n");
336
337		ip->ip_len = MIN(768 + 20, mtu - 68);
338		i = 512;
339		for (; i < (63 * 1024 + 768); i += 768) {
340			ip->ip_off = htons(IP_MF | (i >> 3));
341			if ((rand() & 0x1f) != 0) {
342				(void) send_ip(nfd, mtu, ip, gwip, 1);
343				printf("%d\r", i);
344			} else
345				printf("skip %d\n", i);
346			fflush(stdout);
347			PAUSE();
348		}
349		ip->ip_len = 896 + 20;
350		ip->ip_off = htons(i >> 3);
351		if ((rand() & 0x1f) != 0) {
352			(void) send_ip(nfd, mtu, ip, gwip, 1);
353			printf("%d\r", i);
354		} else
355			printf("skip\n");
356		putchar('\n');
357		fflush(stdout);
358
359		/*
360		 * Part8.3: 33k packet - test for not dealing with -ve length
361		 * Mark it as being ICMP (so it doesn't get junked), but
362		 * don't bother about the ICMP header, we're not worrying
363		 * about that here.
364		 */
365		ip->ip_p = IPPROTO_ICMP;
366		ip->ip_off = htons(IP_MF);
367		u->uh_dport = htons(9);
368		ip->ip_id = htons(id++);
369		printf("1.8.3 33k packet\n");
370		ip->ip_len = 768 + 20 + 8;
371		(void) send_ip(nfd, mtu, ip, gwip, 1);
372		printf("%d\r", i);
373
374		ip->ip_len = MIN(768 + 20, mtu - 68);
375		i = 512;
376		for (; i < (32 * 1024 + 768); i += 768) {
377			ip->ip_off = htons(IP_MF | (i >> 3));
378			(void) send_ip(nfd, mtu, ip, gwip, 1);
379			printf("%d\r", i);
380			fflush(stdout);
381			PAUSE();
382		}
383		ip->ip_len = 896 + 20;
384		ip->ip_off = htons(i >> 3);
385		(void) send_ip(nfd, mtu, ip, gwip, 1);
386		printf("%d\r", i);
387		putchar('\n');
388		fflush(stdout);
389	}
390
391	ip->ip_len = len;
392	ip->ip_off = 0;
393	if (!ptest || (ptest == 9)) {
394		/*
395		 * Part9: off & 0x8000 == 0x8000
396		 */
397		ip->ip_id = 0;
398		ip->ip_off = htons(0x8000);
399		printf("1.9. ip_off & 0x8000 == 0x8000\n");
400		(void) send_ip(nfd, mtu, ip, gwip, 1);
401		fflush(stdout);
402		PAUSE();
403	}
404
405	ip->ip_off = 0;
406
407	if (!ptest || (ptest == 10)) {
408		/*
409		 * Part10: ttl = 255
410		 */
411		ip->ip_id = 0;
412		ip->ip_ttl = 255;
413		printf("1.10.0 ip_ttl = 255\n");
414		(void) send_ip(nfd, mtu, ip, gwip, 1);
415		fflush(stdout);
416		PAUSE();
417
418		ip->ip_ttl = 128;
419		printf("1.10.1 ip_ttl = 128\n");
420		(void) send_ip(nfd, mtu, ip, gwip, 1);
421		fflush(stdout);
422		PAUSE();
423
424		ip->ip_ttl = 0;
425		printf("1.10.2 ip_ttl = 0\n");
426		(void) send_ip(nfd, mtu, ip, gwip, 1);
427		fflush(stdout);
428		PAUSE();
429	}
430
431	(void) close(nfd);
432}
433
434
435void	ip_test2(dev, mtu, ip, gwip, ptest)
436char	*dev;
437int	mtu;
438ip_t	*ip;
439struct	in_addr	gwip;
440int	ptest;
441{
442	struct	timeval	tv;
443	int	nfd;
444	u_char	*s;
445
446	s = (u_char *)(ip + 1);
447	nfd = initdevice(dev, htons(1), 1);
448
449	ip->ip_hl = 6;
450	ip->ip_len = ip->ip_hl << 2;
451	s[IPOPT_OPTVAL] = IPOPT_NOP;
452	s++;
453	if (!ptest || (ptest == 1)) {
454		/*
455		 * Test 1: option length > packet length,
456		 *                header length == packet length
457		 */
458		s[IPOPT_OPTVAL] = IPOPT_TS;
459		s[IPOPT_OLEN] = 4;
460		s[IPOPT_OFFSET] = IPOPT_MINOFF;
461		ip->ip_p = IPPROTO_IP;
462		printf("2.1 option length > packet length\n");
463		(void) send_ip(nfd, mtu, ip, gwip, 1);
464		fflush(stdout);
465		PAUSE();
466	}
467
468	ip->ip_hl = 7;
469	ip->ip_len = ip->ip_hl << 2;
470	if (!ptest || (ptest == 1)) {
471		/*
472		 * Test 2: options have length = 0
473		 */
474		printf("2.2.1 option length = 0, RR\n");
475		s[IPOPT_OPTVAL] = IPOPT_RR;
476		s[IPOPT_OLEN] = 0;
477		(void) send_ip(nfd, mtu, ip, gwip, 1);
478		fflush(stdout);
479		PAUSE();
480
481		printf("2.2.2 option length = 0, TS\n");
482		s[IPOPT_OPTVAL] = IPOPT_TS;
483		s[IPOPT_OLEN] = 0;
484		(void) send_ip(nfd, mtu, ip, gwip, 1);
485		fflush(stdout);
486		PAUSE();
487
488		printf("2.2.3 option length = 0, SECURITY\n");
489		s[IPOPT_OPTVAL] = IPOPT_SECURITY;
490		s[IPOPT_OLEN] = 0;
491		(void) send_ip(nfd, mtu, ip, gwip, 1);
492		fflush(stdout);
493		PAUSE();
494
495		printf("2.2.4 option length = 0, LSRR\n");
496		s[IPOPT_OPTVAL] = IPOPT_LSRR;
497		s[IPOPT_OLEN] = 0;
498		(void) send_ip(nfd, mtu, ip, gwip, 1);
499		fflush(stdout);
500		PAUSE();
501
502		printf("2.2.5 option length = 0, SATID\n");
503		s[IPOPT_OPTVAL] = IPOPT_SATID;
504		s[IPOPT_OLEN] = 0;
505		(void) send_ip(nfd, mtu, ip, gwip, 1);
506		fflush(stdout);
507		PAUSE();
508
509		printf("2.2.6 option length = 0, SSRR\n");
510		s[IPOPT_OPTVAL] = IPOPT_SSRR;
511		s[IPOPT_OLEN] = 0;
512		(void) send_ip(nfd, mtu, ip, gwip, 1);
513		fflush(stdout);
514		PAUSE();
515	}
516
517	(void) close(nfd);
518}
519
520
521/*
522 * test 3 (ICMP)
523 */
524void	ip_test3(dev, mtu, ip, gwip, ptest)
525char	*dev;
526int	mtu;
527ip_t	*ip;
528struct	in_addr	gwip;
529int	ptest;
530{
531	static	int	ict1[10] = { 8, 9, 10, 13, 14, 15, 16, 17, 18, 0 };
532	static	int	ict2[8] = { 3, 9, 10, 13, 14, 17, 18, 0 };
533	struct	timeval	tv;
534	struct	icmp	*icp;
535	int	nfd, i;
536
537	ip->ip_hl = sizeof(*ip) >> 2;
538	ip->ip_v = IPVERSION;
539	ip->ip_tos = 0;
540	ip->ip_off = 0;
541	ip->ip_ttl = 60;
542	ip->ip_p = IPPROTO_ICMP;
543	ip->ip_sum = 0;
544	ip->ip_len = sizeof(*ip) + sizeof(*icp);
545	icp = (struct icmp *)((char *)ip + (ip->ip_hl << 2));
546	nfd = initdevice(dev, htons(1), 1);
547
548	if (!ptest || (ptest == 1)) {
549		/*
550		 * Type 0 - 31, 255, code = 0
551		 */
552		bzero((char *)icp, sizeof(*icp));
553		for (i = 0; i < 32; i++) {
554			icp->icmp_type = i;
555			(void) send_icmp(nfd, mtu, ip, gwip);
556			PAUSE();
557			printf("3.1.%d ICMP type %d code 0 (all 0's)\r", i, i);
558		}
559		icp->icmp_type = 255;
560		(void) send_icmp(nfd, mtu, ip, gwip);
561		PAUSE();
562		printf("3.1.%d ICMP type %d code 0 (all 0's)\r", i, 255);
563		putchar('\n');
564	}
565
566	if (!ptest || (ptest == 2)) {
567		/*
568		 * Type 3, code = 0 - 31
569		 */
570		icp->icmp_type = 3;
571		for (i = 0; i < 32; i++) {
572			icp->icmp_code = i;
573			(void) send_icmp(nfd, mtu, ip, gwip);
574			PAUSE();
575			printf("3.2.%d ICMP type 3 code %d (all 0's)\r", i, i);
576		}
577	}
578
579	if (!ptest || (ptest == 3)) {
580		/*
581		 * Type 4, code = 0,127,128,255
582		 */
583		icp->icmp_type = 4;
584		icp->icmp_code = 0;
585		(void) send_icmp(nfd, mtu, ip, gwip);
586		PAUSE();
587		printf("3.3.1 ICMP type 4 code 0 (all 0's)\r");
588		icp->icmp_code = 127;
589		(void) send_icmp(nfd, mtu, ip, gwip);
590		PAUSE();
591		printf("3.3.2 ICMP type 4 code 127 (all 0's)\r");
592		icp->icmp_code = 128;
593		(void) send_icmp(nfd, mtu, ip, gwip);
594		PAUSE();
595		printf("3.3.3 ICMP type 4 code 128 (all 0's)\r");
596		icp->icmp_code = 255;
597		(void) send_icmp(nfd, mtu, ip, gwip);
598		PAUSE();
599		printf("3.3.4 ICMP type 4 code 255 (all 0's)\r");
600	}
601
602	if (!ptest || (ptest == 4)) {
603		/*
604		 * Type 5, code = 0,127,128,255
605		 */
606		icp->icmp_type = 5;
607		icp->icmp_code = 0;
608		(void) send_icmp(nfd, mtu, ip, gwip);
609		PAUSE();
610		printf("3.4.1 ICMP type 5 code 0 (all 0's)\r");
611		icp->icmp_code = 127;
612		(void) send_icmp(nfd, mtu, ip, gwip);
613		PAUSE();
614		printf("3.4.2 ICMP type 5 code 127 (all 0's)\r");
615		icp->icmp_code = 128;
616		(void) send_icmp(nfd, mtu, ip, gwip);
617		PAUSE();
618		printf("3.4.3 ICMP type 5 code 128 (all 0's)\r");
619		icp->icmp_code = 255;
620		(void) send_icmp(nfd, mtu, ip, gwip);
621		PAUSE();
622		printf("3.4.4 ICMP type 5 code 255 (all 0's)\r");
623	}
624
625	if (!ptest || (ptest == 5)) {
626		/*
627		 * Type 8-10;13-18, code - 0,127,128,255
628		 */
629		for (i = 0; ict1[i]; i++) {
630			icp->icmp_type = ict1[i];
631			icp->icmp_code = 0;
632			(void) send_icmp(nfd, mtu, ip, gwip);
633			PAUSE();
634			printf("3.5.%d ICMP type 5 code 0 (all 0's)\r",
635				i * 4);
636			icp->icmp_code = 127;
637			(void) send_icmp(nfd, mtu, ip, gwip);
638			PAUSE();
639			printf("3.5.%d ICMP type 5 code 127 (all 0's)\r",
640				i * 4 + 1);
641			icp->icmp_code = 128;
642			(void) send_icmp(nfd, mtu, ip, gwip);
643			PAUSE();
644			printf("3.5.%d ICMP type 5 code 128 (all 0's)\r",
645				i * 4 + 2);
646			icp->icmp_code = 255;
647			(void) send_icmp(nfd, mtu, ip, gwip);
648			PAUSE();
649			printf("3.5.%d ICMP type 5 code 255 (all 0's)\r",
650				i * 4 + 3);
651		}
652		putchar('\n');
653	}
654
655	if (!ptest || (ptest == 6)) {
656		/*
657		 * Type 12, code - 0,127,128,129,255
658		 */
659		icp->icmp_type = 12;
660		icp->icmp_code = 0;
661		(void) send_icmp(nfd, mtu, ip, gwip);
662		PAUSE();
663		printf("3.6.1 ICMP type 12 code 0 (all 0's)\r");
664		icp->icmp_code = 127;
665		(void) send_icmp(nfd, mtu, ip, gwip);
666		PAUSE();
667		printf("3.6.2 ICMP type 12 code 127 (all 0's)\r");
668		icp->icmp_code = 128;
669		(void) send_icmp(nfd, mtu, ip, gwip);
670		PAUSE();
671		printf("3.6.3 ICMP type 12 code 128 (all 0's)\r");
672		icp->icmp_code = 129;
673		(void) send_icmp(nfd, mtu, ip, gwip);
674		PAUSE();
675		printf("3.6.4 ICMP type 12 code 129 (all 0's)\r");
676		icp->icmp_code = 255;
677		(void) send_icmp(nfd, mtu, ip, gwip);
678		PAUSE();
679		printf("3.6.5 ICMP type 12 code 255 (all 0's)\r");
680		putchar('\n');
681	}
682
683	if (!ptest || (ptest == 7)) {
684		/*
685		 * Type 3;9-10;13-14;17-18 - shorter packets
686		 */
687		ip->ip_len = sizeof(*ip) + sizeof(*icp) / 2;
688		for (i = 0; ict2[i]; i++) {
689			icp->icmp_type = ict1[i];
690			icp->icmp_code = 0;
691			(void) send_icmp(nfd, mtu, ip, gwip);
692			PAUSE();
693			printf("3.5.%d ICMP type %d code 0 (all 0's)\r",
694				i * 4, icp->icmp_type);
695			icp->icmp_code = 127;
696			(void) send_icmp(nfd, mtu, ip, gwip);
697			PAUSE();
698			printf("3.5.%d ICMP type %d code 127 (all 0's)\r",
699				i * 4 + 1, icp->icmp_type);
700			icp->icmp_code = 128;
701			(void) send_icmp(nfd, mtu, ip, gwip);
702			PAUSE();
703			printf("3.5.%d ICMP type %d code 128 (all 0's)\r",
704				i * 4 + 2, icp->icmp_type);
705			icp->icmp_code = 255;
706			(void) send_icmp(nfd, mtu, ip, gwip);
707			PAUSE();
708			printf("3.5.%d ICMP type %d code 127 (all 0's)\r",
709				i * 4 + 3, icp->icmp_type);
710		}
711		putchar('\n');
712	}
713}
714
715
716/* Perform test 4 (UDP) */
717
718void	ip_test4(dev, mtu, ip, gwip, ptest)
719char	*dev;
720int	mtu;
721ip_t	*ip;
722struct	in_addr	gwip;
723int	ptest;
724{
725	struct	timeval	tv;
726	udphdr_t	*u;
727	int	nfd, i;
728
729
730	ip->ip_hl = sizeof(*ip) >> 2;
731	ip->ip_v = IPVERSION;
732	ip->ip_tos = 0;
733	ip->ip_off = 0;
734	ip->ip_ttl = 60;
735	ip->ip_p = IPPROTO_UDP;
736	ip->ip_sum = 0;
737	u = (udphdr_t *)((char *)ip + (ip->ip_hl << 2));
738	u->uh_sport = htons(1);
739	u->uh_dport = htons(1);
740	u->uh_ulen = htons(sizeof(*u) + 4);
741	nfd = initdevice(dev, u->uh_sport, 1);
742
743	if (!ptest || (ptest == 1)) {
744		/*
745		 * Test 1. ulen > packet
746		 */
747		u->uh_ulen = htons(sizeof(*u) + 4);
748		ip->ip_len = (ip->ip_hl << 2) + ntohs(u->uh_ulen);
749		printf("4.1 UDP uh_ulen > packet size - short packets\n");
750		for (i = ntohs(u->uh_ulen) * 2; i > sizeof(*u) + 4; i--) {
751			u->uh_ulen = htons(i);
752			(void) send_udp(nfd, 1500, ip, gwip);
753			printf("%d\r", i);
754			fflush(stdout);
755			PAUSE();
756		}
757		putchar('\n');
758	}
759
760	if (!ptest || (ptest == 2)) {
761		/*
762		 * Test 2. ulen < packet
763		 */
764		u->uh_ulen = htons(sizeof(*u) + 4);
765		ip->ip_len = (ip->ip_hl << 2) + ntohs(u->uh_ulen);
766		printf("4.2 UDP uh_ulen < packet size - short packets\n");
767		for (i = ntohs(u->uh_ulen) * 2; i > sizeof(*u) + 4; i--) {
768			ip->ip_len = i;
769			(void) send_udp(nfd, 1500, ip, gwip);
770			printf("%d\r", i);
771			fflush(stdout);
772			PAUSE();
773		}
774		putchar('\n');
775	}
776
777	if (!ptest || (ptest == 3)) {
778		/*
779		 * Test 3: sport = 0, sport = 1, sport = 32767
780		 *         sport = 32768, sport = 65535
781		 */
782		u->uh_ulen = sizeof(*u) + 4;
783		ip->ip_len = (ip->ip_hl << 2) + ntohs(u->uh_ulen);
784		printf("4.3.1 UDP sport = 0\n");
785		u->uh_sport = 0;
786		(void) send_udp(nfd, 1500, ip, gwip);
787		printf("0\n");
788		fflush(stdout);
789		PAUSE();
790		printf("4.3.2 UDP sport = 1\n");
791		u->uh_sport = htons(1);
792		(void) send_udp(nfd, 1500, ip, gwip);
793		printf("1\n");
794		fflush(stdout);
795		PAUSE();
796		printf("4.3.3 UDP sport = 32767\n");
797		u->uh_sport = htons(32767);
798		(void) send_udp(nfd, 1500, ip, gwip);
799		printf("32767\n");
800		fflush(stdout);
801		PAUSE();
802		printf("4.3.4 UDP sport = 32768\n");
803		u->uh_sport = htons(32768);
804		(void) send_udp(nfd, 1500, ip, gwip);
805		printf("32768\n");
806		putchar('\n');
807		fflush(stdout);
808		PAUSE();
809		printf("4.3.5 UDP sport = 65535\n");
810		u->uh_sport = htons(65535);
811		(void) send_udp(nfd, 1500, ip, gwip);
812		printf("65535\n");
813		fflush(stdout);
814		PAUSE();
815	}
816
817	if (!ptest || (ptest == 4)) {
818		/*
819		 * Test 4: dport = 0, dport = 1, dport = 32767
820		 *         dport = 32768, dport = 65535
821		 */
822		u->uh_ulen = ntohs(sizeof(*u) + 4);
823		u->uh_sport = htons(1);
824		ip->ip_len = (ip->ip_hl << 2) + ntohs(u->uh_ulen);
825		printf("4.4.1 UDP dport = 0\n");
826		u->uh_dport = 0;
827		(void) send_udp(nfd, 1500, ip, gwip);
828		printf("0\n");
829		fflush(stdout);
830		PAUSE();
831		printf("4.4.2 UDP dport = 1\n");
832		u->uh_dport = htons(1);
833		(void) send_udp(nfd, 1500, ip, gwip);
834		printf("1\n");
835		fflush(stdout);
836		PAUSE();
837		printf("4.4.3 UDP dport = 32767\n");
838		u->uh_dport = htons(32767);
839		(void) send_udp(nfd, 1500, ip, gwip);
840		printf("32767\n");
841		fflush(stdout);
842		PAUSE();
843		printf("4.4.4 UDP dport = 32768\n");
844		u->uh_dport = htons(32768);
845		(void) send_udp(nfd, 1500, ip, gwip);
846		printf("32768\n");
847		fflush(stdout);
848		PAUSE();
849		printf("4.4.5 UDP dport = 65535\n");
850		u->uh_dport = htons(65535);
851		(void) send_udp(nfd, 1500, ip, gwip);
852		printf("65535\n");
853		fflush(stdout);
854		PAUSE();
855	}
856
857	if (!ptest || (ptest == 5)) {
858		/*
859		 * Test 5: sizeof(ip_t) <= MTU <= sizeof(udphdr_t) +
860		 * sizeof(ip_t)
861		 */
862		printf("4.5 UDP 20 <= MTU <= 32\n");
863		for (i = sizeof(*ip); i <= ntohs(u->uh_ulen); i++) {
864			(void) send_udp(nfd, i, ip, gwip);
865			printf("%d\r", i);
866			fflush(stdout);
867			PAUSE();
868		}
869		putchar('\n');
870	}
871}
872
873
874/* Perform test 5 (TCP) */
875
876void	ip_test5(dev, mtu, ip, gwip, ptest)
877char	*dev;
878int	mtu;
879ip_t	*ip;
880struct	in_addr	gwip;
881int	ptest;
882{
883	struct	timeval	tv;
884	tcphdr_t *t;
885	int	nfd, i;
886
887	t = (tcphdr_t *)((char *)ip + (ip->ip_hl << 2));
888#ifndef	linux
889	t->th_x2 = 0;
890#endif
891	t->th_off = 0;
892	t->th_sport = htons(1);
893	t->th_dport = htons(1);
894	t->th_win = htons(4096);
895	t->th_urp = 0;
896	t->th_sum = 0;
897	t->th_seq = htonl(1);
898	t->th_ack = 0;
899	ip->ip_len = sizeof(ip_t) + sizeof(tcphdr_t);
900	nfd = initdevice(dev, t->th_sport, 1);
901
902	if (!ptest || (ptest == 1)) {
903		/*
904		 * Test 1: flags variations, 0 - 3f
905		 */
906		t->th_off = sizeof(*t) >> 2;
907		printf("5.1 Test TCP flag combinations\n");
908		for (i = 0; i <= (TH_URG|TH_ACK|TH_PUSH|TH_RST|TH_SYN|TH_FIN);
909		     i++) {
910			t->th_flags = i;
911			(void) send_tcp(nfd, mtu, ip, gwip);
912			printf("%d\r", i);
913			fflush(stdout);
914			PAUSE();
915		}
916		putchar('\n');
917	}
918
919	if (!ptest || (ptest == 2)) {
920		t->th_flags = TH_SYN;
921		/*
922		 * Test 2: seq = 0, seq = 1, seq = 0x7fffffff, seq=0x80000000,
923		 *         seq = 0xa000000, seq = 0xffffffff
924		 */
925		printf("5.2.1 TCP seq = 0\n");
926		t->th_seq = htonl(0);
927		(void) send_tcp(nfd, mtu, ip, gwip);
928		fflush(stdout);
929		PAUSE();
930
931		printf("5.2.2 TCP seq = 1\n");
932		t->th_seq = htonl(1);
933		(void) send_tcp(nfd, mtu, ip, gwip);
934		fflush(stdout);
935		PAUSE();
936
937		printf("5.2.3 TCP seq = 0x7fffffff\n");
938		t->th_seq = htonl(0x7fffffff);
939		(void) send_tcp(nfd, mtu, ip, gwip);
940		fflush(stdout);
941		PAUSE();
942
943		printf("5.2.4 TCP seq = 0x80000000\n");
944		t->th_seq = htonl(0x80000000);
945		(void) send_tcp(nfd, mtu, ip, gwip);
946		fflush(stdout);
947		PAUSE();
948
949		printf("5.2.5 TCP seq = 0xc0000000\n");
950		t->th_seq = htonl(0xc0000000);
951		(void) send_tcp(nfd, mtu, ip, gwip);
952		fflush(stdout);
953		PAUSE();
954
955		printf("5.2.6 TCP seq = 0xffffffff\n");
956		t->th_seq = htonl(0xffffffff);
957		(void) send_tcp(nfd, mtu, ip, gwip);
958		fflush(stdout);
959		PAUSE();
960	}
961
962	if (!ptest || (ptest == 3)) {
963		t->th_flags = TH_ACK;
964		/*
965		 * Test 3: ack = 0, ack = 1, ack = 0x7fffffff, ack = 0x8000000
966		 *         ack = 0xa000000, ack = 0xffffffff
967		 */
968		printf("5.3.1 TCP ack = 0\n");
969		t->th_ack = 0;
970		(void) send_tcp(nfd, mtu, ip, gwip);
971		fflush(stdout);
972		PAUSE();
973
974		printf("5.3.2 TCP ack = 1\n");
975		t->th_ack = htonl(1);
976		(void) send_tcp(nfd, mtu, ip, gwip);
977		fflush(stdout);
978		PAUSE();
979
980		printf("5.3.3 TCP ack = 0x7fffffff\n");
981		t->th_ack = htonl(0x7fffffff);
982		(void) send_tcp(nfd, mtu, ip, gwip);
983		fflush(stdout);
984		PAUSE();
985
986		printf("5.3.4 TCP ack = 0x80000000\n");
987		t->th_ack = htonl(0x80000000);
988		(void) send_tcp(nfd, mtu, ip, gwip);
989		fflush(stdout);
990		PAUSE();
991
992		printf("5.3.5 TCP ack = 0xc0000000\n");
993		t->th_ack = htonl(0xc0000000);
994		(void) send_tcp(nfd, mtu, ip, gwip);
995		fflush(stdout);
996		PAUSE();
997
998		printf("5.3.6 TCP ack = 0xffffffff\n");
999		t->th_ack = htonl(0xffffffff);
1000		(void) send_tcp(nfd, mtu, ip, gwip);
1001		fflush(stdout);
1002		PAUSE();
1003	}
1004
1005	if (!ptest || (ptest == 4)) {
1006		t->th_flags = TH_SYN;
1007		/*
1008		 * Test 4: win = 0, win = 32768, win = 65535
1009		 */
1010		printf("5.4.1 TCP win = 0\n");
1011		t->th_seq = htonl(0);
1012		(void) send_tcp(nfd, mtu, ip, gwip);
1013		fflush(stdout);
1014		PAUSE();
1015
1016		printf("5.4.2 TCP win = 32768\n");
1017		t->th_seq = htonl(0x7fff);
1018		(void) send_tcp(nfd, mtu, ip, gwip);
1019		fflush(stdout);
1020		PAUSE();
1021
1022		printf("5.4.3 TCP win = 65535\n");
1023		t->th_win = htons(0xffff);
1024		(void) send_tcp(nfd, mtu, ip, gwip);
1025		fflush(stdout);
1026		PAUSE();
1027	}
1028
1029#if !defined(linux) && !defined(__SVR4) && !defined(__svr4__) && \
1030    !defined(__sgi)
1031	{
1032	struct tcpcb *tcbp, tcb;
1033	struct tcpiphdr ti;
1034	struct sockaddr_in sin;
1035	int fd, slen;
1036
1037	bzero((char *)&sin, sizeof(sin));
1038
1039	for (i = 1; i < 63; i++) {
1040		fd = socket(AF_INET, SOCK_STREAM, 0);
1041		bzero((char *)&sin, sizeof(sin));
1042		sin.sin_addr.s_addr = ip->ip_dst.s_addr;
1043		sin.sin_port = htons(i);
1044		sin.sin_family = AF_INET;
1045		if (!connect(fd, (struct sockaddr *)&sin, sizeof(sin)))
1046			break;
1047		close(fd);
1048	}
1049
1050	if (i == 63) {
1051		printf("Couldn't open a TCP socket between ports 1 and 63\n");
1052		printf("to host %s for test 5 and 6 - skipping.\n",
1053			inet_ntoa(ip->ip_dst));
1054		goto skip_five_and_six;
1055	}
1056
1057	bcopy((char *)ip, (char *)&ti, sizeof(*ip));
1058	t->th_dport = htons(i);
1059	slen = sizeof(sin);
1060	if (!getsockname(fd, (struct sockaddr *)&sin, &slen))
1061		t->th_sport = sin.sin_port;
1062	if (!(tcbp = find_tcp(fd, &ti))) {
1063		printf("Can't find PCB\n");
1064		goto skip_five_and_six;
1065	}
1066	KMCPY(&tcb, tcbp, sizeof(tcb));
1067	ti.ti_win = tcb.rcv_adv;
1068	ti.ti_seq = htonl(tcb.snd_nxt - 1);
1069	ti.ti_ack = tcb.rcv_nxt;
1070
1071	if (!ptest || (ptest == 5)) {
1072		/*
1073		 * Test 5: urp
1074		 */
1075		t->th_flags = TH_ACK|TH_URG;
1076		printf("5.5.1 TCP Urgent pointer, sport %hu dport %hu\n",
1077			ntohs(t->th_sport), ntohs(t->th_dport));
1078		t->th_urp = htons(1);
1079		(void) send_tcp(nfd, mtu, ip, gwip);
1080		PAUSE();
1081
1082		t->th_seq = htonl(tcb.snd_nxt);
1083		ip->ip_len = sizeof(ip_t) + sizeof(tcphdr_t) + 1;
1084		t->th_urp = htons(0x7fff);
1085		(void) send_tcp(nfd, mtu, ip, gwip);
1086		PAUSE();
1087		t->th_urp = htons(0x8000);
1088		(void) send_tcp(nfd, mtu, ip, gwip);
1089		PAUSE();
1090		t->th_urp = htons(0xffff);
1091		(void) send_tcp(nfd, mtu, ip, gwip);
1092		PAUSE();
1093		t->th_urp = 0;
1094		t->th_flags &= ~TH_URG;
1095		ip->ip_len = sizeof(ip_t) + sizeof(tcphdr_t);
1096	}
1097
1098	if (!ptest || (ptest == 6)) {
1099		/*
1100		 * Test 6: data offset, off = 0, off is inside, off is outside
1101		 */
1102		t->th_flags = TH_ACK;
1103		printf("5.6.1 TCP off = 1-15, len = 40\n");
1104		for (i = 1; i < 16; i++) {
1105			ti.ti_off = ntohs(i);
1106			(void) send_tcp(nfd, mtu, ip, gwip);
1107			printf("%d\r", i);
1108			fflush(stdout);
1109			PAUSE();
1110		}
1111		putchar('\n');
1112		ip->ip_len = sizeof(ip_t) + sizeof(tcphdr_t);
1113	}
1114
1115	(void) close(fd);
1116	}
1117skip_five_and_six:
1118#endif
1119	t->th_seq = htonl(1);
1120	t->th_ack = htonl(1);
1121	t->th_off = 0;
1122
1123	if (!ptest || (ptest == 7)) {
1124		t->th_flags = TH_SYN;
1125		/*
1126		 * Test 7: sport = 0, sport = 1, sport = 32767
1127		 *         sport = 32768, sport = 65535
1128		 */
1129		printf("5.7.1 TCP sport = 0\n");
1130		t->th_sport = 0;
1131		(void) send_tcp(nfd, mtu, ip, gwip);
1132		fflush(stdout);
1133		PAUSE();
1134
1135		printf("5.7.2 TCP sport = 1\n");
1136		t->th_sport = htons(1);
1137		(void) send_tcp(nfd, mtu, ip, gwip);
1138		fflush(stdout);
1139		PAUSE();
1140
1141		printf("5.7.3 TCP sport = 32767\n");
1142		t->th_sport = htons(32767);
1143		(void) send_tcp(nfd, mtu, ip, gwip);
1144		fflush(stdout);
1145		PAUSE();
1146
1147		printf("5.7.4 TCP sport = 32768\n");
1148		t->th_sport = htons(32768);
1149		(void) send_tcp(nfd, mtu, ip, gwip);
1150		fflush(stdout);
1151		PAUSE();
1152
1153		printf("5.7.5 TCP sport = 65535\n");
1154		t->th_sport = htons(65535);
1155		(void) send_tcp(nfd, mtu, ip, gwip);
1156		fflush(stdout);
1157		PAUSE();
1158	}
1159
1160	if (!ptest || (ptest == 8)) {
1161		t->th_sport = htons(1);
1162		t->th_flags = TH_SYN;
1163		/*
1164		 * Test 8: dport = 0, dport = 1, dport = 32767
1165		 *         dport = 32768, dport = 65535
1166		 */
1167		printf("5.8.1 TCP dport = 0\n");
1168		t->th_dport = 0;
1169		(void) send_tcp(nfd, mtu, ip, gwip);
1170		fflush(stdout);
1171		PAUSE();
1172
1173		printf("5.8.2 TCP dport = 1\n");
1174		t->th_dport = htons(1);
1175		(void) send_tcp(nfd, mtu, ip, gwip);
1176		fflush(stdout);
1177		PAUSE();
1178
1179		printf("5.8.3 TCP dport = 32767\n");
1180		t->th_dport = htons(32767);
1181		(void) send_tcp(nfd, mtu, ip, gwip);
1182		fflush(stdout);
1183		PAUSE();
1184
1185		printf("5.8.4 TCP dport = 32768\n");
1186		t->th_dport = htons(32768);
1187		(void) send_tcp(nfd, mtu, ip, gwip);
1188		fflush(stdout);
1189		PAUSE();
1190
1191		printf("5.8.5 TCP dport = 65535\n");
1192		t->th_dport = htons(65535);
1193		(void) send_tcp(nfd, mtu, ip, gwip);
1194		fflush(stdout);
1195		PAUSE();
1196	}
1197
1198	/* LAND attack - self connect, so make src & dst ip/port the same */
1199	if (!ptest || (ptest == 9)) {
1200		printf("5.9 TCP LAND attack. sport = 25, dport = 25\n");
1201		/* chose SMTP port 25 */
1202		t->th_sport = htons(25);
1203		t->th_dport = htons(25);
1204		t->th_flags = TH_SYN;
1205		ip->ip_src = ip->ip_dst;
1206		(void) send_tcp(nfd, mtu, ip, gwip);
1207		fflush(stdout);
1208		PAUSE();
1209	}
1210
1211	/* TCP options header checking */
1212	/* 0 length options, etc */
1213}
1214
1215
1216/* Perform test 6 (exhaust mbuf test) */
1217
1218void	ip_test6(dev, mtu, ip, gwip, ptest)
1219char	*dev;
1220int	mtu;
1221ip_t	*ip;
1222struct	in_addr	gwip;
1223int	ptest;
1224{
1225	struct	timeval	tv;
1226	udphdr_t *u;
1227	int	nfd, i, j, k;
1228
1229	ip->ip_v = IPVERSION;
1230	ip->ip_tos = 0;
1231	ip->ip_off = 0;
1232	ip->ip_ttl = 60;
1233	ip->ip_p = IPPROTO_UDP;
1234	ip->ip_sum = 0;
1235	u = (udphdr_t *)(ip + 1);
1236	u->uh_sport = htons(1);
1237	u->uh_dport = htons(9);
1238	u->uh_sum = 0;
1239
1240	nfd = initdevice(dev, u->uh_sport, 1);
1241	u->uh_ulen = htons(7168);
1242
1243	printf("6. Exhaustive mbuf test.\n");
1244	printf("   Send 7k packet in 768 & 128 byte fragments, 128 times.\n");
1245	printf("   Total of around 8,900 packets\n");
1246	for (i = 0; i < 128; i++) {
1247		/*
1248		 * First send the entire packet in 768 byte chunks.
1249		 */
1250		ip->ip_len = sizeof(*ip) + 768 + sizeof(*u);
1251		ip->ip_hl = sizeof(*ip) >> 2;
1252		ip->ip_off = htons(IP_MF);
1253		(void) send_ip(nfd, 1500, ip, gwip, 1);
1254		printf("%d %d\r", i, 0);
1255		fflush(stdout);
1256		PAUSE();
1257		/*
1258		 * And again using 128 byte chunks.
1259		 */
1260		ip->ip_len = sizeof(*ip) + 128 + sizeof(*u);
1261		ip->ip_off = htons(IP_MF);
1262		(void) send_ip(nfd, 1500, ip, gwip, 1);
1263		printf("%d %d\r", i, 0);
1264		fflush(stdout);
1265		PAUSE();
1266
1267		for (j = 768; j < 3584; j += 768) {
1268			ip->ip_len = sizeof(*ip) + 768;
1269			ip->ip_off = htons(IP_MF|(j>>3));
1270			(void) send_ip(nfd, 1500, ip, gwip, 1);
1271			printf("%d %d\r", i, j);
1272			fflush(stdout);
1273			PAUSE();
1274
1275			ip->ip_len = sizeof(*ip) + 128;
1276			for (k = j - 768; k < j; k += 128) {
1277				ip->ip_off = htons(IP_MF|(k>>3));
1278				(void) send_ip(nfd, 1500, ip, gwip, 1);
1279				printf("%d %d\r", i, k);
1280				fflush(stdout);
1281				PAUSE();
1282			}
1283		}
1284	}
1285	putchar('\n');
1286}
1287
1288
1289/* Perform test 7 (random packets) */
1290
1291static	u_long	tbuf[64];
1292
1293void	ip_test7(dev, mtu, ip, gwip, ptest)
1294char	*dev;
1295int	mtu;
1296ip_t	*ip;
1297struct	in_addr	gwip;
1298int	ptest;
1299{
1300	ip_t	*pip;
1301	struct	timeval	tv;
1302	int	nfd, i, j;
1303	u_char	*s;
1304
1305	nfd = initdevice(dev, 0, 1);
1306	pip = (ip_t *)tbuf;
1307
1308	srand(time(NULL) ^ (getpid() * getppid()));
1309
1310	printf("7. send 1024 random IP packets.\n");
1311
1312	for (i = 0; i < 512; i++) {
1313		for (s = (u_char *)pip, j = 0; j < sizeof(tbuf); j++, s++)
1314			*s = (rand() >> 13) & 0xff;
1315		pip->ip_v = IPVERSION;
1316		bcopy((char *)&ip->ip_dst, (char *)&pip->ip_dst,
1317		      sizeof(struct in_addr));
1318		pip->ip_sum = 0;
1319		pip->ip_len &= 0xff;
1320		(void) send_ip(nfd, mtu, pip, gwip, 0);
1321		printf("%d\r", i);
1322		fflush(stdout);
1323		PAUSE();
1324	}
1325	putchar('\n');
1326
1327	for (i = 0; i < 512; i++) {
1328		for (s = (u_char *)pip, j = 0; j < sizeof(tbuf); j++, s++)
1329			*s = (rand() >> 13) & 0xff;
1330		pip->ip_v = IPVERSION;
1331		pip->ip_off &= htons(0xc000);
1332		bcopy((char *)&ip->ip_dst, (char *)&pip->ip_dst,
1333		      sizeof(struct in_addr));
1334		pip->ip_sum = 0;
1335		pip->ip_len &= 0xff;
1336		(void) send_ip(nfd, mtu, pip, gwip, 0);
1337		printf("%d\r", i);
1338		fflush(stdout);
1339		PAUSE();
1340	}
1341	putchar('\n');
1342}
1343