iptests.c revision 24583
1193323Sed/*
2221345Sdim * (C)opyright 1993, 1994, 1995 by Darren Reed.
3193323Sed *
4193323Sed * This code may be freely distributed as long as it retains this notice
5193323Sed * and is not changed in any way.  The author accepts no responsibility
6193323Sed * for the use of this software.  I hate legaleese, don't you ?
7221345Sdim */
8193323Sed#if !defined(lint) && defined(LIBC_SCCS)
9193323Sedstatic	char	sccsid[] = "%W% %G% (C)1995 Darren Reed";
10221345Sdim#endif
11193323Sed#include <stdio.h>
12193323Sed#include <unistd.h>
13193323Sed#include <stdlib.h>
14193323Sed#include <string.h>
15193323Sed#include <sys/types.h>
16193323Sed#include <sys/time.h>
17193323Sed#include <sys/param.h>
18193323Sed#if !defined(solaris)
19193323Sed# define _KERNEL
20193323Sed# define KERNEL
21193323Sed# include <sys/file.h>
22198090Srdivacky# undef  _KERNEL
23198090Srdivacky# undef  KERNEL
24198090Srdivacky# include <nlist.h>
25198090Srdivacky# include <sys/user.h>
26218893Sdim# include <sys/proc.h>
27218893Sdim#endif
28202375Srdivacky#include <kvm.h>
29218893Sdim#include <sys/socket.h>
30193323Sed#include <sys/socketvar.h>
31193323Sed#ifdef sun
32193323Sed#include <sys/systm.h>
33193323Sed#include <sys/session.h>
34198090Srdivacky#endif
35221345Sdim#if BSD >= 199103
36198090Srdivacky#include <sys/sysctl.h>
37193323Sed#include <sys/filedesc.h>
38193323Sed#include <paths.h>
39193323Sed#endif
40193323Sed#include <netinet/in_systm.h>
41193323Sed#include <sys/socket.h>
42193323Sed#include <net/if.h>
43193323Sed#include <net/route.h>
44193323Sed#include <netinet/in.h>
45193323Sed#include <arpa/inet.h>
46193323Sed#include <netinet/ip.h>
47193323Sed#include <netinet/tcp.h>
48193323Sed#include <netinet/udp.h>
49193323Sed#include <netinet/ip_icmp.h>
50193323Sed#include <netinet/if_ether.h>
51218893Sdim#include <netinet/ip_var.h>
52193323Sed#include <netinet/in_pcb.h>
53221345Sdim#include <netinet/tcp_timer.h>
54221345Sdim#include <netinet/tcp_var.h>
55193323Sed# if defined(__SVR4) || defined(__svr4__)
56193323Sed#include <sys/sysmacros.h>
57193323Sed# endif
58193323Sed#include "ipsend.h"
59193323Sed
60193323Sed
61193323Sed#define	PAUSE()	tv.tv_sec = 0; tv.tv_usec = 10000; \
62205218Srdivacky		  (void) select(0, NULL, NULL, NULL, &tv)
63205218Srdivacky
64193323Sed
65193323Sedvoid	ip_test1(dev, mtu, ip, gwip, ptest)
66206083Srdivackychar	*dev;
67206083Srdivackyint	mtu;
68206083Srdivackyip_t	*ip;
69193323Sedstruct	in_addr	gwip;
70218893Sdimint	ptest;
71218893Sdim{
72193323Sed	struct	timeval	tv;
73195098Sed	udphdr_t *u;
74195098Sed	int	nfd, i, len, id = getpid();
75212904Sdim
76212904Sdim	ip->ip_hl = sizeof(*ip) >> 2;
77195098Sed	ip->ip_v = IPVERSION;
78201360Srdivacky	ip->ip_tos = 0;
79195098Sed	ip->ip_off = 0;
80195098Sed	ip->ip_ttl = 60;
81202375Srdivacky	ip->ip_p = IPPROTO_UDP;
82202375Srdivacky	ip->ip_sum = 0;
83202375Srdivacky	u = (udphdr_t *)(ip + 1);
84206124Srdivacky	u->uh_sport = 1;
85206124Srdivacky	u->uh_dport = 9;
86195098Sed	u->uh_sum = 0;
87193323Sed	u->uh_ulen = sizeof(*u) + 4;
88193323Sed	ip->ip_len = sizeof(*ip) + u->uh_ulen;
89193323Sed	len = ip->ip_len;
90193323Sed	nfd = initdevice(dev, u->uh_sport, 1);
91193323Sed
92193323Sed	u->uh_sport = htons(u->uh_sport);
93193323Sed	u->uh_dport = htons(u->uh_dport);
94193323Sed	u->uh_ulen = htons(u->uh_ulen);
95193323Sed	if (!ptest || (ptest == 1)) {
96193323Sed		/*
97193323Sed		 * Part1: hl < len
98193323Sed		 */
99193323Sed		ip->ip_id = 0;
100193323Sed		printf("1.1. sending packets with ip_hl < ip_len\n");
101198090Srdivacky		for (i = 0; i < ((sizeof(*ip) + u->uh_ulen) >> 2); i++) {
102198090Srdivacky			ip->ip_hl = i >> 2;
103193323Sed			(void) send_ip(nfd, 1500, ip, gwip, 1);
104223017Sdim			printf("%d\r", i);
105193323Sed			fflush(stdout);
106193323Sed			PAUSE();
107223017Sdim		}
108193323Sed		putchar('\n');
109193323Sed	}
110193323Sed
111193323Sed	if (!ptest || (ptest == 2)) {
112193323Sed		/*
113193323Sed		 * Part2: hl > len
114193323Sed		 */
115206124Srdivacky		ip->ip_id = 0;
116206083Srdivacky		printf("1.2. sending packets with ip_hl > ip_len\n");
117206124Srdivacky		for (; i < ((sizeof(*ip) * 2 + u->uh_ulen) >> 2); i++) {
118206083Srdivacky			ip->ip_hl = i >> 2;
119206083Srdivacky			(void) send_ip(nfd, 1500, ip, gwip, 1);
120206124Srdivacky			printf("%d\r", i);
121206124Srdivacky			fflush(stdout);
122218893Sdim			PAUSE();
123218893Sdim		}
124218893Sdim		putchar('\n');
125218893Sdim	}
126218893Sdim
127223017Sdim	if (!ptest || (ptest == 3)) {
128218893Sdim		/*
129193323Sed		 * Part3: v < 4
130193323Sed		 */
131221345Sdim		ip->ip_id = 0;
132221345Sdim		printf("1.3. ip_v < 4\n");
133221345Sdim		ip->ip_hl = sizeof(*ip) >> 2;
134221345Sdim		for (i = 0; i < 4; i++) {
135193323Sed			ip->ip_v = i;
136193323Sed			(void) send_ip(nfd, 1500, ip, gwip, 1);
137193323Sed			printf("%d\r", i);
138193323Sed			fflush(stdout);
139193323Sed			PAUSE();
140193323Sed		}
141193323Sed		putchar('\n');
142193323Sed	}
143193323Sed
144193323Sed	if (!ptest || (ptest == 4)) {
145193323Sed		/*
146193323Sed		 * Part4: v > 4
147193323Sed		 */
148193323Sed		ip->ip_id = 0;
149193323Sed		printf("1.4. ip_v > 4\n");
150193323Sed		for (i = 5; i < 16; i++) {
151193323Sed			ip->ip_v = i;
152193323Sed			(void) send_ip(nfd, 1500, ip, gwip, 1);
153193323Sed			printf("%d\r", i);
154193323Sed			fflush(stdout);
155193323Sed			PAUSE();
156195340Sed		}
157195340Sed		putchar('\n');
158195340Sed	}
159195340Sed
160193323Sed	if (!ptest || (ptest == 5)) {
161193323Sed		/*
162221345Sdim		 * Part5: len < packet
163221345Sdim		 */
164193323Sed		ip->ip_id = 0;
165193323Sed		ip->ip_v = IPVERSION;
166193323Sed		i = ip->ip_len + 1;
167193323Sed		ip->ip_len = htons(ip->ip_len);
168193323Sed		ip->ip_off = htons(ip->ip_off);
169193323Sed		printf("1.5.0 ip_len < packet size (size++, long packets)\n");
170193323Sed		for (; i < (ntohs(ip->ip_len) * 2); i++) {
171193323Sed			ip->ip_id = htons(id++);
172193323Sed			ip->ip_sum = 0;
173193323Sed			ip->ip_sum = chksum((u_short *)ip, ip->ip_hl << 2);
174193323Sed			(void) send_ether(nfd, (char *)ip, i, gwip);
175193323Sed			printf("%d\r", i);
176193323Sed			fflush(stdout);
177193323Sed			PAUSE();
178206274Srdivacky		}
179193323Sed		putchar('\n');
180193323Sed		printf("1.5.1 ip_len < packet size (ip_len-, short packets)\n");
181193323Sed		for (i = len; i > 0; i--) {
182193323Sed			ip->ip_id = htons(id++);
183193323Sed			ip->ip_len = htons(i);
184193323Sed			ip->ip_sum = 0;
185193323Sed			ip->ip_sum = chksum((u_short *)ip, ip->ip_hl << 2);
186193323Sed			(void) send_ether(nfd, (char *)ip, len, gwip);
187193323Sed			printf("%d\r", i);
188218893Sdim			fflush(stdout);
189193323Sed			PAUSE();
190193323Sed		}
191198090Srdivacky		putchar('\n');
192198090Srdivacky	}
193207631Srdivacky
194198090Srdivacky	if (!ptest || (ptest == 6)) {
195198090Srdivacky		/*
196198090Srdivacky		 * Part6: len > packet
197198090Srdivacky		 */
198198090Srdivacky		ip->ip_id = 0;
199198090Srdivacky		printf("1.6.0 ip_len > packet size (increase ip_len)\n");
200198090Srdivacky		for (i = len + 1; i < (len * 2); i++) {
201198090Srdivacky			ip->ip_id = htons(id++);
202198090Srdivacky			ip->ip_len = htons(i);
203218893Sdim			ip->ip_sum = 0;
204218893Sdim			ip->ip_sum = chksum((u_short *)ip, ip->ip_hl << 2);
205218893Sdim			(void) send_ether(nfd, (char *)ip, len, gwip);
206218893Sdim			printf("%d\r", i);
207193323Sed			fflush(stdout);
208193323Sed			PAUSE();
209193323Sed		}
210198090Srdivacky		putchar('\n');
211193323Sed		ip->ip_len = htons(len);
212218893Sdim		printf("1.6.1 ip_len > packet size (size--, short packets)\n");
213193323Sed		for (i = len; i > 0; i--) {
214193323Sed			ip->ip_id = htons(id++);
215198090Srdivacky			ip->ip_sum = 0;
216193323Sed			ip->ip_sum = chksum((u_short *)ip, ip->ip_hl << 2);
217218893Sdim			(void) send_ether(nfd, (char *)ip, i, gwip);
218193323Sed			printf("%d\r", i);
219193323Sed			fflush(stdout);
220193323Sed			PAUSE();
221193323Sed		}
222193323Sed		putchar('\n');
223193323Sed	}
224198090Srdivacky
225198090Srdivacky	if (!ptest || (ptest == 7)) {
226193323Sed		/*
227193323Sed		 * Part7: 0 length fragment
228		 */
229		printf("1.7.0 Zero length fragments (ip_off = 0x2000)\n");
230		ip->ip_id = 0;
231		ip->ip_len = sizeof(*ip);
232		ip->ip_off = htons(IP_MF);
233		(void) send_ip(nfd, mtu, ip, gwip, 1);
234		fflush(stdout);
235		PAUSE();
236
237		printf("1.7.1 Zero length fragments (ip_off = 0x3000)\n");
238		ip->ip_id = 0;
239		ip->ip_len = sizeof(*ip);
240		ip->ip_off = htons(IP_MF);
241		(void) send_ip(nfd, mtu, ip, gwip, 1);
242		fflush(stdout);
243		PAUSE();
244
245		printf("1.7.2 Zero length fragments (ip_off = 0xa000)\n");
246		ip->ip_id = 0;
247		ip->ip_len = sizeof(*ip);
248		ip->ip_off = htons(0xa000);
249		(void) send_ip(nfd, mtu, ip, gwip, 1);
250		fflush(stdout);
251		PAUSE();
252
253		printf("1.7.3 Zero length fragments (ip_off = 0x0100)\n");
254		ip->ip_id = 0;
255		ip->ip_len = sizeof(*ip);
256		ip->ip_off = htons(0x0100);
257		(void) send_ip(nfd, mtu, ip, gwip, 1);
258		fflush(stdout);
259		PAUSE();
260	}
261
262	if (!ptest || (ptest == 8)) {
263		struct	timeval	tv;
264
265		gettimeofday(&tv, NULL);
266		srand(tv.tv_sec ^ getpid() ^ tv.tv_usec);
267		/*
268		 * Part8.1: 63k packet + 1k fragment at offset 0x1ffe
269		 * Mark it as being ICMP (so it doesn't get junked), but
270		 * don't bother about the ICMP header, we're not worrying
271		 * about that here.
272		 */
273		ip->ip_p = IPPROTO_ICMP;
274		ip->ip_off = IP_MF;
275		u->uh_dport = htons(9);
276		ip->ip_id = htons(id++);
277		printf("1.8.1 63k packet + 1k fragment at offset 0x1ffe\n");
278		ip->ip_len = 768 + 20 + 8;
279		(void) send_ip(nfd, mtu, ip, gwip, 1);
280		printf("%d\r", i);
281
282		ip->ip_len = MIN(768 + 20, mtu - 68);
283		i = 512;
284		for (; i < (63 * 1024 + 768); i += 768) {
285			ip->ip_off = IP_MF | (i >> 3);
286			(void) send_ip(nfd, mtu, ip, gwip, 1);
287			printf("%d\r", i);
288			fflush(stdout);
289			PAUSE();
290		}
291		ip->ip_len = 896 + 20;
292		ip->ip_off = (i >> 3);
293		(void) send_ip(nfd, mtu, ip, gwip, 1);
294		printf("%d\r", i);
295		putchar('\n');
296		fflush(stdout);
297
298		/*
299		 * Part8.2: 63k packet + 1k fragment at offset 0x1ffe
300		 * Mark it as being ICMP (so it doesn't get junked), but
301		 * don't bother about the ICMP header, we're not worrying
302		 * about that here.  (Lossage here)
303		 */
304		ip->ip_p = IPPROTO_ICMP;
305		ip->ip_off = IP_MF;
306		u->uh_dport = htons(9);
307		ip->ip_id = htons(id++);
308		printf("1.8.2 63k packet + 1k fragment at offset 0x1ffe\n");
309		ip->ip_len = 768 + 20 + 8;
310		if ((rand() & 0x1f) != 0) {
311			(void) send_ip(nfd, mtu, ip, gwip, 1);
312			printf("%d\r", i);
313		} else
314			printf("skip 0\n");
315
316		ip->ip_len = MIN(768 + 20, mtu - 68);
317		i = 512;
318		for (; i < (63 * 1024 + 768); i += 768) {
319			ip->ip_off = IP_MF | (i >> 3);
320			if ((rand() & 0x1f) != 0) {
321				(void) send_ip(nfd, mtu, ip, gwip, 1);
322				printf("%d\r", i);
323			} else
324				printf("skip %d\n", i);
325			fflush(stdout);
326			PAUSE();
327		}
328		ip->ip_len = 896 + 20;
329		ip->ip_off = (i >> 3);
330		if ((rand() & 0x1f) != 0) {
331			(void) send_ip(nfd, mtu, ip, gwip, 1);
332			printf("%d\r", i);
333		} else
334			printf("skip\n");
335		putchar('\n');
336		fflush(stdout);
337
338		/*
339		 * Part8.3: 33k packet - test for not dealing with -ve length
340		 * Mark it as being ICMP (so it doesn't get junked), but
341		 * don't bother about the ICMP header, we're not worrying
342		 * about that here.
343		 */
344		ip->ip_p = IPPROTO_ICMP;
345		ip->ip_off = IP_MF;
346		u->uh_dport = htons(9);
347		ip->ip_id = htons(id++);
348		printf("1.8.3 33k packet\n");
349		ip->ip_len = 768 + 20 + 8;
350		(void) send_ip(nfd, mtu, ip, gwip, 1);
351		printf("%d\r", i);
352
353		ip->ip_len = MIN(768 + 20, mtu - 68);
354		i = 512;
355		for (; i < (32 * 1024 + 768); i += 768) {
356			ip->ip_off = IP_MF | (i >> 3);
357			(void) send_ip(nfd, mtu, ip, gwip, 1);
358			printf("%d\r", i);
359			fflush(stdout);
360			PAUSE();
361		}
362		ip->ip_len = 896 + 20;
363		ip->ip_off = (i >> 3);
364		(void) send_ip(nfd, mtu, ip, gwip, 1);
365		printf("%d\r", i);
366		putchar('\n');
367		fflush(stdout);
368	}
369
370	ip->ip_len = len;
371	ip->ip_off = 0;
372	if (!ptest || (ptest == 9)) {
373		/*
374		 * Part9: off & 0x8000 == 0x8000
375		 */
376		ip->ip_id = 0;
377		ip->ip_off = 0x8000;
378		printf("1.9. ip_off & 0x8000 == 0x8000\n");
379		(void) send_ip(nfd, mtu, ip, gwip, 1);
380		fflush(stdout);
381		PAUSE();
382	}
383
384	ip->ip_off = 0;
385
386	if (!ptest || (ptest == 10)) {
387		/*
388		 * Part10: ttl = 255
389		 */
390		ip->ip_id = 0;
391		ip->ip_ttl = 255;
392		printf("1.10.0 ip_ttl = 255\n");
393		(void) send_ip(nfd, mtu, ip, gwip, 1);
394		fflush(stdout);
395		PAUSE();
396
397		ip->ip_ttl = 128;
398		printf("1.10.1 ip_ttl = 128\n");
399		(void) send_ip(nfd, mtu, ip, gwip, 1);
400		fflush(stdout);
401		PAUSE();
402
403		ip->ip_ttl = 0;
404		printf("1.10.2 ip_ttl = 0\n");
405		(void) send_ip(nfd, mtu, ip, gwip, 1);
406		fflush(stdout);
407		PAUSE();
408	}
409
410	(void) close(nfd);
411}
412
413
414void	ip_test2(dev, mtu, ip, gwip, ptest)
415char	*dev;
416int	mtu;
417ip_t	*ip;
418struct	in_addr	gwip;
419int	ptest;
420{
421	struct	timeval	tv;
422	int	nfd;
423	u_char	*s;
424
425	s = (u_char *)(ip + 1);
426	nfd = initdevice(dev, 1, 1);
427
428	ip->ip_hl = 6;
429	ip->ip_len = ip->ip_hl << 2;
430	s[IPOPT_OPTVAL] = IPOPT_NOP;
431	s++;
432	if (!ptest || (ptest == 1)) {
433		/*
434		 * Test 1: option length > packet length,
435		 *                header length == packet length
436		 */
437		s[IPOPT_OPTVAL] = IPOPT_TS;
438		s[IPOPT_OLEN] = 4;
439		s[IPOPT_OFFSET] = IPOPT_MINOFF;
440		ip->ip_p = IPPROTO_IP;
441		printf("2.1 option length > packet length\n");
442		(void) send_ip(nfd, mtu, ip, gwip, 1);
443		fflush(stdout);
444		PAUSE();
445	}
446
447	ip->ip_hl = 7;
448	ip->ip_len = ip->ip_hl << 2;
449	if (!ptest || (ptest == 1)) {
450		/*
451		 * Test 2: options have length = 0
452		 */
453		printf("2.2.1 option length = 0, RR\n");
454		s[IPOPT_OPTVAL] = IPOPT_RR;
455		s[IPOPT_OLEN] = 0;
456		(void) send_ip(nfd, mtu, ip, gwip, 1);
457		fflush(stdout);
458		PAUSE();
459
460		printf("2.2.2 option length = 0, TS\n");
461		s[IPOPT_OPTVAL] = IPOPT_TS;
462		s[IPOPT_OLEN] = 0;
463		(void) send_ip(nfd, mtu, ip, gwip, 1);
464		fflush(stdout);
465		PAUSE();
466
467		printf("2.2.3 option length = 0, SECURITY\n");
468		s[IPOPT_OPTVAL] = IPOPT_SECURITY;
469		s[IPOPT_OLEN] = 0;
470		(void) send_ip(nfd, mtu, ip, gwip, 1);
471		fflush(stdout);
472		PAUSE();
473
474		printf("2.2.4 option length = 0, LSRR\n");
475		s[IPOPT_OPTVAL] = IPOPT_LSRR;
476		s[IPOPT_OLEN] = 0;
477		(void) send_ip(nfd, mtu, ip, gwip, 1);
478		fflush(stdout);
479		PAUSE();
480
481		printf("2.2.5 option length = 0, SATID\n");
482		s[IPOPT_OPTVAL] = IPOPT_SATID;
483		s[IPOPT_OLEN] = 0;
484		(void) send_ip(nfd, mtu, ip, gwip, 1);
485		fflush(stdout);
486		PAUSE();
487
488		printf("2.2.6 option length = 0, SSRR\n");
489		s[IPOPT_OPTVAL] = IPOPT_SSRR;
490		s[IPOPT_OLEN] = 0;
491		(void) send_ip(nfd, mtu, ip, gwip, 1);
492		fflush(stdout);
493		PAUSE();
494	}
495
496	(void) close(nfd);
497}
498
499
500/*
501 * test 3 (ICMP)
502 */
503void	ip_test3(dev, mtu, ip, gwip, ptest)
504char	*dev;
505int	mtu;
506ip_t	*ip;
507struct	in_addr	gwip;
508int	ptest;
509{
510	static	int	ict1[10] = { 8, 9, 10, 13, 14, 15, 16, 17, 18, 0 };
511	static	int	ict2[8] = { 3, 9, 10, 13, 14, 17, 18, 0 };
512	struct	timeval	tv;
513	struct	icmp	*icp;
514	int	nfd, i;
515
516	ip->ip_hl = sizeof(*ip) >> 2;
517	ip->ip_v = IPVERSION;
518	ip->ip_tos = 0;
519	ip->ip_off = 0;
520	ip->ip_ttl = 60;
521	ip->ip_p = IPPROTO_ICMP;
522	ip->ip_sum = 0;
523	ip->ip_len = sizeof(*ip) + sizeof(*icp);
524	icp = (struct icmp *)((char *)ip + (ip->ip_hl << 2));
525	nfd = initdevice(dev, 1, 1);
526
527	if (!ptest || (ptest == 1)) {
528		/*
529		 * Type 0 - 31, 255, code = 0
530		 */
531		bzero((char *)icp, sizeof(*icp));
532		for (i = 0; i < 32; i++) {
533			icp->icmp_type = i;
534			(void) send_icmp(nfd, mtu, ip, gwip);
535			PAUSE();
536			printf("3.1.%d ICMP type %d code 0 (all 0's)\r", i, i);
537		}
538		icp->icmp_type = 255;
539		(void) send_icmp(nfd, mtu, ip, gwip);
540		PAUSE();
541		printf("3.1.%d ICMP type %d code 0 (all 0's)\r", i, 255);
542		putchar('\n');
543	}
544
545	if (!ptest || (ptest == 2)) {
546		/*
547		 * Type 3, code = 0 - 31
548		 */
549		icp->icmp_type = 3;
550		for (i = 0; i < 32; i++) {
551			icp->icmp_code = i;
552			(void) send_icmp(nfd, mtu, ip, gwip);
553			PAUSE();
554			printf("3.2.%d ICMP type 3 code %d (all 0's)\r", i, i);
555		}
556	}
557
558	if (!ptest || (ptest == 3)) {
559		/*
560		 * Type 4, code = 0,127,128,255
561		 */
562		icp->icmp_type = 4;
563		icp->icmp_code = 0;
564		(void) send_icmp(nfd, mtu, ip, gwip);
565		PAUSE();
566		printf("3.3.1 ICMP type 4 code 0 (all 0's)\r");
567		icp->icmp_code = 127;
568		(void) send_icmp(nfd, mtu, ip, gwip);
569		PAUSE();
570		printf("3.3.2 ICMP type 4 code 127 (all 0's)\r");
571		icp->icmp_code = 128;
572		(void) send_icmp(nfd, mtu, ip, gwip);
573		PAUSE();
574		printf("3.3.3 ICMP type 4 code 128 (all 0's)\r");
575		icp->icmp_code = 255;
576		(void) send_icmp(nfd, mtu, ip, gwip);
577		PAUSE();
578		printf("3.3.4 ICMP type 4 code 255 (all 0's)\r");
579	}
580
581	if (!ptest || (ptest == 4)) {
582		/*
583		 * Type 5, code = 0,127,128,255
584		 */
585		icp->icmp_type = 5;
586		icp->icmp_code = 0;
587		(void) send_icmp(nfd, mtu, ip, gwip);
588		PAUSE();
589		printf("3.4.1 ICMP type 5 code 0 (all 0's)\r");
590		icp->icmp_code = 127;
591		(void) send_icmp(nfd, mtu, ip, gwip);
592		PAUSE();
593		printf("3.4.2 ICMP type 5 code 127 (all 0's)\r");
594		icp->icmp_code = 128;
595		(void) send_icmp(nfd, mtu, ip, gwip);
596		PAUSE();
597		printf("3.4.3 ICMP type 5 code 128 (all 0's)\r");
598		icp->icmp_code = 255;
599		(void) send_icmp(nfd, mtu, ip, gwip);
600		PAUSE();
601		printf("3.4.4 ICMP type 5 code 255 (all 0's)\r");
602	}
603
604	if (!ptest || (ptest == 5)) {
605		/*
606		 * Type 8-10;13-18, code - 0,127,128,255
607		 */
608		for (i = 0; ict1[i]; i++) {
609			icp->icmp_type = ict1[i];
610			icp->icmp_code = 0;
611			(void) send_icmp(nfd, mtu, ip, gwip);
612			PAUSE();
613			printf("3.5.%d ICMP type 5 code 0 (all 0's)\r",
614				i * 4);
615			icp->icmp_code = 127;
616			(void) send_icmp(nfd, mtu, ip, gwip);
617			PAUSE();
618			printf("3.5.%d ICMP type 5 code 127 (all 0's)\r",
619				i * 4 + 1);
620			icp->icmp_code = 128;
621			(void) send_icmp(nfd, mtu, ip, gwip);
622			PAUSE();
623			printf("3.5.%d ICMP type 5 code 128 (all 0's)\r",
624				i * 4 + 2);
625			icp->icmp_code = 255;
626			(void) send_icmp(nfd, mtu, ip, gwip);
627			PAUSE();
628			printf("3.5.%d ICMP type 5 code 255 (all 0's)\r",
629				i * 4 + 3);
630		}
631		putchar('\n');
632	}
633
634	if (!ptest || (ptest == 6)) {
635		/*
636		 * Type 12, code - 0,127,128,129,255
637		 */
638		icp->icmp_type = 12;
639		icp->icmp_code = 0;
640		(void) send_icmp(nfd, mtu, ip, gwip);
641		PAUSE();
642		printf("3.6.1 ICMP type 12 code 0 (all 0's)\r");
643		icp->icmp_code = 127;
644		(void) send_icmp(nfd, mtu, ip, gwip);
645		PAUSE();
646		printf("3.6.2 ICMP type 12 code 127 (all 0's)\r");
647		icp->icmp_code = 128;
648		(void) send_icmp(nfd, mtu, ip, gwip);
649		PAUSE();
650		printf("3.6.3 ICMP type 12 code 128 (all 0's)\r");
651		icp->icmp_code = 129;
652		(void) send_icmp(nfd, mtu, ip, gwip);
653		PAUSE();
654		printf("3.6.4 ICMP type 12 code 129 (all 0's)\r");
655		icp->icmp_code = 255;
656		(void) send_icmp(nfd, mtu, ip, gwip);
657		PAUSE();
658		printf("3.6.5 ICMP type 12 code 255 (all 0's)\r");
659		putchar('\n');
660	}
661
662	if (!ptest || (ptest == 7)) {
663		/*
664		 * Type 3;9-10;13-14;17-18 - shorter packets
665		 */
666		ip->ip_len = sizeof(*ip) + sizeof(*icp) / 2;
667		for (i = 0; ict2[i]; i++) {
668			icp->icmp_type = ict1[i];
669			icp->icmp_code = 0;
670			(void) send_icmp(nfd, mtu, ip, gwip);
671			PAUSE();
672			printf("3.5.%d ICMP type %d code 0 (all 0's)\r",
673				i * 4, icp->icmp_type);
674			icp->icmp_code = 127;
675			(void) send_icmp(nfd, mtu, ip, gwip);
676			PAUSE();
677			printf("3.5.%d ICMP type %d code 127 (all 0's)\r",
678				i * 4 + 1, icp->icmp_type);
679			icp->icmp_code = 128;
680			(void) send_icmp(nfd, mtu, ip, gwip);
681			PAUSE();
682			printf("3.5.%d ICMP type %d code 128 (all 0's)\r",
683				i * 4 + 2, icp->icmp_type);
684			icp->icmp_code = 255;
685			(void) send_icmp(nfd, mtu, ip, gwip);
686			PAUSE();
687			printf("3.5.%d ICMP type %d code 127 (all 0's)\r",
688				i * 4 + 3, icp->icmp_type);
689		}
690		putchar('\n');
691	}
692}
693
694
695/* Perform test 4 (UDP) */
696
697void	ip_test4(dev, mtu, ip, gwip, ptest)
698char	*dev;
699int	mtu;
700ip_t	*ip;
701struct	in_addr	gwip;
702int	ptest;
703{
704	struct	timeval	tv;
705	struct	udphdr	*u;
706	int	nfd, i;
707
708
709	ip->ip_hl = sizeof(*ip) >> 2;
710	ip->ip_v = IPVERSION;
711	ip->ip_tos = 0;
712	ip->ip_off = 0;
713	ip->ip_ttl = 60;
714	ip->ip_p = IPPROTO_UDP;
715	ip->ip_sum = 0;
716	u = (udphdr_t *)((char *)ip + (ip->ip_hl << 2));
717	u->uh_sport = 1;
718	u->uh_dport = 1;
719	u->uh_ulen = sizeof(*u) + 4;
720	nfd = initdevice(dev, u->uh_sport, 1);
721
722	if (!ptest || (ptest == 1)) {
723		/*
724		 * Test 1. ulen > packet
725		 */
726		u->uh_ulen = sizeof(*u) + 4;
727		ip->ip_len = (ip->ip_hl << 2) + u->uh_ulen;
728		printf("4.1 UDP uh_ulen > packet size - short packets\n");
729		for (i = u->uh_ulen * 2; i > sizeof(*u) + 4; i--) {
730			u->uh_ulen = i;
731			(void) send_udp(nfd, 1500, ip, gwip);
732			printf("%d\r", i);
733			fflush(stdout);
734			PAUSE();
735		}
736		putchar('\n');
737	}
738
739	if (!ptest || (ptest == 2)) {
740		/*
741		 * Test 2. ulen < packet
742		 */
743		u->uh_ulen = sizeof(*u) + 4;
744		ip->ip_len = (ip->ip_hl << 2) + u->uh_ulen;
745		printf("4.2 UDP uh_ulen < packet size - short packets\n");
746		for (i = u->uh_ulen * 2; i > sizeof(*u) + 4; i--) {
747			ip->ip_len = i;
748			(void) send_udp(nfd, 1500, ip, gwip);
749			printf("%d\r", i);
750			fflush(stdout);
751			PAUSE();
752		}
753		putchar('\n');
754	}
755
756	if (!ptest || (ptest == 3)) {
757		/*
758		 * Test 3: sport = 0, sport = 1, sport = 32767
759		 *         sport = 32768, sport = 65535
760		 */
761		u->uh_ulen = sizeof(*u) + 4;
762		ip->ip_len = (ip->ip_hl << 2) + u->uh_ulen;
763		printf("4.3.1 UDP sport = 0\n");
764		u->uh_sport = 0;
765		(void) send_udp(nfd, 1500, ip, gwip);
766		printf("0\n");
767		fflush(stdout);
768		PAUSE();
769		printf("4.3.2 UDP sport = 1\n");
770		u->uh_sport = 1;
771		(void) send_udp(nfd, 1500, ip, gwip);
772		printf("1\n");
773		fflush(stdout);
774		PAUSE();
775		printf("4.3.3 UDP sport = 32767\n");
776		u->uh_sport = 32767;
777		(void) send_udp(nfd, 1500, ip, gwip);
778		printf("32767\n");
779		fflush(stdout);
780		PAUSE();
781		printf("4.3.4 UDP sport = 32768\n");
782		u->uh_sport = 32768;
783		(void) send_udp(nfd, 1500, ip, gwip);
784		printf("32768\n");
785		putchar('\n');
786		fflush(stdout);
787		PAUSE();
788		printf("4.3.5 UDP sport = 65535\n");
789		u->uh_sport = 65535;
790		(void) send_udp(nfd, 1500, ip, gwip);
791		printf("65535\n");
792		fflush(stdout);
793		PAUSE();
794	}
795
796	if (!ptest || (ptest == 4)) {
797		/*
798		 * Test 4: dport = 0, dport = 1, dport = 32767
799		 *         dport = 32768, dport = 65535
800		 */
801		u->uh_ulen = sizeof(*u) + 4;
802		u->uh_sport = 1;
803		ip->ip_len = (ip->ip_hl << 2) + u->uh_ulen;
804		printf("4.4.1 UDP dport = 0\n");
805		u->uh_dport = 0;
806		(void) send_udp(nfd, 1500, ip, gwip);
807		printf("0\n");
808		fflush(stdout);
809		PAUSE();
810		printf("4.4.2 UDP dport = 1\n");
811		u->uh_dport = 1;
812		(void) send_udp(nfd, 1500, ip, gwip);
813		printf("1\n");
814		fflush(stdout);
815		PAUSE();
816		printf("4.4.3 UDP dport = 32767\n");
817		u->uh_dport = 32767;
818		(void) send_udp(nfd, 1500, ip, gwip);
819		printf("32767\n");
820		fflush(stdout);
821		PAUSE();
822		printf("4.4.4 UDP dport = 32768\n");
823		u->uh_dport = 32768;
824		(void) send_udp(nfd, 1500, ip, gwip);
825		printf("32768\n");
826		fflush(stdout);
827		PAUSE();
828		printf("4.4.5 UDP dport = 65535\n");
829		u->uh_dport = 65535;
830		(void) send_udp(nfd, 1500, ip, gwip);
831		printf("65535\n");
832		fflush(stdout);
833		PAUSE();
834	}
835
836	if (!ptest || (ptest == 4)) {
837		/*
838		 * Test 5: sizeof(struct ip) <= MTU <= sizeof(struct udphdr) +
839		 * sizeof(struct ip)
840		 */
841		printf("4.5 UDP 20 <= MTU <= 32\n");
842		for (i = sizeof(*ip); i <= u->uh_ulen; i++) {
843			(void) send_udp(nfd, i, ip, gwip);
844			printf("%d\r", i);
845			fflush(stdout);
846			PAUSE();
847		}
848		putchar('\n');
849	}
850}
851
852
853/* Perform test 5 (TCP) */
854
855void	ip_test5(dev, mtu, ip, gwip, ptest)
856char	*dev;
857int	mtu;
858ip_t	*ip;
859struct	in_addr	gwip;
860int	ptest;
861{
862	struct	timeval	tv;
863	tcphdr_t *t;
864	int	nfd, i;
865
866	t = (tcphdr_t *)((char *)ip + (ip->ip_hl << 2));
867	t->th_x2 = 0;
868	t->th_off = 0;
869	t->th_sport = 1;
870	t->th_dport = 1;
871	t->th_win = 4096;
872	t->th_urp = 0;
873	t->th_sum = 0;
874	t->th_seq = 1;
875	t->th_ack = 0;
876	nfd = initdevice(dev, t->th_sport, 1);
877
878	if (!ptest || (ptest == 1)) {
879		/*
880		 * Test 1: flags variations, 0 - 3f
881		 */
882		t->th_off = sizeof(*t) >> 2;
883		printf("5.1 Test TCP flag combinations\n");
884		for (i = 0; i <= (TH_URG|TH_ACK|TH_PUSH|TH_RST|TH_SYN|TH_FIN);
885		     i++) {
886			t->th_flags = i;
887			(void) send_tcp(nfd, mtu, ip, gwip);
888			printf("%d\r", i);
889			fflush(stdout);
890			PAUSE();
891		}
892		putchar('\n');
893	}
894
895	if (!ptest || (ptest == 2)) {
896		t->th_flags = TH_SYN;
897		/*
898		 * Test 2: seq = 0, seq = 1, seq = 0x7fffffff, seq=0x80000000,
899		 *         seq = 0xa000000, seq = 0xffffffff
900		 */
901		printf("5.2.1 TCP seq = 0\n");
902		t->th_seq = 0;
903		(void) send_tcp(nfd, mtu, ip, gwip);
904		fflush(stdout);
905		PAUSE();
906
907		printf("5.2.2 TCP seq = 1\n");
908		t->th_seq = 1;
909		(void) send_tcp(nfd, mtu, ip, gwip);
910		fflush(stdout);
911		PAUSE();
912
913		printf("5.2.3 TCP seq = 0x7fffffff\n");
914		t->th_seq = 0x7fffffff;
915		(void) send_tcp(nfd, mtu, ip, gwip);
916		fflush(stdout);
917		PAUSE();
918
919		printf("5.2.4 TCP seq = 0x80000000\n");
920		t->th_seq = 0x80000000;
921		(void) send_tcp(nfd, mtu, ip, gwip);
922		fflush(stdout);
923		PAUSE();
924
925		printf("5.2.5 TCP seq = 0xc0000000\n");
926		t->th_seq = 0xc0000000;
927		(void) send_tcp(nfd, mtu, ip, gwip);
928		fflush(stdout);
929		PAUSE();
930
931		printf("5.2.6 TCP seq = 0xffffffff\n");
932		t->th_seq = 0xffffffff;
933		(void) send_tcp(nfd, mtu, ip, gwip);
934		fflush(stdout);
935		PAUSE();
936	}
937
938	if (!ptest || (ptest == 3)) {
939		t->th_flags = TH_ACK;
940		/*
941		 * Test 3: ack = 0, ack = 1, ack = 0x7fffffff, ack = 0x8000000
942		 *         ack = 0xa000000, ack = 0xffffffff
943		 */
944		printf("5.3.1 TCP ack = 0\n");
945		t->th_ack = 0;
946		(void) send_tcp(nfd, mtu, ip, gwip);
947		fflush(stdout);
948		PAUSE();
949
950		printf("5.3.2 TCP ack = 1\n");
951		t->th_ack = 1;
952		(void) send_tcp(nfd, mtu, ip, gwip);
953		fflush(stdout);
954		PAUSE();
955
956		printf("5.3.3 TCP ack = 0x7fffffff\n");
957		t->th_ack = 0x7fffffff;
958		(void) send_tcp(nfd, mtu, ip, gwip);
959		fflush(stdout);
960		PAUSE();
961
962		printf("5.3.4 TCP ack = 0x80000000\n");
963		t->th_ack = 0x80000000;
964		(void) send_tcp(nfd, mtu, ip, gwip);
965		fflush(stdout);
966		PAUSE();
967
968		printf("5.3.5 TCP ack = 0xc0000000\n");
969		t->th_ack = 0xc0000000;
970		(void) send_tcp(nfd, mtu, ip, gwip);
971		fflush(stdout);
972		PAUSE();
973
974		printf("5.3.6 TCP ack = 0xffffffff\n");
975		t->th_ack = 0xffffffff;
976		(void) send_tcp(nfd, mtu, ip, gwip);
977		fflush(stdout);
978		PAUSE();
979	}
980
981	if (!ptest || (ptest == 4)) {
982		t->th_flags = TH_SYN;
983		/*
984		 * Test 4: win = 0, win = 32768, win = 65535
985		 */
986		printf("5.4.1 TCP win = 0\n");
987		t->th_seq = 0;
988		(void) send_tcp(nfd, mtu, ip, gwip);
989		fflush(stdout);
990		PAUSE();
991
992		printf("5.4.2 TCP win = 32768\n");
993		t->th_seq = 0x7fff;
994		(void) send_tcp(nfd, mtu, ip, gwip);
995		fflush(stdout);
996		PAUSE();
997
998		printf("5.4.3 TCP win = 65535\n");
999		t->th_win = 0xffff;
1000		(void) send_tcp(nfd, mtu, ip, gwip);
1001		fflush(stdout);
1002		PAUSE();
1003	}
1004
1005#if !defined(linux) && !defined(__SVR4) && !defined(__svr4__)
1006	{
1007	struct tcpcb *t, tcb;
1008	struct tcpiphdr ti;
1009	struct sockaddr_in sin;
1010	int fd, slen;
1011
1012	bzero((char *)&sin, sizeof(sin));
1013
1014	for (i = 1; i < 63; i++) {
1015		fd = socket(AF_INET, SOCK_STREAM, 0);
1016		sin.sin_addr.s_addr = ip->ip_dst.s_addr;
1017		sin.sin_port = htons(i);
1018		if (!connect(fd, (struct sockaddr *)&sin, sizeof(sin)))
1019			break;
1020	}
1021
1022	if (i == 63) {
1023		printf("Couldn't open a TCP socket between ports 1 and 63\n");
1024		printf("to host %s for test 5 and 6 - skipping.\n",
1025			inet_ntoa(ip->ip_dst));
1026		goto skip_five_and_six;
1027	}
1028
1029	bcopy((char *)ip, (char *)&ti, sizeof(*ip));
1030	ti.ti_dport = i;
1031	slen = sizeof(sin);
1032	if (!getsockname(fd, (struct sockaddr *)&sin, &slen))
1033		ti.ti_sport = sin.sin_port;
1034	if (!(t = find_tcp(fd, &ti))) {
1035		printf("Can't find PCB\n");
1036		goto skip_five_and_six;
1037	}
1038	KMCPY(&tcb, t, sizeof(tcb));
1039	ti.ti_win = tcb.rcv_adv;
1040	ti.ti_seq = tcb.snd_nxt - 1;
1041	ti.ti_ack = tcb.rcv_nxt;
1042
1043	if (!ptest || (ptest == 5)) {
1044		/*
1045		 * Test 5: urp
1046		 */
1047		printf("5.1 TCP Urgent pointer\n");
1048		ti.ti_urp = 1;
1049		(void) send_tcp(nfd, mtu, ip, gwip);
1050		PAUSE();
1051		ti.ti_urp = 0x7fff;
1052		(void) send_tcp(nfd, mtu, ip, gwip);
1053		PAUSE();
1054		ti.ti_urp = 0x8000;
1055		(void) send_tcp(nfd, mtu, ip, gwip);
1056		PAUSE();
1057		ti.ti_urp = 0xffff;
1058		(void) send_tcp(nfd, mtu, ip, gwip);
1059		PAUSE();
1060	}
1061
1062	if (!ptest || (ptest == 6)) {
1063		/*
1064		 * Test 6: data offset, off = 0, off is inside, off is outside
1065		 */
1066		printf("6.1 TCP off = 0-15, len = 40\n");
1067		for (i = 0; i < 16; i++) {
1068			ti.ti_off = ntohs(i);
1069			(void) send_tcp(nfd, mtu, ip, gwip);
1070			printf("%d\r", i);
1071			fflush(stdout);
1072			PAUSE();
1073		}
1074		putchar('\n');
1075	}
1076
1077	(void) close(fd);
1078	}
1079skip_five_and_six:
1080#endif
1081	t->th_seq = 1;
1082	t->th_ack = 1;
1083
1084	if (!ptest || (ptest == 7)) {
1085		t->th_off = 0;
1086		t->th_flags = TH_SYN;
1087		/*
1088		 * Test 7: sport = 0, sport = 1, sport = 32767
1089		 *         sport = 32768, sport = 65535
1090		 */
1091		printf("5.7.1 TCP sport = 0\n");
1092		t->th_sport = 0;
1093		(void) send_tcp(nfd, mtu, ip, gwip);
1094		fflush(stdout);
1095		PAUSE();
1096
1097		printf("5.7.2 TCP sport = 1\n");
1098		t->th_sport = 1;
1099		(void) send_tcp(nfd, mtu, ip, gwip);
1100		fflush(stdout);
1101		PAUSE();
1102
1103		printf("5.7.3 TCP sport = 32767\n");
1104		t->th_sport = 32767;
1105		(void) send_tcp(nfd, mtu, ip, gwip);
1106		fflush(stdout);
1107		PAUSE();
1108
1109		printf("5.7.4 TCP sport = 32768\n");
1110		t->th_sport = 32768;
1111		(void) send_tcp(nfd, mtu, ip, gwip);
1112		fflush(stdout);
1113		PAUSE();
1114
1115		printf("5.7.5 TCP sport = 65535\n");
1116		t->th_sport = 65535;
1117		(void) send_tcp(nfd, mtu, ip, gwip);
1118		fflush(stdout);
1119		PAUSE();
1120	}
1121
1122	if (!ptest || (ptest == 8)) {
1123		t->th_sport = 1;
1124		/*
1125		 * Test 8: dport = 0, dport = 1, dport = 32767
1126		 *         dport = 32768, dport = 65535
1127		 */
1128		printf("5.8.1 TCP dport = 0\n");
1129		t->th_dport = 0;
1130		(void) send_tcp(nfd, mtu, ip, gwip);
1131		fflush(stdout);
1132		PAUSE();
1133
1134		printf("5.8.2 TCP dport = 1\n");
1135		t->th_dport = 1;
1136		(void) send_tcp(nfd, mtu, ip, gwip);
1137		fflush(stdout);
1138		PAUSE();
1139
1140		printf("5.8.3 TCP dport = 32767\n");
1141		t->th_dport = 32767;
1142		(void) send_tcp(nfd, mtu, ip, gwip);
1143		fflush(stdout);
1144		PAUSE();
1145
1146		printf("5.8.4 TCP dport = 32768\n");
1147		t->th_dport = 32768;
1148		(void) send_tcp(nfd, mtu, ip, gwip);
1149		fflush(stdout);
1150		PAUSE();
1151
1152		printf("5.8.5 TCP dport = 65535\n");
1153		t->th_dport = 65535;
1154		(void) send_tcp(nfd, mtu, ip, gwip);
1155		fflush(stdout);
1156		PAUSE();
1157	}
1158	/* TCP options header checking */
1159	/* 0 length options, etc */
1160}
1161
1162
1163/* Perform test 6 (exhaust mbuf test) */
1164
1165void	ip_test6(dev, mtu, ip, gwip, ptest)
1166char	*dev;
1167int	mtu;
1168ip_t	*ip;
1169struct	in_addr	gwip;
1170int	ptest;
1171{
1172	struct	timeval	tv;
1173	udphdr_t *u;
1174	int	nfd, i, j, k;
1175
1176	ip->ip_v = IPVERSION;
1177	ip->ip_tos = 0;
1178	ip->ip_off = 0;
1179	ip->ip_ttl = 60;
1180	ip->ip_p = IPPROTO_UDP;
1181	ip->ip_sum = 0;
1182	u = (udphdr_t *)(ip + 1);
1183	u->uh_sport = 1;
1184	u->uh_dport = 9;
1185	u->uh_sum = 0;
1186
1187	nfd = initdevice(dev, u->uh_sport, 1);
1188	u->uh_sport = htons(u->uh_sport);
1189	u->uh_dport = htons(u->uh_dport);
1190	u->uh_ulen = 7168;
1191
1192	for (i = 0; i < 128; i++) {
1193		/*
1194		 * First send the entire packet in 768 byte chunks.
1195		 */
1196		ip->ip_len = sizeof(*ip) + 768 + sizeof(*u);
1197		ip->ip_hl = sizeof(*ip) >> 2;
1198		ip->ip_off = IP_MF;
1199		(void) send_ip(nfd, 1500, ip, gwip, 1);
1200		printf("%d %d\r", i, 0);
1201		fflush(stdout);
1202		PAUSE();
1203		/*
1204		 * And again using 128 byte chunks.
1205		 */
1206		ip->ip_len = sizeof(*ip) + 128 + sizeof(*u);
1207		ip->ip_off = IP_MF;
1208		(void) send_ip(nfd, 1500, ip, gwip, 1);
1209		printf("%d %d\r", i, 0);
1210		fflush(stdout);
1211		PAUSE();
1212
1213		for (j = 768; j < 3584; j += 768) {
1214			ip->ip_len = sizeof(*ip) + 768;
1215			ip->ip_off = IP_MF|(j>>3);
1216			(void) send_ip(nfd, 1500, ip, gwip, 1);
1217			printf("%d %d\r", i, j);
1218			fflush(stdout);
1219			PAUSE();
1220
1221			ip->ip_len = sizeof(*ip) + 128;
1222			for (k = j - 768; k < j; k += 128) {
1223				ip->ip_off = IP_MF|(k>>3);
1224				(void) send_ip(nfd, 1500, ip, gwip, 1);
1225				printf("%d %d\r", i, k);
1226				fflush(stdout);
1227				PAUSE();
1228			}
1229		}
1230	}
1231	putchar('\n');
1232}
1233
1234
1235/* Perform test 7 (random packets) */
1236
1237static	u_long	tbuf[64];
1238
1239void	ip_test7(dev, mtu, ip, gwip, ptest)
1240char	*dev;
1241int	mtu;
1242ip_t	*ip;
1243struct	in_addr	gwip;
1244int	ptest;
1245{
1246	ip_t	*pip;
1247	struct	timeval	tv;
1248	int	nfd, i, j;
1249	u_char	*s;
1250
1251	nfd = initdevice(dev, 0, 1);
1252	pip = (ip_t *)tbuf;
1253
1254	srand(time(NULL) ^ (getpid() * getppid()));
1255
1256	printf("7. send 1024 random IP packets.\n");
1257
1258	for (i = 0; i < 512; i++) {
1259		for (s = (u_char *)pip, j = 0; j < sizeof(tbuf); j++, s++)
1260			*s = (rand() >> 13) & 0xff;
1261		pip->ip_v = IPVERSION;
1262		bcopy((char *)&ip->ip_dst, (char *)&pip->ip_dst,
1263		      sizeof(struct in_addr));
1264		pip->ip_sum = 0;
1265		pip->ip_len &= 0xff;
1266		(void) send_ip(nfd, mtu, pip, gwip, 0);
1267		printf("%d\r", i);
1268		fflush(stdout);
1269		PAUSE();
1270	}
1271	putchar('\n');
1272
1273	for (i = 0; i < 512; i++) {
1274		for (s = (u_char *)pip, j = 0; j < sizeof(tbuf); j++, s++)
1275			*s = (rand() >> 13) & 0xff;
1276		pip->ip_v = IPVERSION;
1277		pip->ip_off &= 0xc000;
1278		bcopy((char *)&ip->ip_dst, (char *)&pip->ip_dst,
1279		      sizeof(struct in_addr));
1280		pip->ip_sum = 0;
1281		pip->ip_len &= 0xff;
1282		(void) send_ip(nfd, mtu, pip, gwip, 0);
1283		printf("%d\r", i);
1284		fflush(stdout);
1285		PAUSE();
1286	}
1287	putchar('\n');
1288}
1289