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