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