print-ip.c (162021) | print-ip.c (172686) |
---|---|
1/* 2 * Copyright (c) 1988, 1989, 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1997 3 * The Regents of the University of California. All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that: (1) source code distributions 7 * retain the above copyright notice and this paragraph in its entirety, (2) 8 * distributions including binary code include the above copyright notice and --- 4 unchanged lines hidden (view full) --- 13 * Lawrence Berkeley Laboratory and its contributors.'' Neither the name of 14 * the University nor the names of its contributors may be used to endorse 15 * or promote products derived from this software without specific prior 16 * written permission. 17 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED 18 * WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF 19 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. 20 * | 1/* 2 * Copyright (c) 1988, 1989, 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1997 3 * The Regents of the University of California. All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that: (1) source code distributions 7 * retain the above copyright notice and this paragraph in its entirety, (2) 8 * distributions including binary code include the above copyright notice and --- 4 unchanged lines hidden (view full) --- 13 * Lawrence Berkeley Laboratory and its contributors.'' Neither the name of 14 * the University nor the names of its contributors may be used to endorse 15 * or promote products derived from this software without specific prior 16 * written permission. 17 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED 18 * WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF 19 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. 20 * |
21 * $FreeBSD: head/contrib/tcpdump/print-ip.c 162021 2006-09-04 20:25:04Z sam $ | 21 * $FreeBSD: head/contrib/tcpdump/print-ip.c 172686 2007-10-16 02:31:48Z mlaier $ |
22 */ 23 24#ifndef lint 25static const char rcsid[] _U_ = | 22 */ 23 24#ifndef lint 25static const char rcsid[] _U_ = |
26 "@(#) $Header: /tcpdump/master/tcpdump/print-ip.c,v 1.149.2.2 2005/09/20 06:05:38 guy Exp $ (LBL)"; | 26 "@(#) $Header: /tcpdump/master/tcpdump/print-ip.c,v 1.149.2.9 2007/09/14 01:30:02 guy Exp $ (LBL)"; |
27#endif 28 29#ifdef HAVE_CONFIG_H 30#include "config.h" 31#endif 32 33#include <tcpdump-stdinc.h> 34 --- 12 unchanged lines hidden (view full) --- 47 { IPOPT_EOL, "EOL" }, 48 { IPOPT_NOP, "NOP" }, 49 { IPOPT_TS, "timestamp" }, 50 { IPOPT_SECURITY, "security" }, 51 { IPOPT_RR, "RR" }, 52 { IPOPT_SSRR, "SSRR" }, 53 { IPOPT_LSRR, "LSRR" }, 54 { IPOPT_RA, "RA" }, | 27#endif 28 29#ifdef HAVE_CONFIG_H 30#include "config.h" 31#endif 32 33#include <tcpdump-stdinc.h> 34 --- 12 unchanged lines hidden (view full) --- 47 { IPOPT_EOL, "EOL" }, 48 { IPOPT_NOP, "NOP" }, 49 { IPOPT_TS, "timestamp" }, 50 { IPOPT_SECURITY, "security" }, 51 { IPOPT_RR, "RR" }, 52 { IPOPT_SSRR, "SSRR" }, 53 { IPOPT_LSRR, "LSRR" }, 54 { IPOPT_RA, "RA" }, |
55 { IPOPT_RFC1393, "traceroute" }, |
|
55 { 0, NULL } 56}; 57 58/* 59 * print the recorded route in an IP RR, LSRR or SSRR option. 60 */ 61static void 62ip_printroute(register const u_char *cp, u_int length) --- 7 unchanged lines hidden (view full) --- 70 } 71 if ((length + 1) & 3) 72 printf(" [bad length %u]", length); 73 ptr = cp[2] - 1; 74 if (ptr < 3 || ((ptr + 1) & 3) || ptr > length + 1) 75 printf(" [bad ptr %u]", cp[2]); 76 77 for (len = 3; len < length; len += 4) { | 56 { 0, NULL } 57}; 58 59/* 60 * print the recorded route in an IP RR, LSRR or SSRR option. 61 */ 62static void 63ip_printroute(register const u_char *cp, u_int length) --- 7 unchanged lines hidden (view full) --- 71 } 72 if ((length + 1) & 3) 73 printf(" [bad length %u]", length); 74 ptr = cp[2] - 1; 75 if (ptr < 3 || ((ptr + 1) & 3) || ptr > length + 1) 76 printf(" [bad ptr %u]", cp[2]); 77 78 for (len = 3; len < length; len += 4) { |
78 printf("%s", ipaddr_string(&cp[len])); | 79 printf(" %s", ipaddr_string(&cp[len])); |
79 if (ptr > len) | 80 if (ptr > len) |
80 printf (", "); | 81 printf(","); |
81 } 82} 83 84/* 85 * If source-routing is present and valid, return the final destination. 86 * Otherwise, return IP destination. 87 * 88 * This is used for UDP and TCP pseudo-header in the checksum --- 45 unchanged lines hidden (view full) --- 134ip_printts(register const u_char *cp, u_int length) 135{ 136 register u_int ptr; 137 register u_int len; 138 int hoplen; 139 const char *type; 140 141 if (length < 4) { | 82 } 83} 84 85/* 86 * If source-routing is present and valid, return the final destination. 87 * Otherwise, return IP destination. 88 * 89 * This is used for UDP and TCP pseudo-header in the checksum --- 45 unchanged lines hidden (view full) --- 135ip_printts(register const u_char *cp, u_int length) 136{ 137 register u_int ptr; 138 register u_int len; 139 int hoplen; 140 const char *type; 141 142 if (length < 4) { |
142 printf("[bad length %d]", length); | 143 printf("[bad length %u]", length); |
143 return; 144 } 145 printf(" TS{"); 146 hoplen = ((cp[3]&0xF) != IPOPT_TS_TSONLY) ? 8 : 4; 147 if ((length - 4) & (hoplen-1)) | 144 return; 145 } 146 printf(" TS{"); 147 hoplen = ((cp[3]&0xF) != IPOPT_TS_TSONLY) ? 8 : 4; 148 if ((length - 4) & (hoplen-1)) |
148 printf("[bad length %d]", length); | 149 printf("[bad length %u]", length); |
149 ptr = cp[2] - 1; 150 len = 0; 151 if (ptr < 4 || ((ptr - 4) & (hoplen-1)) || ptr > length + 1) | 150 ptr = cp[2] - 1; 151 len = 0; 152 if (ptr < 4 || ((ptr - 4) & (hoplen-1)) || ptr > length + 1) |
152 printf("[bad ptr %d]", cp[2]); | 153 printf("[bad ptr %u]", cp[2]); |
153 switch (cp[3]&0xF) { 154 case IPOPT_TS_TSONLY: 155 printf("TSONLY"); 156 break; 157 case IPOPT_TS_TSANDADDR: 158 printf("TS+ADDR"); 159 break; 160 /* --- 33 unchanged lines hidden (view full) --- 194 195/* 196 * print IP options. 197 */ 198static void 199ip_optprint(register const u_char *cp, u_int length) 200{ 201 register u_int option_len; | 154 switch (cp[3]&0xF) { 155 case IPOPT_TS_TSONLY: 156 printf("TSONLY"); 157 break; 158 case IPOPT_TS_TSANDADDR: 159 printf("TS+ADDR"); 160 break; 161 /* --- 33 unchanged lines hidden (view full) --- 195 196/* 197 * print IP options. 198 */ 199static void 200ip_optprint(register const u_char *cp, u_int length) 201{ 202 register u_int option_len; |
203 const char *sep = ""; |
|
202 203 for (; length > 0; cp += option_len, length -= option_len) { 204 u_int option_code; 205 | 204 205 for (; length > 0; cp += option_len, length -= option_len) { 206 u_int option_code; 207 |
208 printf("%s", sep); 209 sep = ","; 210 |
|
206 TCHECK(*cp); 207 option_code = *cp; 208 | 211 TCHECK(*cp); 212 option_code = *cp; 213 |
214 printf("%s", 215 tok2str(ip_option_values,"unknown %u",option_code)); 216 |
|
209 if (option_code == IPOPT_NOP || 210 option_code == IPOPT_EOL) 211 option_len = 1; 212 213 else { 214 TCHECK(cp[1]); | 217 if (option_code == IPOPT_NOP || 218 option_code == IPOPT_EOL) 219 option_len = 1; 220 221 else { 222 TCHECK(cp[1]); |
215 option_len = cp[1]; | 223 option_len = cp[1]; 224 if (option_len < 2) { 225 printf(" [bad length %u]", option_len); 226 return; 227 } |
216 } 217 | 228 } 229 |
218 printf("%s (%u) len %u", 219 tok2str(ip_option_values,"unknown",option_code), 220 option_code, 221 option_len); | 230 if (option_len > length) { 231 printf(" [bad length %u]", option_len); 232 return; 233 } |
222 | 234 |
223 if (option_len < 2) 224 return; 225 | |
226 TCHECK2(*cp, option_len); 227 228 switch (option_code) { 229 case IPOPT_EOL: 230 return; 231 232 case IPOPT_TS: 233 ip_printts(cp, option_len); 234 break; 235 236 case IPOPT_RR: /* fall through */ 237 case IPOPT_SSRR: 238 case IPOPT_LSRR: | 235 TCHECK2(*cp, option_len); 236 237 switch (option_code) { 238 case IPOPT_EOL: 239 return; 240 241 case IPOPT_TS: 242 ip_printts(cp, option_len); 243 break; 244 245 case IPOPT_RR: /* fall through */ 246 case IPOPT_SSRR: 247 case IPOPT_LSRR: |
239 ip_printroute( cp, option_len); | 248 ip_printroute(cp, option_len); |
240 break; 241 242 case IPOPT_RA: | 249 break; 250 251 case IPOPT_RA: |
252 if (option_len < 4) { 253 printf(" [bad length %u]", option_len); 254 break; 255 } |
|
243 TCHECK(cp[3]); 244 if (EXTRACT_16BITS(&cp[2]) != 0) | 256 TCHECK(cp[3]); 257 if (EXTRACT_16BITS(&cp[2]) != 0) |
245 printf("value %u", EXTRACT_16BITS(&cp[2])); | 258 printf(" value %u", EXTRACT_16BITS(&cp[2])); |
246 break; 247 248 case IPOPT_NOP: /* nothing to print - fall through */ 249 case IPOPT_SECURITY: 250 default: 251 break; 252 } 253 } --- 84 unchanged lines hidden (view full) --- 338 */ 339 shouldbe = sum; 340 shouldbe += ntohs(computed_sum); 341 shouldbe = (shouldbe & 0xFFFF) + (shouldbe >> 16); 342 shouldbe = (shouldbe & 0xFFFF) + (shouldbe >> 16); 343 return shouldbe; 344} 345 | 259 break; 260 261 case IPOPT_NOP: /* nothing to print - fall through */ 262 case IPOPT_SECURITY: 263 default: 264 break; 265 } 266 } --- 84 unchanged lines hidden (view full) --- 351 */ 352 shouldbe = sum; 353 shouldbe += ntohs(computed_sum); 354 shouldbe = (shouldbe & 0xFFFF) + (shouldbe >> 16); 355 shouldbe = (shouldbe & 0xFFFF) + (shouldbe >> 16); 356 return shouldbe; 357} 358 |
346#ifndef IP_MF 347#define IP_MF 0x2000 348#endif /* IP_MF */ 349#ifndef IP_DF 350#define IP_DF 0x4000 351#endif /* IP_DF */ | |
352#define IP_RES 0x8000 353 354static struct tok ip_frag_values[] = { 355 { IP_MF, "+" }, 356 { IP_DF, "DF" }, 357 { IP_RES, "rsvd" }, /* The RFC3514 evil ;-) bit */ 358 { 0, NULL } 359}; --- 54 unchanged lines hidden (view full) --- 414 sctp_print(ipds->cp, (const u_char *)ipds->ip, ipds->len); 415 break; 416 417 case IPPROTO_DCCP: 418 dccp_print(ipds->cp, (const u_char *)ipds->ip, ipds->len); 419 break; 420 421 case IPPROTO_TCP: | 359#define IP_RES 0x8000 360 361static struct tok ip_frag_values[] = { 362 { IP_MF, "+" }, 363 { IP_DF, "DF" }, 364 { IP_RES, "rsvd" }, /* The RFC3514 evil ;-) bit */ 365 { 0, NULL } 366}; --- 54 unchanged lines hidden (view full) --- 421 sctp_print(ipds->cp, (const u_char *)ipds->ip, ipds->len); 422 break; 423 424 case IPPROTO_DCCP: 425 dccp_print(ipds->cp, (const u_char *)ipds->ip, ipds->len); 426 break; 427 428 case IPPROTO_TCP: |
429 /* pass on the MF bit plus the offset to detect fragments */ |
|
422 tcp_print(ipds->cp, ipds->len, (const u_char *)ipds->ip, | 430 tcp_print(ipds->cp, ipds->len, (const u_char *)ipds->ip, |
423 (ipds->off &~ 0x6000)); | 431 ipds->off & (IP_MF|IP_OFFMASK)); |
424 break; 425 426 case IPPROTO_UDP: | 432 break; 433 434 case IPPROTO_UDP: |
435 /* pass on the MF bit plus the offset to detect fragments */ |
|
427 udp_print(ipds->cp, ipds->len, (const u_char *)ipds->ip, | 436 udp_print(ipds->cp, ipds->len, (const u_char *)ipds->ip, |
428 (ipds->off &~ 0x6000)); | 437 ipds->off & (IP_MF|IP_OFFMASK)); |
429 break; 430 431 case IPPROTO_ICMP: 432 /* pass on the MF bit plus the offset to detect fragments */ 433 icmp_print(ipds->cp, ipds->len, (const u_char *)ipds->ip, | 438 break; 439 440 case IPPROTO_ICMP: 441 /* pass on the MF bit plus the offset to detect fragments */ 442 icmp_print(ipds->cp, ipds->len, (const u_char *)ipds->ip, |
434 (ipds->off & 0x3fff)); | 443 ipds->off & (IP_MF|IP_OFFMASK)); |
435 break; 436 437 case IPPROTO_PIGP: 438 /* 439 * XXX - the current IANA protocol number assignments 440 * page lists 9 as "any private interior gateway 441 * (used by Cisco for their IGRP)" and 88 as 442 * "EIGRP" from Cisco. --- 179 unchanged lines hidden (view full) --- 622 (void)printf(",ECT(0)"); 623 break; 624 case 3: 625 (void)printf(",CE"); 626 } 627 } 628 629 if (ipds->ip->ip_ttl >= 1) | 444 break; 445 446 case IPPROTO_PIGP: 447 /* 448 * XXX - the current IANA protocol number assignments 449 * page lists 9 as "any private interior gateway 450 * (used by Cisco for their IGRP)" and 88 as 451 * "EIGRP" from Cisco. --- 179 unchanged lines hidden (view full) --- 631 (void)printf(",ECT(0)"); 632 break; 633 case 3: 634 (void)printf(",CE"); 635 } 636 } 637 638 if (ipds->ip->ip_ttl >= 1) |
630 (void)printf(", ttl %3u", ipds->ip->ip_ttl); | 639 (void)printf(", ttl %u", ipds->ip->ip_ttl); |
631 632 /* 633 * for the firewall guys, print id, offset. 634 * On all but the last stick a "+" in the flags portion. 635 * For unfragmented datagrams, note the don't fragment flag. 636 */ 637 | 640 641 /* 642 * for the firewall guys, print id, offset. 643 * On all but the last stick a "+" in the flags portion. 644 * For unfragmented datagrams, note the don't fragment flag. 645 */ 646 |
638 (void)printf(", id %u, offset %u, flags [%s], proto: %s (%u)", | 647 (void)printf(", id %u, offset %u, flags [%s], proto %s (%u)", |
639 EXTRACT_16BITS(&ipds->ip->ip_id), 640 (ipds->off & 0x1fff) * 8, | 648 EXTRACT_16BITS(&ipds->ip->ip_id), 649 (ipds->off & 0x1fff) * 8, |
641 bittok2str(ip_frag_values, "none", ipds->off&0xe000 ), | 650 bittok2str(ip_frag_values, "none", ipds->off&0xe000), |
642 tok2str(ipproto_values,"unknown",ipds->ip->ip_p), 643 ipds->ip->ip_p); 644 | 651 tok2str(ipproto_values,"unknown",ipds->ip->ip_p), 652 ipds->ip->ip_p); 653 |
645 (void)printf(", length: %u", EXTRACT_16BITS(&ipds->ip->ip_len)); | 654 (void)printf(", length %u", EXTRACT_16BITS(&ipds->ip->ip_len)); |
646 647 if ((hlen - sizeof(struct ip)) > 0) { | 655 656 if ((hlen - sizeof(struct ip)) > 0) { |
648 printf(", options ( "); | 657 printf(", options ("); |
649 ip_optprint((u_char *)(ipds->ip + 1), hlen - sizeof(struct ip)); | 658 ip_optprint((u_char *)(ipds->ip + 1), hlen - sizeof(struct ip)); |
650 printf(" )"); | 659 printf(")"); |
651 } 652 653 if ((u_char *)ipds->ip + hlen <= snapend) { 654 sum = in_cksum((const u_short *)ipds->ip, hlen, 0); 655 if (sum != 0) { 656 ip_sum = EXTRACT_16BITS(&ipds->ip->ip_sum); 657 (void)printf(", bad cksum %x (->%x)!", ip_sum, 658 in_cksum_shouldbe(ip_sum, sum)); --- 75 unchanged lines hidden --- | 660 } 661 662 if ((u_char *)ipds->ip + hlen <= snapend) { 663 sum = in_cksum((const u_short *)ipds->ip, hlen, 0); 664 if (sum != 0) { 665 ip_sum = EXTRACT_16BITS(&ipds->ip->ip_sum); 666 (void)printf(", bad cksum %x (->%x)!", ip_sum, 667 in_cksum_shouldbe(ip_sum, sum)); --- 75 unchanged lines hidden --- |