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