Deleted Added
full compact
print-ip.c (75118) print-ip.c (98527)
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 75118 2001-04-03 07:50:46Z fenner $
21 * $FreeBSD: head/contrib/tcpdump/print-ip.c 98527 2002-06-21 00:49:02Z fenner $
22 */
23
24#ifndef lint
25static const char rcsid[] =
22 */
23
24#ifndef lint
25static const char rcsid[] =
26 "@(#) $Header: /tcpdump/master/tcpdump/print-ip.c,v 1.92 2001/01/02 23:00:01 guy Exp $ (LBL)";
26 "@(#) $Header: /tcpdump/master/tcpdump/print-ip.c,v 1.100 2001/09/17 21:58:03 fenner Exp $ (LBL)";
27#endif
28
29#ifdef HAVE_CONFIG_H
30#include "config.h"
31#endif
32
33#include <sys/param.h>
34#include <sys/time.h>

--- 165 unchanged lines hidden (view full) ---

200#define IPOPT_RA 148 /* router alert */
201#endif
202 case IPOPT_RA:
203 printf(" RA");
204 if (len != 4)
205 printf("{%d}", len);
206 else if (cp[2] || cp[3])
207 printf("%d.%d", cp[2], cp[3]);
27#endif
28
29#ifdef HAVE_CONFIG_H
30#include "config.h"
31#endif
32
33#include <sys/param.h>
34#include <sys/time.h>

--- 165 unchanged lines hidden (view full) ---

200#define IPOPT_RA 148 /* router alert */
201#endif
202 case IPOPT_RA:
203 printf(" RA");
204 if (len != 4)
205 printf("{%d}", len);
206 else if (cp[2] || cp[3])
207 printf("%d.%d", cp[2], cp[3]);
208 break;
208 break;
209
210 default:
211 printf(" IPOPT-%d{%d}", cp[0], len);
212 break;
213 }
214 }
215}
216
217/*
218 * compute an IP header checksum.
219 * don't modifiy the packet.
220 */
221u_short
209
210 default:
211 printf(" IPOPT-%d{%d}", cp[0], len);
212 break;
213 }
214 }
215}
216
217/*
218 * compute an IP header checksum.
219 * don't modifiy the packet.
220 */
221u_short
222in_cksum(const u_short *addr, register int len, u_short csum)
222in_cksum(const u_short *addr, register u_int len, int csum)
223{
224 int nleft = len;
225 const u_short *w = addr;
226 u_short answer;
227 int sum = csum;
228
229 /*
230 * Our algorithm is simple, using a 32 bit accumulator (sum),

--- 67 unchanged lines hidden (view full) ---

298 hlen = IP_HL(ip) * 4;
299 if (hlen < sizeof (struct ip)) {
300 (void)printf("bad-hlen %d", hlen);
301 return;
302 }
303
304 len = ntohs(ip->ip_len);
305 if (length < len)
223{
224 int nleft = len;
225 const u_short *w = addr;
226 u_short answer;
227 int sum = csum;
228
229 /*
230 * Our algorithm is simple, using a 32 bit accumulator (sum),

--- 67 unchanged lines hidden (view full) ---

298 hlen = IP_HL(ip) * 4;
299 if (hlen < sizeof (struct ip)) {
300 (void)printf("bad-hlen %d", hlen);
301 return;
302 }
303
304 len = ntohs(ip->ip_len);
305 if (length < len)
306 (void)printf("truncated-ip - %d bytes missing!",
306 (void)printf("truncated-ip - %d bytes missing! ",
307 len - length);
308 len -= hlen;
309 len0 = len;
310
311 /*
312 * If this is fragment zero, hand it to the next higher
313 * level protocol.
314 */
315 off = ntohs(ip->ip_off);
316 if ((off & 0x1fff) == 0) {
317 cp = (const u_char *)ip + hlen;
318 nh = ip->ip_p;
319
307 len - length);
308 len -= hlen;
309 len0 = len;
310
311 /*
312 * If this is fragment zero, hand it to the next higher
313 * level protocol.
314 */
315 off = ntohs(ip->ip_off);
316 if ((off & 0x1fff) == 0) {
317 cp = (const u_char *)ip + hlen;
318 nh = ip->ip_p;
319
320 if (nh != IPPROTO_TCP && nh != IPPROTO_UDP) {
320#ifndef IPPROTO_SCTP
321#define IPPROTO_SCTP 132
322#endif
323 if (nh != IPPROTO_TCP && nh != IPPROTO_UDP &&
324 nh != IPPROTO_SCTP) {
321 (void)printf("%s > %s: ", ipaddr_string(&ip->ip_src),
322 ipaddr_string(&ip->ip_dst));
323 }
324again:
325 switch (nh) {
326
327#ifndef IPPROTO_AH
328#define IPPROTO_AH 51

--- 5 unchanged lines hidden (view full) ---

334 len -= advance;
335 goto again;
336
337#ifndef IPPROTO_ESP
338#define IPPROTO_ESP 50
339#endif
340 case IPPROTO_ESP:
341 {
325 (void)printf("%s > %s: ", ipaddr_string(&ip->ip_src),
326 ipaddr_string(&ip->ip_dst));
327 }
328again:
329 switch (nh) {
330
331#ifndef IPPROTO_AH
332#define IPPROTO_AH 51

--- 5 unchanged lines hidden (view full) ---

338 len -= advance;
339 goto again;
340
341#ifndef IPPROTO_ESP
342#define IPPROTO_ESP 50
343#endif
344 case IPPROTO_ESP:
345 {
342 int enh;
343 advance = esp_print(cp, (const u_char *)ip, &enh);
346 int enh, padlen;
347 advance = esp_print(cp, (const u_char *)ip, &enh, &padlen);
344 cp += advance;
348 cp += advance;
345 len -= advance;
349 len -= advance + padlen;
346 if (enh < 0)
347 break;
348 nh = enh & 0xff;
349 goto again;
350 }
351
352#ifndef IPPROTO_IPCOMP
353#define IPPROTO_IPCOMP 108

--- 5 unchanged lines hidden (view full) ---

359 cp += advance;
360 len -= advance;
361 if (enh < 0)
362 break;
363 nh = enh & 0xff;
364 goto again;
365 }
366
350 if (enh < 0)
351 break;
352 nh = enh & 0xff;
353 goto again;
354 }
355
356#ifndef IPPROTO_IPCOMP
357#define IPPROTO_IPCOMP 108

--- 5 unchanged lines hidden (view full) ---

363 cp += advance;
364 len -= advance;
365 if (enh < 0)
366 break;
367 nh = enh & 0xff;
368 goto again;
369 }
370
371 case IPPROTO_SCTP:
372 sctp_print(cp, (const u_char *)ip, len);
373 break;
374
367 case IPPROTO_TCP:
368 tcp_print(cp, len, (const u_char *)ip, (off &~ 0x6000));
369 break;
370
371 case IPPROTO_UDP:
372 udp_print(cp, len, (const u_char *)ip, (off &~ 0x6000));
373 break;
374

--- 4 unchanged lines hidden (view full) ---

379#ifndef IPPROTO_IGRP
380#define IPPROTO_IGRP 9
381#endif
382 case IPPROTO_IGRP:
383 igrp_print(cp, len, (const u_char *)ip);
384 break;
385
386 case IPPROTO_ND:
375 case IPPROTO_TCP:
376 tcp_print(cp, len, (const u_char *)ip, (off &~ 0x6000));
377 break;
378
379 case IPPROTO_UDP:
380 udp_print(cp, len, (const u_char *)ip, (off &~ 0x6000));
381 break;
382

--- 4 unchanged lines hidden (view full) ---

387#ifndef IPPROTO_IGRP
388#define IPPROTO_IGRP 9
389#endif
390 case IPPROTO_IGRP:
391 igrp_print(cp, len, (const u_char *)ip);
392 break;
393
394 case IPPROTO_ND:
387#if 0
388 (void)printf("%s > %s:", ipaddr_string(&ip->ip_src),
389 ipaddr_string(&ip->ip_dst));
390#endif
391 (void)printf(" nd %d", len);
392 break;
393
394 case IPPROTO_EGP:
395 egp_print(cp, len, (const u_char *)ip);
396 break;
397
398#ifndef IPPROTO_OSPF
399#define IPPROTO_OSPF 89
400#endif
401 case IPPROTO_OSPF:
402 ospf_print(cp, len, (const u_char *)ip);
403 break;
404
405#ifndef IPPROTO_IGMP
406#define IPPROTO_IGMP 2
407#endif
408 case IPPROTO_IGMP:
395 (void)printf(" nd %d", len);
396 break;
397
398 case IPPROTO_EGP:
399 egp_print(cp, len, (const u_char *)ip);
400 break;
401
402#ifndef IPPROTO_OSPF
403#define IPPROTO_OSPF 89
404#endif
405 case IPPROTO_OSPF:
406 ospf_print(cp, len, (const u_char *)ip);
407 break;
408
409#ifndef IPPROTO_IGMP
410#define IPPROTO_IGMP 2
411#endif
412 case IPPROTO_IGMP:
409 igmp_print(cp, len, (const u_char *)ip);
413 igmp_print(cp, len);
410 break;
411
412 case 4:
413 /* DVMRP multicast tunnel (ip-in-ip encapsulation) */
414 break;
415
416 case 4:
417 /* DVMRP multicast tunnel (ip-in-ip encapsulation) */
414#if 0
415 if (vflag)
416 (void)printf("%s > %s: ",
417 ipaddr_string(&ip->ip_src),
418 ipaddr_string(&ip->ip_dst));
419#endif
420 ip_print(cp, len);
421 if (! vflag) {
418 ip_print(cp, len);
419 if (! vflag) {
422 printf(" (ipip)");
420 printf(" (ipip-proto-4)");
423 return;
424 }
425 break;
426
427#ifdef INET6
428#ifndef IP6PROTO_ENCAP
429#define IP6PROTO_ENCAP 41
430#endif
431 case IP6PROTO_ENCAP:
432 /* ip6-in-ip encapsulation */
421 return;
422 }
423 break;
424
425#ifdef INET6
426#ifndef IP6PROTO_ENCAP
427#define IP6PROTO_ENCAP 41
428#endif
429 case IP6PROTO_ENCAP:
430 /* ip6-in-ip encapsulation */
433#if 0
434 if (vflag)
435 (void)printf("%s > %s: ",
436 ipaddr_string(&ip->ip_src),
437 ipaddr_string(&ip->ip_dst));
438#endif
439 ip6_print(cp, len);
431 ip6_print(cp, len);
440 if (! vflag) {
441 printf(" (encap)");
442 return;
443 }
444 break;
445#endif /*INET6*/
446
447
448#ifndef IPPROTO_GRE
449#define IPPROTO_GRE 47
450#endif
451 case IPPROTO_GRE:
432 break;
433#endif /*INET6*/
434
435
436#ifndef IPPROTO_GRE
437#define IPPROTO_GRE 47
438#endif
439 case IPPROTO_GRE:
452 if (vflag)
453 (void)printf("gre %s > %s: ",
454 ipaddr_string(&ip->ip_src),
455 ipaddr_string(&ip->ip_dst));
456 /* do it */
457 gre_print(cp, len);
440 /* do it */
441 gre_print(cp, len);
458 if (! vflag) {
459 printf(" (gre encap)");
460 return;
461 }
462 break;
442 break;
463
464#ifndef IPPROTO_MOBILE
465#define IPPROTO_MOBILE 55
466#endif
467 case IPPROTO_MOBILE:
443
444#ifndef IPPROTO_MOBILE
445#define IPPROTO_MOBILE 55
446#endif
447 case IPPROTO_MOBILE:
468 if (vflag)
469 (void)printf("mobile %s > %s: ",
470 ipaddr_string(&ip->ip_src),
471 ipaddr_string(&ip->ip_dst));
472 mobile_print(cp, len);
448 mobile_print(cp, len);
473 if (! vflag) {
474 printf(" (mobile encap)");
475 return;
476 }
477 break;
478
479#ifndef IPPROTO_PIM
480#define IPPROTO_PIM 103
481#endif
482 case IPPROTO_PIM:
483 pim_print(cp, len);
484 break;
485
486#ifndef IPPROTO_VRRP
487#define IPPROTO_VRRP 112
488#endif
489 case IPPROTO_VRRP:
449 break;
450
451#ifndef IPPROTO_PIM
452#define IPPROTO_PIM 103
453#endif
454 case IPPROTO_PIM:
455 pim_print(cp, len);
456 break;
457
458#ifndef IPPROTO_VRRP
459#define IPPROTO_VRRP 112
460#endif
461 case IPPROTO_VRRP:
490 if (vflag)
491 (void)printf("vrrp %s > %s: ",
492 ipaddr_string(&ip->ip_src),
493 ipaddr_string(&ip->ip_dst));
494 vrrp_print(cp, len, ip->ip_ttl);
495 break;
496
497 default:
462 vrrp_print(cp, len, ip->ip_ttl);
463 break;
464
465 default:
498#if 0
499 (void)printf("%s > %s:", ipaddr_string(&ip->ip_src),
500 ipaddr_string(&ip->ip_dst));
501#endif
502 (void)printf(" ip-proto-%d %d", nh, len);
503 break;
504 }
505 }
506
507 /* Ultra quiet now means that all this stuff should be suppressed */
508 /* res 3-Nov-98 */
509 if (qflag > 1) return;

--- 24 unchanged lines hidden (view full) ---

534 (off & IP_MF)? "+" : "");
535
536 } else if (off & IP_DF)
537 (void)printf(" (DF)");
538
539 if (ip->ip_tos) {
540 (void)printf(" [tos 0x%x", (int)ip->ip_tos);
541 /* ECN bits */
466 (void)printf(" ip-proto-%d %d", nh, len);
467 break;
468 }
469 }
470
471 /* Ultra quiet now means that all this stuff should be suppressed */
472 /* res 3-Nov-98 */
473 if (qflag > 1) return;

--- 24 unchanged lines hidden (view full) ---

498 (off & IP_MF)? "+" : "");
499
500 } else if (off & IP_DF)
501 (void)printf(" (DF)");
502
503 if (ip->ip_tos) {
504 (void)printf(" [tos 0x%x", (int)ip->ip_tos);
505 /* ECN bits */
542 if (ip->ip_tos&0x02) {
543 (void)printf(",ECT");
544 if (ip->ip_tos&0x01)
506 if (ip->ip_tos & 0x03) {
507 switch (ip->ip_tos & 0x03) {
508 case 1:
509 (void)printf(",ECT(1)");
510 break;
511 case 2:
512 (void)printf(",ECT(0)");
513 break;
514 case 3:
545 (void)printf(",CE");
515 (void)printf(",CE");
516 }
546 }
547 (void)printf("] ");
548 }
549
550 if (ip->ip_ttl <= 1)
551 (void)printf(" [ttl %d]", (int)ip->ip_ttl);
552
553 if (vflag) {

--- 35 unchanged lines hidden (view full) ---

589 ip = (struct ip *)bp;
590 if (length < 4) {
591 (void)printf("truncated-ip %d", length);
592 return;
593 }
594 memcpy (&hdr, (char *)ip, 4);
595 switch (IP_V(&hdr)) {
596 case 4:
517 }
518 (void)printf("] ");
519 }
520
521 if (ip->ip_ttl <= 1)
522 (void)printf(" [ttl %d]", (int)ip->ip_ttl);
523
524 if (vflag) {

--- 35 unchanged lines hidden (view full) ---

560 ip = (struct ip *)bp;
561 if (length < 4) {
562 (void)printf("truncated-ip %d", length);
563 return;
564 }
565 memcpy (&hdr, (char *)ip, 4);
566 switch (IP_V(&hdr)) {
567 case 4:
597 ip_print (bp, length);
598 return;
568 ip_print (bp, length);
569 return;
599#ifdef INET6
600 case 6:
570#ifdef INET6
571 case 6:
601 ip6_print (bp, length);
602 return;
572 ip6_print (bp, length);
573 return;
603#endif
604 default:
574#endif
575 default:
605 (void)printf("unknown ip %d", IP_V(&hdr));
606 return;
576 (void)printf("unknown ip %d", IP_V(&hdr));
577 return;
607 }
608}
578 }
579}