]>
git.saurik.com Git - apple/network_cmds.git/blob - tcpdump.tproj/print-gre.c
2 * Copyright (c) 1999 Apple Computer, Inc. All rights reserved.
4 * @APPLE_LICENSE_HEADER_START@
6 * "Portions Copyright (c) 1999 Apple Computer, Inc. All Rights
7 * Reserved. This file contains Original Code and/or Modifications of
8 * Original Code as defined in and that are subject to the Apple Public
9 * Source License Version 1.0 (the 'License'). You may not use this file
10 * except in compliance with the License. Please obtain a copy of the
11 * License at http://www.apple.com/publicsource and read it before using
14 * The Original Code and all software distributed under the License are
15 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
16 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
17 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the
19 * License for the specific language governing rights and limitations
22 * @APPLE_LICENSE_HEADER_END@
26 * The Regents of the University of California. All rights reserved.
28 * Redistribution and use in source and binary forms are permitted
29 * provided that the above copyright notice and this paragraph are
30 * duplicated in all such forms and that any documentation,
31 * advertising materials, and other materials related to such
32 * distribution and use acknowledge that the software was developed
33 * by the University of California, Lawrence Berkeley Laboratory,
34 * Berkeley, CA. The name of the University may not be used to
35 * endorse or promote products derived from this software without
36 * specific prior written permission.
37 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
38 * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
39 * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
41 * Initial contribution from John Hawkinson <jhawk@bbnplanet.com>
43 * This module implements support for decoding GRE (Generic Routing
44 * Encapsulation) tunnels; they're documented in RFC1701 and RFC1702.
45 * This code only supports the IP encapsulation thereof.
49 static const char rcsid
[] =
50 "@(#) $Header: /cvs/Darwin/Commands/NeXT/network_cmds/tcpdump.tproj/print-gre.c,v 1.1.1.1 1999/05/02 03:58:33 wsanchez Exp $";
53 #include <sys/param.h>
56 #include <sys/socket.h>
58 #include <netinet/in.h>
59 #include <netinet/in_systm.h>
60 #include <netinet/ip.h>
65 #include "interface.h"
66 #include "addrtoname.h"
67 #include "extract.h" /* must come after interface.h */
96 #define GRE_CP 0x8000 /* Checksum Present */
97 #define GRE_RP 0x4000 /* Routing Present */
98 #define GRE_KP 0x2000 /* Key Present */
99 #define GRE_SP 0x1000 /* Sequence Present */
102 #define GREPROTO_IP 0x0800
106 * Deencapsulate and print a GRE-tunneled IP datagram
109 gre_print(const u_char
*bp
, u_int length
)
111 const u_char
*cp
= bp
+ 4;
112 const struct gre
*gre
;
113 u_short flags
, proto
;
115 gre
= (const struct gre
*)bp
;
117 if (length
< GRE_SIZE
) {
120 flags
= EXTRACT_16BITS(&gre
->flags
);
121 proto
= EXTRACT_16BITS(&gre
->proto
);
124 /* Decode the flags */
136 /* Checksum & Offset are present */
137 if ((flags
& GRE_CP
) | (flags
& GRE_RP
))
140 /* We don't support routing fields (variable length) now. Punt. */
152 ip_print(cp
, length
- ((cp
- bp
) / sizeof(u_char
)));
156 printf("gre-proto-0x%04X", proto
);
162 fputs("[|gre]", stdout
);