/opensource.apple.com/source/tcpdump/tcpdump-11/tcpdump/print-vjc.c
C | 144 lines | 78 code | 8 blank | 58 comment | 0 complexity | b9d8beae925231a7e80ef4bb4fa209ed MD5 | raw file
Possible License(s): MPL-2.0-no-copyleft-exception, GPL-2.0, BSD-3-Clause, GPL-3.0, MPL-2.0, LGPL-2.0, LGPL-2.1, CC-BY-SA-3.0, IPL-1.0, ISC, AGPL-1.0, AGPL-3.0, JSON, Apache-2.0, 0BSD
- <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
- "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
- <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
- <head>
- <title>print-vjc.c</title>
- <style type="text/css">
- .enscript-comment { font-style: italic; color: rgb(178,34,34); }
- .enscript-function-name { font-weight: bold; color: rgb(0,0,255); }
- .enscript-variable-name { font-weight: bold; color: rgb(184,134,11); }
- .enscript-keyword { font-weight: bold; color: rgb(160,32,240); }
- .enscript-reference { font-weight: bold; color: rgb(95,158,160); }
- .enscript-string { font-weight: bold; color: rgb(188,143,143); }
- .enscript-builtin { font-weight: bold; color: rgb(218,112,214); }
- .enscript-type { font-weight: bold; color: rgb(34,139,34); }
- .enscript-highlight { text-decoration: underline; color: 0; }
- </style>
- </head>
- <body id="top">
- <h1 style="margin:8px;" id="f1">print-vjc.c <span style="font-weight: normal; font-size: 0.5em;">[<a href="?txt">plain text</a>]</span></h1>
- <hr/>
- <div></div>
- <pre>
- <span class="enscript-comment">/*
- * Copyright (c) 1990, 1991, 1993, 1994, 1995, 1996, 1997
- * The Regents of the University of California. All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that: (1) source code distributions
- * retain the above copyright notice and this paragraph in its entirety, (2)
- * distributions including binary code include the above copyright notice and
- * this paragraph in its entirety in the documentation or other materials
- * provided with the distribution, and (3) all advertising materials mentioning
- * features or use of this software display the following acknowledgement:
- * ``This product includes software developed by the University of California,
- * Lawrence Berkeley Laboratory and its contributors.'' Neither the name of
- * the University nor the names of its contributors may be used to endorse
- * or promote products derived from this software without specific prior
- * written permission.
- * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED
- * WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
- * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
- */</span>
- #<span class="enscript-reference">ifdef</span> <span class="enscript-variable-name">HAVE_CONFIG_H</span>
- #<span class="enscript-reference">include</span> <span class="enscript-string">"config.h"</span>
- #<span class="enscript-reference">endif</span>
- #<span class="enscript-reference">ifndef</span> <span class="enscript-variable-name">lint</span>
- <span class="enscript-type">static</span> <span class="enscript-type">const</span> <span class="enscript-type">char</span> rcsid[] _U_ =
- <span class="enscript-string">"@(#) $Header: /cvs/root/tcpdump/tcpdump/print-vjc.c,v 1.1.1.3 2004/02/05 19:30:57 rbraun Exp $ (LBL)"</span>;
- #<span class="enscript-reference">endif</span>
- #<span class="enscript-reference">include</span> <span class="enscript-string"><tcpdump-stdinc.h></span>
- #<span class="enscript-reference">include</span> <span class="enscript-string"><pcap.h></span>
- #<span class="enscript-reference">include</span> <span class="enscript-string"><stdio.h></span>
- #<span class="enscript-reference">include</span> <span class="enscript-string">"interface.h"</span>
- #<span class="enscript-reference">include</span> <span class="enscript-string">"addrtoname.h"</span>
- #<span class="enscript-reference">include</span> <span class="enscript-string">"slcompress.h"</span>
- #<span class="enscript-reference">include</span> <span class="enscript-string">"ppp.h"</span>
- <span class="enscript-comment">/*
- * XXX - for BSD/OS PPP, what packets get supplied with a PPP header type
- * of PPP_VJC and what packets get supplied with a PPP header type of
- * PPP_VJNC? PPP_VJNC is for "UNCOMPRESSED_TCP" packets, and PPP_VJC
- * is for COMPRESSED_TCP packets (PPP_IP is used for TYPE_IP packets).
- *
- * RFC 1144 implies that, on the wire, the packet type is *not* needed
- * for PPP, as different PPP protocol types can be used; it only needs
- * to be put on the wire for SLIP.
- *
- * It also indicates that, for compressed SLIP:
- *
- * If the COMPRESSED_TCP bit is set in the first byte, it's
- * a COMPRESSED_TCP packet; that byte is the change byte, and
- * the COMPRESSED_TCP bit, 0x80, isn't used in the change byte.
- *
- * If the upper 4 bits of the first byte are 7, it's an
- * UNCOMPRESSED_TCP packet; that byte is the first byte of
- * the UNCOMPRESSED_TCP modified IP header, with a connection
- * number in the protocol field, and with the version field
- * being 7, not 4.
- *
- * Otherwise, the packet is an IPv4 packet (where the upper 4 bits
- * of the packet are 4).
- *
- * So this routine looks as if it's sort-of intended to handle
- * compressed SLIP, although it doesn't handle UNCOMPRESSED_TCP
- * correctly for that (it doesn't fix the version number and doesn't
- * do anything to the protocol field), and doesn't check for COMPRESSED_TCP
- * packets correctly for that (you only check the first bit - see
- * B.1 in RFC 1144).
- *
- * But it's called for BSD/OS PPP, not SLIP - perhaps BSD/OS does weird
- * things with the headers?
- *
- * Without a BSD/OS VJC-compressed PPP trace, or knowledge of what the
- * BSD/OS VJC code does, we can't say what's the case.
- *
- * We therefore leave "proto" - which is the PPP protocol type - in place,
- * *not* marked as unused, for now, so that GCC warnings about the
- * unused argument remind us that we should fix this some day.
- */</span>
- <span class="enscript-type">int</span>
- <span class="enscript-function-name">vjc_print</span>(<span class="enscript-type">register</span> <span class="enscript-type">const</span> <span class="enscript-type">char</span> *bp, u_short proto)
- {
- <span class="enscript-type">int</span> i;
- <span class="enscript-keyword">switch</span> (bp[0] & 0xf0) {
- <span class="enscript-keyword">case</span> <span class="enscript-reference">TYPE_IP</span>:
- <span class="enscript-keyword">if</span> (eflag)
- printf(<span class="enscript-string">"(vjc type=IP) "</span>);
- <span class="enscript-keyword">return</span> PPP_IP;
- <span class="enscript-keyword">case</span> <span class="enscript-reference">TYPE_UNCOMPRESSED_TCP</span>:
- <span class="enscript-keyword">if</span> (eflag)
- printf(<span class="enscript-string">"(vjc type=raw TCP) "</span>);
- <span class="enscript-keyword">return</span> PPP_IP;
- <span class="enscript-keyword">case</span> <span class="enscript-reference">TYPE_COMPRESSED_TCP</span>:
- <span class="enscript-keyword">if</span> (eflag)
- printf(<span class="enscript-string">"(vjc type=compressed TCP) "</span>);
- <span class="enscript-keyword">for</span> (i = 0; i < 8; i++) {
- <span class="enscript-keyword">if</span> (bp[1] & (0x80 >> i))
- printf(<span class="enscript-string">"%c"</span>, <span class="enscript-string">"?CI?SAWU"</span>[i]);
- }
- <span class="enscript-keyword">if</span> (bp[1])
- printf(<span class="enscript-string">" "</span>);
- printf(<span class="enscript-string">"C=0x%02x "</span>, bp[2]);
- printf(<span class="enscript-string">"sum=0x%04x "</span>, *(u_short *)&bp[3]);
- <span class="enscript-keyword">return</span> -1;
- <span class="enscript-keyword">case</span> <span class="enscript-reference">TYPE_ERROR</span>:
- <span class="enscript-keyword">if</span> (eflag)
- printf(<span class="enscript-string">"(vjc type=error) "</span>);
- <span class="enscript-keyword">return</span> -1;
- <span class="enscript-reference">default</span>:
- <span class="enscript-keyword">if</span> (eflag)
- printf(<span class="enscript-string">"(vjc type=0x%02x) "</span>, bp[0] & 0xf0);
- <span class="enscript-keyword">return</span> -1;
- }
- }
- </pre>
- <hr />
- </body></html>