PageRenderTime 53ms CodeModel.GetById 28ms RepoModel.GetById 0ms app.codeStats 0ms

/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
  1. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
  2. "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
  3. <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
  4. <head>
  5. <title>print-vjc.c</title>
  6. <style type="text/css">
  7. .enscript-comment { font-style: italic; color: rgb(178,34,34); }
  8. .enscript-function-name { font-weight: bold; color: rgb(0,0,255); }
  9. .enscript-variable-name { font-weight: bold; color: rgb(184,134,11); }
  10. .enscript-keyword { font-weight: bold; color: rgb(160,32,240); }
  11. .enscript-reference { font-weight: bold; color: rgb(95,158,160); }
  12. .enscript-string { font-weight: bold; color: rgb(188,143,143); }
  13. .enscript-builtin { font-weight: bold; color: rgb(218,112,214); }
  14. .enscript-type { font-weight: bold; color: rgb(34,139,34); }
  15. .enscript-highlight { text-decoration: underline; color: 0; }
  16. </style>
  17. </head>
  18. <body id="top">
  19. <h1 style="margin:8px;" id="f1">print-vjc.c&nbsp;&nbsp;&nbsp;<span style="font-weight: normal; font-size: 0.5em;">[<a href="?txt">plain text</a>]</span></h1>
  20. <hr/>
  21. <div></div>
  22. <pre>
  23. <span class="enscript-comment">/*
  24. * Copyright (c) 1990, 1991, 1993, 1994, 1995, 1996, 1997
  25. * The Regents of the University of California. All rights reserved.
  26. *
  27. * Redistribution and use in source and binary forms, with or without
  28. * modification, are permitted provided that: (1) source code distributions
  29. * retain the above copyright notice and this paragraph in its entirety, (2)
  30. * distributions including binary code include the above copyright notice and
  31. * this paragraph in its entirety in the documentation or other materials
  32. * provided with the distribution, and (3) all advertising materials mentioning
  33. * features or use of this software display the following acknowledgement:
  34. * ``This product includes software developed by the University of California,
  35. * Lawrence Berkeley Laboratory and its contributors.'' Neither the name of
  36. * the University nor the names of its contributors may be used to endorse
  37. * or promote products derived from this software without specific prior
  38. * written permission.
  39. * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED
  40. * WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
  41. * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
  42. */</span>
  43. #<span class="enscript-reference">ifdef</span> <span class="enscript-variable-name">HAVE_CONFIG_H</span>
  44. #<span class="enscript-reference">include</span> <span class="enscript-string">&quot;config.h&quot;</span>
  45. #<span class="enscript-reference">endif</span>
  46. #<span class="enscript-reference">ifndef</span> <span class="enscript-variable-name">lint</span>
  47. <span class="enscript-type">static</span> <span class="enscript-type">const</span> <span class="enscript-type">char</span> rcsid[] _U_ =
  48. <span class="enscript-string">&quot;@(#) $Header: /cvs/root/tcpdump/tcpdump/print-vjc.c,v 1.1.1.3 2004/02/05 19:30:57 rbraun Exp $ (LBL)&quot;</span>;
  49. #<span class="enscript-reference">endif</span>
  50. #<span class="enscript-reference">include</span> <span class="enscript-string">&lt;tcpdump-stdinc.h&gt;</span>
  51. #<span class="enscript-reference">include</span> <span class="enscript-string">&lt;pcap.h&gt;</span>
  52. #<span class="enscript-reference">include</span> <span class="enscript-string">&lt;stdio.h&gt;</span>
  53. #<span class="enscript-reference">include</span> <span class="enscript-string">&quot;interface.h&quot;</span>
  54. #<span class="enscript-reference">include</span> <span class="enscript-string">&quot;addrtoname.h&quot;</span>
  55. #<span class="enscript-reference">include</span> <span class="enscript-string">&quot;slcompress.h&quot;</span>
  56. #<span class="enscript-reference">include</span> <span class="enscript-string">&quot;ppp.h&quot;</span>
  57. <span class="enscript-comment">/*
  58. * XXX - for BSD/OS PPP, what packets get supplied with a PPP header type
  59. * of PPP_VJC and what packets get supplied with a PPP header type of
  60. * PPP_VJNC? PPP_VJNC is for &quot;UNCOMPRESSED_TCP&quot; packets, and PPP_VJC
  61. * is for COMPRESSED_TCP packets (PPP_IP is used for TYPE_IP packets).
  62. *
  63. * RFC 1144 implies that, on the wire, the packet type is *not* needed
  64. * for PPP, as different PPP protocol types can be used; it only needs
  65. * to be put on the wire for SLIP.
  66. *
  67. * It also indicates that, for compressed SLIP:
  68. *
  69. * If the COMPRESSED_TCP bit is set in the first byte, it's
  70. * a COMPRESSED_TCP packet; that byte is the change byte, and
  71. * the COMPRESSED_TCP bit, 0x80, isn't used in the change byte.
  72. *
  73. * If the upper 4 bits of the first byte are 7, it's an
  74. * UNCOMPRESSED_TCP packet; that byte is the first byte of
  75. * the UNCOMPRESSED_TCP modified IP header, with a connection
  76. * number in the protocol field, and with the version field
  77. * being 7, not 4.
  78. *
  79. * Otherwise, the packet is an IPv4 packet (where the upper 4 bits
  80. * of the packet are 4).
  81. *
  82. * So this routine looks as if it's sort-of intended to handle
  83. * compressed SLIP, although it doesn't handle UNCOMPRESSED_TCP
  84. * correctly for that (it doesn't fix the version number and doesn't
  85. * do anything to the protocol field), and doesn't check for COMPRESSED_TCP
  86. * packets correctly for that (you only check the first bit - see
  87. * B.1 in RFC 1144).
  88. *
  89. * But it's called for BSD/OS PPP, not SLIP - perhaps BSD/OS does weird
  90. * things with the headers?
  91. *
  92. * Without a BSD/OS VJC-compressed PPP trace, or knowledge of what the
  93. * BSD/OS VJC code does, we can't say what's the case.
  94. *
  95. * We therefore leave &quot;proto&quot; - which is the PPP protocol type - in place,
  96. * *not* marked as unused, for now, so that GCC warnings about the
  97. * unused argument remind us that we should fix this some day.
  98. */</span>
  99. <span class="enscript-type">int</span>
  100. <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)
  101. {
  102. <span class="enscript-type">int</span> i;
  103. <span class="enscript-keyword">switch</span> (bp[0] &amp; 0xf0) {
  104. <span class="enscript-keyword">case</span> <span class="enscript-reference">TYPE_IP</span>:
  105. <span class="enscript-keyword">if</span> (eflag)
  106. printf(<span class="enscript-string">&quot;(vjc type=IP) &quot;</span>);
  107. <span class="enscript-keyword">return</span> PPP_IP;
  108. <span class="enscript-keyword">case</span> <span class="enscript-reference">TYPE_UNCOMPRESSED_TCP</span>:
  109. <span class="enscript-keyword">if</span> (eflag)
  110. printf(<span class="enscript-string">&quot;(vjc type=raw TCP) &quot;</span>);
  111. <span class="enscript-keyword">return</span> PPP_IP;
  112. <span class="enscript-keyword">case</span> <span class="enscript-reference">TYPE_COMPRESSED_TCP</span>:
  113. <span class="enscript-keyword">if</span> (eflag)
  114. printf(<span class="enscript-string">&quot;(vjc type=compressed TCP) &quot;</span>);
  115. <span class="enscript-keyword">for</span> (i = 0; i &lt; 8; i++) {
  116. <span class="enscript-keyword">if</span> (bp[1] &amp; (0x80 &gt;&gt; i))
  117. printf(<span class="enscript-string">&quot;%c&quot;</span>, <span class="enscript-string">&quot;?CI?SAWU&quot;</span>[i]);
  118. }
  119. <span class="enscript-keyword">if</span> (bp[1])
  120. printf(<span class="enscript-string">&quot; &quot;</span>);
  121. printf(<span class="enscript-string">&quot;C=0x%02x &quot;</span>, bp[2]);
  122. printf(<span class="enscript-string">&quot;sum=0x%04x &quot;</span>, *(u_short *)&amp;bp[3]);
  123. <span class="enscript-keyword">return</span> -1;
  124. <span class="enscript-keyword">case</span> <span class="enscript-reference">TYPE_ERROR</span>:
  125. <span class="enscript-keyword">if</span> (eflag)
  126. printf(<span class="enscript-string">&quot;(vjc type=error) &quot;</span>);
  127. <span class="enscript-keyword">return</span> -1;
  128. <span class="enscript-reference">default</span>:
  129. <span class="enscript-keyword">if</span> (eflag)
  130. printf(<span class="enscript-string">&quot;(vjc type=0x%02x) &quot;</span>, bp[0] &amp; 0xf0);
  131. <span class="enscript-keyword">return</span> -1;
  132. }
  133. }
  134. </pre>
  135. <hr />
  136. </body></html>