]>
The Tcpdump Group git mirrors - tcpdump/blob - print-gre.c
3 * The Regents of the University of California. All rights reserved.
5 * Redistribution and use in source and binary forms are permitted
6 * provided that the above copyright notice and this paragraph are
7 * duplicated in all such forms and that any documentation,
8 * advertising materials, and other materials related to such
9 * distribution and use acknowledge that the software was developed
10 * by the University of California, Lawrence Berkeley Laboratory,
11 * Berkeley, CA. The name of the University may not be used to
12 * endorse or promote products derived from this software without
13 * specific prior written permission.
14 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
15 * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
16 * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
18 * Initial contribution from John Hawkinson <jhawk@bbnplanet.com>
20 * This module implements support for decoding GRE (Generic Routing
21 * Encapsulation) tunnels; they're documented in RFC1701 and RFC1702.
22 * This code only supports the IP encapsulation thereof.
26 static const char rcsid
[] =
27 "@(#) $Header: /tcpdump/master/tcpdump/print-gre.c,v 1.6 1999-11-21 09:36:52 fenner Exp $";
34 #include <sys/param.h>
37 #include <sys/socket.h>
39 #include <netinet/in.h>
40 #include <netinet/in_systm.h>
41 #include <netinet/ip.h>
46 #include "interface.h"
47 #include "addrtoname.h"
48 #include "extract.h" /* must come after interface.h */
77 #define GRE_CP 0x8000 /* Checksum Present */
78 #define GRE_RP 0x4000 /* Routing Present */
79 #define GRE_KP 0x2000 /* Key Present */
80 #define GRE_SP 0x1000 /* Sequence Present */
84 * Deencapsulate and print a GRE-tunneled IP datagram
87 gre_print(const u_char
*bp
, u_int length
)
89 const u_char
*cp
= bp
+ 4;
90 const struct gre
*gre
;
93 gre
= (const struct gre
*)bp
;
95 if (length
< GRE_SIZE
) {
98 flags
= EXTRACT_16BITS(&gre
->flags
);
99 proto
= EXTRACT_16BITS(&gre
->proto
);
102 /* Decode the flags */
114 /* Checksum & Offset are present */
115 if ((flags
& GRE_CP
) | (flags
& GRE_RP
))
118 /* We don't support routing fields (variable length) now. Punt. */
128 if (ether_encap_print(proto
, cp
, length
, length
) == 0)
129 printf("gre-proto-0x%04X", proto
);
133 fputs("[|gre]", stdout
);