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