Deleted Added
sdiff udiff text old ( 162021 ) new ( 172686 )
full compact
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 172686 2007-10-16 02:31:48Z mlaier $
22 */
23
24#ifndef lint
25static const char rcsid[] _U_ =
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" },
55 { IPOPT_RFC1393, "traceroute" },
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) {
79 printf(" %s", ipaddr_string(&cp[len]));
80 if (ptr > len)
81 printf(",");
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) {
143 printf("[bad length %u]", length);
144 return;
145 }
146 printf(" TS{");
147 hoplen = ((cp[3]&0xF) != IPOPT_TS_TSONLY) ? 8 : 4;
148 if ((length - 4) & (hoplen-1))
149 printf("[bad length %u]", length);
150 ptr = cp[2] - 1;
151 len = 0;
152 if (ptr < 4 || ((ptr - 4) & (hoplen-1)) || ptr > length + 1)
153 printf("[bad ptr %u]", cp[2]);
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 = "";
204
205 for (; length > 0; cp += option_len, length -= option_len) {
206 u_int option_code;
207
208 printf("%s", sep);
209 sep = ",";
210
211 TCHECK(*cp);
212 option_code = *cp;
213
214 printf("%s",
215 tok2str(ip_option_values,"unknown %u",option_code));
216
217 if (option_code == IPOPT_NOP ||
218 option_code == IPOPT_EOL)
219 option_len = 1;
220
221 else {
222 TCHECK(cp[1]);
223 option_len = cp[1];
224 if (option_len < 2) {
225 printf(" [bad length %u]", option_len);
226 return;
227 }
228 }
229
230 if (option_len > length) {
231 printf(" [bad length %u]", option_len);
232 return;
233 }
234
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:
248 ip_printroute(cp, option_len);
249 break;
250
251 case IPOPT_RA:
252 if (option_len < 4) {
253 printf(" [bad length %u]", option_len);
254 break;
255 }
256 TCHECK(cp[3]);
257 if (EXTRACT_16BITS(&cp[2]) != 0)
258 printf(" value %u", EXTRACT_16BITS(&cp[2]));
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
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 */
430 tcp_print(ipds->cp, ipds->len, (const u_char *)ipds->ip,
431 ipds->off & (IP_MF|IP_OFFMASK));
432 break;
433
434 case IPPROTO_UDP:
435 /* pass on the MF bit plus the offset to detect fragments */
436 udp_print(ipds->cp, ipds->len, (const u_char *)ipds->ip,
437 ipds->off & (IP_MF|IP_OFFMASK));
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,
443 ipds->off & (IP_MF|IP_OFFMASK));
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)
639 (void)printf(", ttl %u", ipds->ip->ip_ttl);
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
647 (void)printf(", id %u, offset %u, flags [%s], proto %s (%u)",
648 EXTRACT_16BITS(&ipds->ip->ip_id),
649 (ipds->off & 0x1fff) * 8,
650 bittok2str(ip_frag_values, "none", ipds->off&0xe000),
651 tok2str(ipproto_values,"unknown",ipds->ip->ip_p),
652 ipds->ip->ip_p);
653
654 (void)printf(", length %u", EXTRACT_16BITS(&ipds->ip->ip_len));
655
656 if ((hlen - sizeof(struct ip)) > 0) {
657 printf(", options (");
658 ip_optprint((u_char *)(ipds->ip + 1), hlen - sizeof(struct ip));
659 printf(")");
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 ---