iptests.c (34739) | iptests.c (37074) |
---|---|
1/* 2 * Copyright (C) 1993-1997 by Darren Reed. 3 * 4 * Redistribution and use in source and binary forms are permitted 5 * provided that this notice is preserved and due credit is given 6 * to the original author and the contributors. 7 */ 8#if !defined(lint) 9static const char sccsid[] = "%W% %G% (C)1995 Darren Reed"; | 1/* 2 * Copyright (C) 1993-1997 by Darren Reed. 3 * 4 * Redistribution and use in source and binary forms are permitted 5 * provided that this notice is preserved and due credit is given 6 * to the original author and the contributors. 7 */ 8#if !defined(lint) 9static const char sccsid[] = "%W% %G% (C)1995 Darren Reed"; |
10static const char rcsid[] = "@(#)$Id: iptests.c,v 2.0.2.13.2.1 1997/11/28 03:37:10 darrenr Exp $"; | 10static const char rcsid[] = "@(#)$Id: iptests.c,v 2.0.2.13.2.2 1997/12/21 12:17:38 darrenr Exp $"; |
11#endif 12#include <stdio.h> 13#include <unistd.h> 14#include <stdlib.h> 15#include <string.h> 16#include <sys/types.h> 17#include <sys/time.h> 18#include <sys/param.h> --- 74 unchanged lines hidden (view full) --- 93 ip->ip_hl = sizeof(*ip) >> 2; 94 ip->ip_v = IPVERSION; 95 ip->ip_tos = 0; 96 ip->ip_off = 0; 97 ip->ip_ttl = 60; 98 ip->ip_p = IPPROTO_UDP; 99 ip->ip_sum = 0; 100 u = (udphdr_t *)(ip + 1); | 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> --- 74 unchanged lines hidden (view full) --- 93 ip->ip_hl = sizeof(*ip) >> 2; 94 ip->ip_v = IPVERSION; 95 ip->ip_tos = 0; 96 ip->ip_off = 0; 97 ip->ip_ttl = 60; 98 ip->ip_p = IPPROTO_UDP; 99 ip->ip_sum = 0; 100 u = (udphdr_t *)(ip + 1); |
101 u->uh_sport = 1; 102 u->uh_dport = 9; | 101 u->uh_sport = htons(1); 102 u->uh_dport = htons(9); |
103 u->uh_sum = 0; | 103 u->uh_sum = 0; |
104 u->uh_ulen = sizeof(*u) + 4; 105 ip->ip_len = sizeof(*ip) + u->uh_ulen; | 104 u->uh_ulen = htons(sizeof(*u) + 4); 105 ip->ip_len = sizeof(*ip) + ntohs(u->uh_ulen); |
106 len = ip->ip_len; 107 nfd = initdevice(dev, u->uh_sport, 1); 108 | 106 len = ip->ip_len; 107 nfd = initdevice(dev, u->uh_sport, 1); 108 |
109 u->uh_sport = htons(u->uh_sport); 110 u->uh_dport = htons(u->uh_dport); 111 u->uh_ulen = htons(u->uh_ulen); | |
112 if (!ptest || (ptest == 1)) { 113 /* 114 * Part1: hl < len 115 */ 116 ip->ip_id = 0; 117 printf("1.1. sending packets with ip_hl < ip_len\n"); | 109 if (!ptest || (ptest == 1)) { 110 /* 111 * Part1: hl < len 112 */ 113 ip->ip_id = 0; 114 printf("1.1. sending packets with ip_hl < ip_len\n"); |
118 for (i = 0; i < ((sizeof(*ip) + u->uh_ulen) >> 2); i++) { | 115 for (i = 0; i < ((sizeof(*ip) + ntohs(u->uh_ulen)) >> 2); i++) { |
119 ip->ip_hl = i >> 2; 120 (void) send_ip(nfd, 1500, ip, gwip, 1); 121 printf("%d\r", i); 122 fflush(stdout); 123 PAUSE(); 124 } 125 putchar('\n'); 126 } 127 128 if (!ptest || (ptest == 2)) { 129 /* 130 * Part2: hl > len 131 */ 132 ip->ip_id = 0; 133 printf("1.2. sending packets with ip_hl > ip_len\n"); | 116 ip->ip_hl = i >> 2; 117 (void) send_ip(nfd, 1500, ip, gwip, 1); 118 printf("%d\r", i); 119 fflush(stdout); 120 PAUSE(); 121 } 122 putchar('\n'); 123 } 124 125 if (!ptest || (ptest == 2)) { 126 /* 127 * Part2: hl > len 128 */ 129 ip->ip_id = 0; 130 printf("1.2. sending packets with ip_hl > ip_len\n"); |
134 for (; i < ((sizeof(*ip) * 2 + u->uh_ulen) >> 2); i++) { | 131 for (; i < ((sizeof(*ip) * 2 + ntohs(u->uh_ulen)) >> 2); i++) { |
135 ip->ip_hl = i >> 2; 136 (void) send_ip(nfd, 1500, ip, gwip, 1); 137 printf("%d\r", i); 138 fflush(stdout); 139 PAUSE(); 140 } 141 putchar('\n'); 142 } --- 33 unchanged lines hidden (view full) --- 176 177 if (!ptest || (ptest == 5)) { 178 /* 179 * Part5: len < packet 180 */ 181 ip->ip_id = 0; 182 ip->ip_v = IPVERSION; 183 i = ip->ip_len + 1; | 132 ip->ip_hl = i >> 2; 133 (void) send_ip(nfd, 1500, ip, gwip, 1); 134 printf("%d\r", i); 135 fflush(stdout); 136 PAUSE(); 137 } 138 putchar('\n'); 139 } --- 33 unchanged lines hidden (view full) --- 173 174 if (!ptest || (ptest == 5)) { 175 /* 176 * Part5: len < packet 177 */ 178 ip->ip_id = 0; 179 ip->ip_v = IPVERSION; 180 i = ip->ip_len + 1; |
184 ip->ip_len = htons(ip->ip_len); 185 ip->ip_off = htons(ip->ip_off); | |
186 printf("1.5.0 ip_len < packet size (size++, long packets)\n"); | 181 printf("1.5.0 ip_len < packet size (size++, long packets)\n"); |
187 for (; i < (ntohs(ip->ip_len) * 2); i++) { | 182 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++); | 183 ip->ip_id = htons(id++); 184 ip->ip_sum = 0; 185 ip->ip_sum = chksum((u_short *)ip, ip->ip_hl << 2); 186 (void) send_ether(nfd, (char *)ip, i, gwip); 187 printf("%d\r", i); 188 fflush(stdout); 189 PAUSE(); 190 } 191 putchar('\n'); 192 printf("1.5.1 ip_len < packet size (ip_len-, short packets)\n"); 193 for (i = len; i > 0; i--) { 194 ip->ip_id = htons(id++); |
200 ip->ip_len = htons(i); | 195 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++); | 196 ip->ip_sum = 0; 197 ip->ip_sum = chksum((u_short *)ip, ip->ip_hl << 2); 198 (void) send_ether(nfd, (char *)ip, len, gwip); 199 printf("%d\r", i); 200 fflush(stdout); 201 PAUSE(); 202 } 203 putchar('\n'); 204 } 205 206 if (!ptest || (ptest == 6)) { 207 /* 208 * Part6: len > packet 209 */ 210 ip->ip_id = 0; 211 printf("1.6.0 ip_len > packet size (increase ip_len)\n"); 212 for (i = len + 1; i < (len * 2); i++) { 213 ip->ip_id = htons(id++); |
219 ip->ip_len = htons(i); | 214 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'); | 215 ip->ip_sum = 0; 216 ip->ip_sum = chksum((u_short *)ip, ip->ip_hl << 2); 217 (void) send_ether(nfd, (char *)ip, len, gwip); 218 printf("%d\r", i); 219 fflush(stdout); 220 PAUSE(); 221 } 222 putchar('\n'); |
228 ip->ip_len = htons(len); | 223 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); --- 46 unchanged lines hidden (view full) --- 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; | 224 printf("1.6.1 ip_len > packet size (size--, short packets)\n"); 225 for (i = len; i > 0; i--) { 226 ip->ip_id = htons(id++); 227 ip->ip_sum = 0; 228 ip->ip_sum = chksum((u_short *)ip, ip->ip_hl << 2); 229 (void) send_ether(nfd, (char *)ip, i, gwip); 230 printf("%d\r", i); 231 fflush(stdout); --- 46 unchanged lines hidden (view full) --- 278 srand(tv.tv_sec ^ getpid() ^ tv.tv_usec); 279 /* 280 * Part8.1: 63k packet + 1k fragment at offset 0x1ffe 281 * Mark it as being ICMP (so it doesn't get junked), but 282 * don't bother about the ICMP header, we're not worrying 283 * about that here. 284 */ 285 ip->ip_p = IPPROTO_ICMP; |
291 ip->ip_off = IP_MF; | 286 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) { | 287 u->uh_dport = htons(9); 288 ip->ip_id = htons(id++); 289 printf("1.8.1 63k packet + 1k fragment at offset 0x1ffe\n"); 290 ip->ip_len = 768 + 20 + 8; 291 (void) send_ip(nfd, mtu, ip, gwip, 1); 292 printf("%d\r", i); 293 294 ip->ip_len = MIN(768 + 20, mtu - 68); 295 i = 512; 296 for (; i < (63 * 1024 + 768); i += 768) { |
302 ip->ip_off = IP_MF | (i >> 3); | 297 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; | 298 (void) send_ip(nfd, mtu, ip, gwip, 1); 299 printf("%d\r", i); 300 fflush(stdout); 301 PAUSE(); 302 } 303 ip->ip_len = 896 + 20; |
309 ip->ip_off = (i >> 3); | 304 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; | 305 (void) send_ip(nfd, mtu, ip, gwip, 1); 306 printf("%d\r", i); 307 putchar('\n'); 308 fflush(stdout); 309 310 /* 311 * Part8.2: 63k packet + 1k fragment at offset 0x1ffe 312 * Mark it as being ICMP (so it doesn't get junked), but 313 * don't bother about the ICMP header, we're not worrying 314 * about that here. (Lossage here) 315 */ 316 ip->ip_p = IPPROTO_ICMP; |
322 ip->ip_off = IP_MF; | 317 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) { | 318 u->uh_dport = htons(9); 319 ip->ip_id = htons(id++); 320 printf("1.8.2 63k packet + 1k fragment at offset 0x1ffe\n"); 321 ip->ip_len = 768 + 20 + 8; 322 if ((rand() & 0x1f) != 0) { 323 (void) send_ip(nfd, mtu, ip, gwip, 1); 324 printf("%d\r", i); 325 } else 326 printf("skip 0\n"); 327 328 ip->ip_len = MIN(768 + 20, mtu - 68); 329 i = 512; 330 for (; i < (63 * 1024 + 768); i += 768) { |
336 ip->ip_off = IP_MF | (i >> 3); | 331 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; | 332 if ((rand() & 0x1f) != 0) { 333 (void) send_ip(nfd, mtu, ip, gwip, 1); 334 printf("%d\r", i); 335 } else 336 printf("skip %d\n", i); 337 fflush(stdout); 338 PAUSE(); 339 } 340 ip->ip_len = 896 + 20; |
346 ip->ip_off = (i >> 3); | 341 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; | 342 if ((rand() & 0x1f) != 0) { 343 (void) send_ip(nfd, mtu, ip, gwip, 1); 344 printf("%d\r", i); 345 } else 346 printf("skip\n"); 347 putchar('\n'); 348 fflush(stdout); 349 350 /* 351 * Part8.3: 33k packet - test for not dealing with -ve length 352 * Mark it as being ICMP (so it doesn't get junked), but 353 * don't bother about the ICMP header, we're not worrying 354 * about that here. 355 */ 356 ip->ip_p = IPPROTO_ICMP; |
362 ip->ip_off = IP_MF; | 357 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) { | 358 u->uh_dport = htons(9); 359 ip->ip_id = htons(id++); 360 printf("1.8.3 33k packet\n"); 361 ip->ip_len = 768 + 20 + 8; 362 (void) send_ip(nfd, mtu, ip, gwip, 1); 363 printf("%d\r", i); 364 365 ip->ip_len = MIN(768 + 20, mtu - 68); 366 i = 512; 367 for (; i < (32 * 1024 + 768); i += 768) { |
373 ip->ip_off = IP_MF | (i >> 3); | 368 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; | 369 (void) send_ip(nfd, mtu, ip, gwip, 1); 370 printf("%d\r", i); 371 fflush(stdout); 372 PAUSE(); 373 } 374 ip->ip_len = 896 + 20; |
380 ip->ip_off = (i >> 3); | 375 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; | 376 (void) send_ip(nfd, mtu, ip, gwip, 1); 377 printf("%d\r", i); 378 putchar('\n'); 379 fflush(stdout); 380 } 381 382 ip->ip_len = len; 383 ip->ip_off = 0; 384 if (!ptest || (ptest == 9)) { 385 /* 386 * Part9: off & 0x8000 == 0x8000 387 */ 388 ip->ip_id = 0; |
394 ip->ip_off = 0x8000; | 389 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 --- 32 unchanged lines hidden (view full) --- 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); | 390 printf("1.9. ip_off & 0x8000 == 0x8000\n"); 391 (void) send_ip(nfd, mtu, ip, gwip, 1); 392 fflush(stdout); 393 PAUSE(); 394 } 395 396 ip->ip_off = 0; 397 --- 32 unchanged lines hidden (view full) --- 430struct in_addr gwip; 431int ptest; 432{ 433 struct timeval tv; 434 int nfd; 435 u_char *s; 436 437 s = (u_char *)(ip + 1); |
443 nfd = initdevice(dev, 1, 1); | 438 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, --- 82 unchanged lines hidden (view full) --- 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)); | 439 440 ip->ip_hl = 6; 441 ip->ip_len = ip->ip_hl << 2; 442 s[IPOPT_OPTVAL] = IPOPT_NOP; 443 s++; 444 if (!ptest || (ptest == 1)) { 445 /* 446 * Test 1: option length > packet length, --- 82 unchanged lines hidden (view full) --- 529 ip->ip_v = IPVERSION; 530 ip->ip_tos = 0; 531 ip->ip_off = 0; 532 ip->ip_ttl = 60; 533 ip->ip_p = IPPROTO_ICMP; 534 ip->ip_sum = 0; 535 ip->ip_len = sizeof(*ip) + sizeof(*icp); 536 icp = (struct icmp *)((char *)ip + (ip->ip_hl << 2)); |
542 nfd = initdevice(dev, 1, 1); | 537 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; --- 175 unchanged lines hidden (view full) --- 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)); | 538 539 if (!ptest || (ptest == 1)) { 540 /* 541 * Type 0 - 31, 255, code = 0 542 */ 543 bzero((char *)icp, sizeof(*icp)); 544 for (i = 0; i < 32; i++) { 545 icp->icmp_type = i; --- 175 unchanged lines hidden (view full) --- 721 ip->ip_hl = sizeof(*ip) >> 2; 722 ip->ip_v = IPVERSION; 723 ip->ip_tos = 0; 724 ip->ip_off = 0; 725 ip->ip_ttl = 60; 726 ip->ip_p = IPPROTO_UDP; 727 ip->ip_sum = 0; 728 u = (udphdr_t *)((char *)ip + (ip->ip_hl << 2)); |
734 u->uh_sport = 1; 735 u->uh_dport = 1; 736 u->uh_ulen = sizeof(*u) + 4; | 729 u->uh_sport = htons(1); 730 u->uh_dport = htons(1); 731 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 */ | 732 nfd = initdevice(dev, u->uh_sport, 1); 733 734 if (!ptest || (ptest == 1)) { 735 /* 736 * Test 1. ulen > packet 737 */ |
743 u->uh_ulen = sizeof(*u) + 4; 744 ip->ip_len = (ip->ip_hl << 2) + u->uh_ulen; | 738 u->uh_ulen = htons(sizeof(*u) + 4); 739 ip->ip_len = (ip->ip_hl << 2) + ntohs(u->uh_ulen); |
745 printf("4.1 UDP uh_ulen > packet size - short packets\n"); | 740 printf("4.1 UDP uh_ulen > packet size - short packets\n"); |
746 for (i = u->uh_ulen * 2; i > sizeof(*u) + 4; i--) { 747 u->uh_ulen = i; | 741 for (i = ntohs(u->uh_ulen) * 2; i > sizeof(*u) + 4; i--) { 742 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 */ | 743 (void) send_udp(nfd, 1500, ip, gwip); 744 printf("%d\r", i); 745 fflush(stdout); 746 PAUSE(); 747 } 748 putchar('\n'); 749 } 750 751 if (!ptest || (ptest == 2)) { 752 /* 753 * Test 2. ulen < packet 754 */ |
760 u->uh_ulen = sizeof(*u) + 4; 761 ip->ip_len = (ip->ip_hl << 2) + u->uh_ulen; | 755 u->uh_ulen = htons(sizeof(*u) + 4); 756 ip->ip_len = (ip->ip_hl << 2) + ntohs(u->uh_ulen); |
762 printf("4.2 UDP uh_ulen < packet size - short packets\n"); | 757 printf("4.2 UDP uh_ulen < packet size - short packets\n"); |
763 for (i = u->uh_ulen * 2; i > sizeof(*u) + 4; i--) { | 758 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; | 759 ip->ip_len = i; 760 (void) send_udp(nfd, 1500, ip, gwip); 761 printf("%d\r", i); 762 fflush(stdout); 763 PAUSE(); 764 } 765 putchar('\n'); 766 } 767 768 if (!ptest || (ptest == 3)) { 769 /* 770 * Test 3: sport = 0, sport = 1, sport = 32767 771 * sport = 32768, sport = 65535 772 */ 773 u->uh_ulen = sizeof(*u) + 4; |
779 ip->ip_len = (ip->ip_hl << 2) + u->uh_ulen; | 774 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"); | 775 printf("4.3.1 UDP sport = 0\n"); 776 u->uh_sport = 0; 777 (void) send_udp(nfd, 1500, ip, gwip); 778 printf("0\n"); 779 fflush(stdout); 780 PAUSE(); 781 printf("4.3.2 UDP sport = 1\n"); |
787 u->uh_sport = 1; | 782 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"); | 783 (void) send_udp(nfd, 1500, ip, gwip); 784 printf("1\n"); 785 fflush(stdout); 786 PAUSE(); 787 printf("4.3.3 UDP sport = 32767\n"); |
793 u->uh_sport = 32767; | 788 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"); | 789 (void) send_udp(nfd, 1500, ip, gwip); 790 printf("32767\n"); 791 fflush(stdout); 792 PAUSE(); 793 printf("4.3.4 UDP sport = 32768\n"); |
799 u->uh_sport = 32768; | 794 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"); | 795 (void) send_udp(nfd, 1500, ip, gwip); 796 printf("32768\n"); 797 putchar('\n'); 798 fflush(stdout); 799 PAUSE(); 800 printf("4.3.5 UDP sport = 65535\n"); |
806 u->uh_sport = 65535; | 801 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 */ | 802 (void) send_udp(nfd, 1500, ip, gwip); 803 printf("65535\n"); 804 fflush(stdout); 805 PAUSE(); 806 } 807 808 if (!ptest || (ptest == 4)) { 809 /* 810 * Test 4: dport = 0, dport = 1, dport = 32767 811 * dport = 32768, dport = 65535 812 */ |
818 u->uh_ulen = sizeof(*u) + 4; 819 u->uh_sport = 1; 820 ip->ip_len = (ip->ip_hl << 2) + u->uh_ulen; | 813 u->uh_ulen = ntohs(sizeof(*u) + 4); 814 u->uh_sport = htons(1); 815 ip->ip_len = (ip->ip_hl << 2) + ntohs(u->uh_ulen); |
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"); | 816 printf("4.4.1 UDP dport = 0\n"); 817 u->uh_dport = 0; 818 (void) send_udp(nfd, 1500, ip, gwip); 819 printf("0\n"); 820 fflush(stdout); 821 PAUSE(); 822 printf("4.4.2 UDP dport = 1\n"); |
828 u->uh_dport = 1; | 823 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"); | 824 (void) send_udp(nfd, 1500, ip, gwip); 825 printf("1\n"); 826 fflush(stdout); 827 PAUSE(); 828 printf("4.4.3 UDP dport = 32767\n"); |
834 u->uh_dport = 32767; | 829 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"); | 830 (void) send_udp(nfd, 1500, ip, gwip); 831 printf("32767\n"); 832 fflush(stdout); 833 PAUSE(); 834 printf("4.4.4 UDP dport = 32768\n"); |
840 u->uh_dport = 32768; | 835 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"); | 836 (void) send_udp(nfd, 1500, ip, gwip); 837 printf("32768\n"); 838 fflush(stdout); 839 PAUSE(); 840 printf("4.4.5 UDP dport = 65535\n"); |
846 u->uh_dport = 65535; | 841 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"); | 842 (void) send_udp(nfd, 1500, ip, gwip); 843 printf("65535\n"); 844 fflush(stdout); 845 PAUSE(); 846 } 847 848 if (!ptest || (ptest == 5)) { 849 /* 850 * Test 5: sizeof(ip_t) <= MTU <= sizeof(udphdr_t) + 851 * sizeof(ip_t) 852 */ 853 printf("4.5 UDP 20 <= MTU <= 32\n"); |
859 for (i = sizeof(*ip); i <= u->uh_ulen; i++) { | 854 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} --- 12 unchanged lines hidden (view full) --- 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; | 855 (void) send_udp(nfd, i, ip, gwip); 856 printf("%d\r", i); 857 fflush(stdout); 858 PAUSE(); 859 } 860 putchar('\n'); 861 } 862} --- 12 unchanged lines hidden (view full) --- 875 tcphdr_t *t; 876 int nfd, i; 877 878 t = (tcphdr_t *)((char *)ip + (ip->ip_hl << 2)); 879#ifndef linux 880 t->th_x2 = 0; 881#endif 882 t->th_off = 0; |
888 t->th_sport = 1; 889 t->th_dport = 1; 890 t->th_win = 4096; | 883 t->th_sport = htons(1); 884 t->th_dport = htons(1); 885 t->th_win = htons(4096); |
891 t->th_urp = 0; 892 t->th_sum = 0; | 886 t->th_urp = 0; 887 t->th_sum = 0; |
893 t->th_seq = 1; | 888 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 */ --- 12 unchanged lines hidden (view full) --- 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"); | 889 t->th_ack = 0; 890 ip->ip_len = sizeof(ip_t) + sizeof(tcphdr_t); 891 nfd = initdevice(dev, t->th_sport, 1); 892 893 if (!ptest || (ptest == 1)) { 894 /* 895 * Test 1: flags variations, 0 - 3f 896 */ --- 12 unchanged lines hidden (view full) --- 909 910 if (!ptest || (ptest == 2)) { 911 t->th_flags = TH_SYN; 912 /* 913 * Test 2: seq = 0, seq = 1, seq = 0x7fffffff, seq=0x80000000, 914 * seq = 0xa000000, seq = 0xffffffff 915 */ 916 printf("5.2.1 TCP seq = 0\n"); |
922 t->th_seq = 0; | 917 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"); | 918 (void) send_tcp(nfd, mtu, ip, gwip); 919 fflush(stdout); 920 PAUSE(); 921 922 printf("5.2.2 TCP seq = 1\n"); |
928 t->th_seq = 1; | 923 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"); | 924 (void) send_tcp(nfd, mtu, ip, gwip); 925 fflush(stdout); 926 PAUSE(); 927 928 printf("5.2.3 TCP seq = 0x7fffffff\n"); |
934 t->th_seq = 0x7fffffff; | 929 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"); | 930 (void) send_tcp(nfd, mtu, ip, gwip); 931 fflush(stdout); 932 PAUSE(); 933 934 printf("5.2.4 TCP seq = 0x80000000\n"); |
940 t->th_seq = 0x80000000; | 935 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"); | 936 (void) send_tcp(nfd, mtu, ip, gwip); 937 fflush(stdout); 938 PAUSE(); 939 940 printf("5.2.5 TCP seq = 0xc0000000\n"); |
946 t->th_seq = 0xc0000000; | 941 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"); | 942 (void) send_tcp(nfd, mtu, ip, gwip); 943 fflush(stdout); 944 PAUSE(); 945 946 printf("5.2.6 TCP seq = 0xffffffff\n"); |
952 t->th_seq = 0xffffffff; | 947 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"); | 948 (void) send_tcp(nfd, mtu, ip, gwip); 949 fflush(stdout); 950 PAUSE(); 951 } 952 953 if (!ptest || (ptest == 3)) { 954 t->th_flags = TH_ACK; 955 /* 956 * Test 3: ack = 0, ack = 1, ack = 0x7fffffff, ack = 0x8000000 957 * ack = 0xa000000, ack = 0xffffffff 958 */ 959 printf("5.3.1 TCP ack = 0\n"); 960 t->th_ack = 0; 961 (void) send_tcp(nfd, mtu, ip, gwip); 962 fflush(stdout); 963 PAUSE(); 964 965 printf("5.3.2 TCP ack = 1\n"); |
971 t->th_ack = 1; | 966 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"); | 967 (void) send_tcp(nfd, mtu, ip, gwip); 968 fflush(stdout); 969 PAUSE(); 970 971 printf("5.3.3 TCP ack = 0x7fffffff\n"); |
977 t->th_ack = 0x7fffffff; | 972 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"); | 973 (void) send_tcp(nfd, mtu, ip, gwip); 974 fflush(stdout); 975 PAUSE(); 976 977 printf("5.3.4 TCP ack = 0x80000000\n"); |
983 t->th_ack = 0x80000000; | 978 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"); | 979 (void) send_tcp(nfd, mtu, ip, gwip); 980 fflush(stdout); 981 PAUSE(); 982 983 printf("5.3.5 TCP ack = 0xc0000000\n"); |
989 t->th_ack = 0xc0000000; | 984 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"); | 985 (void) send_tcp(nfd, mtu, ip, gwip); 986 fflush(stdout); 987 PAUSE(); 988 989 printf("5.3.6 TCP ack = 0xffffffff\n"); |
995 t->th_ack = 0xffffffff; | 990 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"); | 991 (void) send_tcp(nfd, mtu, ip, gwip); 992 fflush(stdout); 993 PAUSE(); 994 } 995 996 if (!ptest || (ptest == 4)) { 997 t->th_flags = TH_SYN; 998 /* 999 * Test 4: win = 0, win = 32768, win = 65535 1000 */ 1001 printf("5.4.1 TCP win = 0\n"); |
1007 t->th_seq = 0; | 1002 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"); | 1003 (void) send_tcp(nfd, mtu, ip, gwip); 1004 fflush(stdout); 1005 PAUSE(); 1006 1007 printf("5.4.2 TCP win = 32768\n"); |
1013 t->th_seq = 0x7fff; | 1008 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"); | 1009 (void) send_tcp(nfd, mtu, ip, gwip); 1010 fflush(stdout); 1011 PAUSE(); 1012 1013 printf("5.4.3 TCP win = 65535\n"); |
1019 t->th_win = 0xffff; | 1014 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 { --- 28 unchanged lines hidden (view full) --- 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; | 1015 (void) send_tcp(nfd, mtu, ip, gwip); 1016 fflush(stdout); 1017 PAUSE(); 1018 } 1019 1020#if !defined(linux) && !defined(__SVR4) && !defined(__svr4__) && \ 1021 !defined(__sgi) 1022 { --- 28 unchanged lines hidden (view full) --- 1051 if (!getsockname(fd, (struct sockaddr *)&sin, &slen)) 1052 t->th_sport = sin.sin_port; 1053 if (!(tcbp = find_tcp(fd, &ti))) { 1054 printf("Can't find PCB\n"); 1055 goto skip_five_and_six; 1056 } 1057 KMCPY(&tcb, tcbp, sizeof(tcb)); 1058 ti.ti_win = tcb.rcv_adv; |
1064 ti.ti_seq = tcb.snd_nxt - 1; | 1059 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 | 1060 ti.ti_ack = tcb.rcv_nxt; 1061 1062 if (!ptest || (ptest == 5)) { 1063 /* 1064 * Test 5: urp 1065 */ 1066 t->th_flags = TH_ACK|TH_URG; 1067 printf("5.5.1 TCP Urgent pointer, sport %hu dport %hu\n", 1068 ntohs(t->th_sport), ntohs(t->th_dport)); 1069 t->th_urp = htons(1); 1070 (void) send_tcp(nfd, mtu, ip, gwip); 1071 PAUSE(); 1072 |
1078 t->th_seq = tcb.snd_nxt; | 1073 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(); | 1074 ip->ip_len = sizeof(ip_t) + sizeof(tcphdr_t) + 1; 1075 t->th_urp = htons(0x7fff); 1076 (void) send_tcp(nfd, mtu, ip, gwip); 1077 PAUSE(); 1078 t->th_urp = htons(0x8000); 1079 (void) send_tcp(nfd, mtu, ip, gwip); 1080 PAUSE(); 1081 t->th_urp = htons(0xffff); 1082 (void) send_tcp(nfd, mtu, ip, gwip); 1083 PAUSE(); |
1089 t->th_urp = htons(0); | 1084 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 */ --- 9 unchanged lines hidden (view full) --- 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 | 1085 t->th_flags &= ~TH_URG; 1086 ip->ip_len = sizeof(ip_t) + sizeof(tcphdr_t); 1087 } 1088 1089 if (!ptest || (ptest == 6)) { 1090 /* 1091 * Test 6: data offset, off = 0, off is inside, off is outside 1092 */ --- 9 unchanged lines hidden (view full) --- 1102 putchar('\n'); 1103 ip->ip_len = sizeof(ip_t) + sizeof(tcphdr_t); 1104 } 1105 1106 (void) close(fd); 1107 } 1108skip_five_and_six: 1109#endif |
1115 t->th_seq = 1; 1116 t->th_ack = 1; | 1110 t->th_seq = htonl(1); 1111 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"); | 1112 t->th_off = 0; 1113 1114 if (!ptest || (ptest == 7)) { 1115 t->th_flags = TH_SYN; 1116 /* 1117 * Test 7: sport = 0, sport = 1, sport = 32767 1118 * sport = 32768, sport = 65535 1119 */ 1120 printf("5.7.1 TCP sport = 0\n"); 1121 t->th_sport = 0; 1122 (void) send_tcp(nfd, mtu, ip, gwip); 1123 fflush(stdout); 1124 PAUSE(); 1125 1126 printf("5.7.2 TCP sport = 1\n"); |
1132 t->th_sport = 1; | 1127 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"); | 1128 (void) send_tcp(nfd, mtu, ip, gwip); 1129 fflush(stdout); 1130 PAUSE(); 1131 1132 printf("5.7.3 TCP sport = 32767\n"); |
1138 t->th_sport = 32767; | 1133 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"); | 1134 (void) send_tcp(nfd, mtu, ip, gwip); 1135 fflush(stdout); 1136 PAUSE(); 1137 1138 printf("5.7.4 TCP sport = 32768\n"); |
1144 t->th_sport = 32768; | 1139 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"); | 1140 (void) send_tcp(nfd, mtu, ip, gwip); 1141 fflush(stdout); 1142 PAUSE(); 1143 1144 printf("5.7.5 TCP sport = 65535\n"); |
1150 t->th_sport = 65535; | 1145 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)) { | 1146 (void) send_tcp(nfd, mtu, ip, gwip); 1147 fflush(stdout); 1148 PAUSE(); 1149 } 1150 1151 if (!ptest || (ptest == 8)) { |
1157 t->th_sport = 1; | 1152 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"); | 1153 t->th_flags = TH_SYN; 1154 /* 1155 * Test 8: dport = 0, dport = 1, dport = 32767 1156 * dport = 32768, dport = 65535 1157 */ 1158 printf("5.8.1 TCP dport = 0\n"); 1159 t->th_dport = 0; 1160 (void) send_tcp(nfd, mtu, ip, gwip); 1161 fflush(stdout); 1162 PAUSE(); 1163 1164 printf("5.8.2 TCP dport = 1\n"); |
1170 t->th_dport = 1; | 1165 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"); | 1166 (void) send_tcp(nfd, mtu, ip, gwip); 1167 fflush(stdout); 1168 PAUSE(); 1169 1170 printf("5.8.3 TCP dport = 32767\n"); |
1176 t->th_dport = 32767; | 1171 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"); | 1172 (void) send_tcp(nfd, mtu, ip, gwip); 1173 fflush(stdout); 1174 PAUSE(); 1175 1176 printf("5.8.4 TCP dport = 32768\n"); |
1182 t->th_dport = 32768; | 1177 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"); | 1178 (void) send_tcp(nfd, mtu, ip, gwip); 1179 fflush(stdout); 1180 PAUSE(); 1181 1182 printf("5.8.5 TCP dport = 65535\n"); |
1188 t->th_dport = 65535; | 1183 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"); --- 27 unchanged lines hidden (view full) --- 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); | 1184 (void) send_tcp(nfd, mtu, ip, gwip); 1185 fflush(stdout); 1186 PAUSE(); 1187 } 1188 1189 /* LAND attack - self connect, so make src & dst ip/port the same */ 1190 if (!ptest || (ptest == 9)) { 1191 printf("5.9 TCP LAND attack. sport = 25, dport = 25\n"); --- 27 unchanged lines hidden (view full) --- 1219 1220 ip->ip_v = IPVERSION; 1221 ip->ip_tos = 0; 1222 ip->ip_off = 0; 1223 ip->ip_ttl = 60; 1224 ip->ip_p = IPPROTO_UDP; 1225 ip->ip_sum = 0; 1226 u = (udphdr_t *)(ip + 1); |
1232 u->uh_sport = 1; 1233 u->uh_dport = 9; | 1227 u->uh_sport = htons(1); 1228 u->uh_dport = htons(9); |
1234 u->uh_sum = 0; 1235 1236 nfd = initdevice(dev, u->uh_sport, 1); | 1229 u->uh_sum = 0; 1230 1231 nfd = initdevice(dev, u->uh_sport, 1); |
1237 u->uh_sport = htons(u->uh_sport); 1238 u->uh_dport = htons(u->uh_dport); 1239 u->uh_ulen = 7168; | 1232 u->uh_ulen = htons(7168); |
1240 1241 printf("6. Exhaustive mbuf test.\n"); 1242 printf(" Send 7k packet in 768 & 128 byte fragments, 128 times.\n"); 1243 printf(" Total of around 8,900 packets\n"); 1244 for (i = 0; i < 128; i++) { 1245 /* 1246 * First send the entire packet in 768 byte chunks. 1247 */ 1248 ip->ip_len = sizeof(*ip) + 768 + sizeof(*u); 1249 ip->ip_hl = sizeof(*ip) >> 2; | 1233 1234 printf("6. Exhaustive mbuf test.\n"); 1235 printf(" Send 7k packet in 768 & 128 byte fragments, 128 times.\n"); 1236 printf(" Total of around 8,900 packets\n"); 1237 for (i = 0; i < 128; i++) { 1238 /* 1239 * First send the entire packet in 768 byte chunks. 1240 */ 1241 ip->ip_len = sizeof(*ip) + 768 + sizeof(*u); 1242 ip->ip_hl = sizeof(*ip) >> 2; |
1250 ip->ip_off = IP_MF; | 1243 ip->ip_off = htons(IP_MF); |
1251 (void) send_ip(nfd, 1500, ip, gwip, 1); 1252 printf("%d %d\r", i, 0); 1253 fflush(stdout); 1254 PAUSE(); 1255 /* 1256 * And again using 128 byte chunks. 1257 */ 1258 ip->ip_len = sizeof(*ip) + 128 + sizeof(*u); | 1244 (void) send_ip(nfd, 1500, ip, gwip, 1); 1245 printf("%d %d\r", i, 0); 1246 fflush(stdout); 1247 PAUSE(); 1248 /* 1249 * And again using 128 byte chunks. 1250 */ 1251 ip->ip_len = sizeof(*ip) + 128 + sizeof(*u); |
1259 ip->ip_off = IP_MF; | 1252 ip->ip_off = htons(IP_MF); |
1260 (void) send_ip(nfd, 1500, ip, gwip, 1); 1261 printf("%d %d\r", i, 0); 1262 fflush(stdout); 1263 PAUSE(); 1264 1265 for (j = 768; j < 3584; j += 768) { 1266 ip->ip_len = sizeof(*ip) + 768; | 1253 (void) send_ip(nfd, 1500, ip, gwip, 1); 1254 printf("%d %d\r", i, 0); 1255 fflush(stdout); 1256 PAUSE(); 1257 1258 for (j = 768; j < 3584; j += 768) { 1259 ip->ip_len = sizeof(*ip) + 768; |
1267 ip->ip_off = IP_MF|(j>>3); | 1260 ip->ip_off = htons(IP_MF|(j>>3)); |
1268 (void) send_ip(nfd, 1500, ip, gwip, 1); 1269 printf("%d %d\r", i, j); 1270 fflush(stdout); 1271 PAUSE(); 1272 1273 ip->ip_len = sizeof(*ip) + 128; 1274 for (k = j - 768; k < j; k += 128) { | 1261 (void) send_ip(nfd, 1500, ip, gwip, 1); 1262 printf("%d %d\r", i, j); 1263 fflush(stdout); 1264 PAUSE(); 1265 1266 ip->ip_len = sizeof(*ip) + 128; 1267 for (k = j - 768; k < j; k += 128) { |
1275 ip->ip_off = IP_MF|(k>>3); | 1268 ip->ip_off = htons(IP_MF|(k>>3)); |
1276 (void) send_ip(nfd, 1500, ip, gwip, 1); 1277 printf("%d %d\r", i, k); 1278 fflush(stdout); 1279 PAUSE(); 1280 } 1281 } 1282 } 1283 putchar('\n'); --- 37 unchanged lines hidden (view full) --- 1321 PAUSE(); 1322 } 1323 putchar('\n'); 1324 1325 for (i = 0; i < 512; i++) { 1326 for (s = (u_char *)pip, j = 0; j < sizeof(tbuf); j++, s++) 1327 *s = (rand() >> 13) & 0xff; 1328 pip->ip_v = IPVERSION; | 1269 (void) send_ip(nfd, 1500, ip, gwip, 1); 1270 printf("%d %d\r", i, k); 1271 fflush(stdout); 1272 PAUSE(); 1273 } 1274 } 1275 } 1276 putchar('\n'); --- 37 unchanged lines hidden (view full) --- 1314 PAUSE(); 1315 } 1316 putchar('\n'); 1317 1318 for (i = 0; i < 512; i++) { 1319 for (s = (u_char *)pip, j = 0; j < sizeof(tbuf); j++, s++) 1320 *s = (rand() >> 13) & 0xff; 1321 pip->ip_v = IPVERSION; |
1329 pip->ip_off &= 0xc000; | 1322 pip->ip_off &= htons(0xc000); |
1330 bcopy((char *)&ip->ip_dst, (char *)&pip->ip_dst, 1331 sizeof(struct in_addr)); 1332 pip->ip_sum = 0; 1333 pip->ip_len &= 0xff; 1334 (void) send_ip(nfd, mtu, pip, gwip, 0); 1335 printf("%d\r", i); 1336 fflush(stdout); 1337 PAUSE(); 1338 } 1339 putchar('\n'); 1340} | 1323 bcopy((char *)&ip->ip_dst, (char *)&pip->ip_dst, 1324 sizeof(struct in_addr)); 1325 pip->ip_sum = 0; 1326 pip->ip_len &= 0xff; 1327 (void) send_ip(nfd, mtu, pip, gwip, 0); 1328 printf("%d\r", i); 1329 fflush(stdout); 1330 PAUSE(); 1331 } 1332 putchar('\n'); 1333} |