Merge from vendor branch GCC:
[dragonfly.git] / contrib / tcpdump-3.9 / print-sunatm.c
1 /*
2  * Copyright (c) 1997 Yen Yen Lim and North Dakota State University
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions
7  * are met:
8  * 1. Redistributions of source code must retain the above copyright
9  *    notice, this list of conditions and the following disclaimer.
10  * 2. Redistributions in binary form must reproduce the above copyright
11  *    notice, this list of conditions and the following disclaimer in the
12  *    documentation and/or other materials provided with the distribution.
13  * 3. All advertising materials mentioning features or use of this software
14  *    must display the following acknowledgement:
15  *      This product includes software developed by Yen Yen Lim and
16         North Dakota State University
17  * 4. The name of the author may not be used to endorse or promote products
18  *    derived from this software without specific prior written permission.
19  *
20  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
21  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
22  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
23  * DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT,
24  * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
25  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
26  * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
27  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
28  * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
29  * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
30  * POSSIBILITY OF SUCH DAMAGE.
31  */
32 #ifndef lint
33 static const char rcsid[] _U_ =
34     "@(#) $Header: /tcpdump/master/tcpdump/print-sunatm.c,v 1.8 2004/03/17 23:24:38 guy Exp $ (LBL)";
35 #endif
36
37 #ifdef HAVE_CONFIG_H
38 #include "config.h"
39 #endif
40
41 #include <tcpdump-stdinc.h>
42  
43 struct mbuf;
44 struct rtentry;
45  
46 #include <stdio.h>
47 #include <pcap.h>
48
49 #include "interface.h"
50 #include "extract.h"
51 #include "addrtoname.h"
52
53 #include "atm.h"
54 #include "atmuni31.h"
55
56 /* SunATM header for ATM packet */
57 #define DIR_POS         0       /* Direction (0x80 = transmit, 0x00 = receive) */
58 #define VPI_POS         1       /* VPI */
59 #define VCI_POS         2       /* VCI */
60 #define PKT_BEGIN_POS   4       /* Start of the ATM packet */
61
62 /* Protocol type values in the bottom for bits of the byte at SUNATM_DIR_POS. */
63 #define PT_LANE         0x01    /* LANE */
64 #define PT_LLC          0x02    /* LLC encapsulation */
65
66 /*
67  * This is the top level routine of the printer.  'p' points
68  * to the SunATM pseudo-header for the packet, 'h->ts' is the timestamp,
69  * 'h->len' is the length of the packet off the wire, and 'h->caplen'
70  * is the number of bytes actually captured.
71  */
72 u_int
73 sunatm_if_print(const struct pcap_pkthdr *h, const u_char *p)
74 {
75         u_int caplen = h->caplen;
76         u_int length = h->len;
77         u_short vci;
78         u_char vpi;
79         u_int traftype;
80
81         if (caplen < PKT_BEGIN_POS) {
82                 printf("[|atm]");
83                 return (caplen);
84         }
85
86         if (eflag) {
87                 if (p[DIR_POS] & 0x80)
88                         printf("Tx: ");
89                 else
90                         printf("Rx: ");
91         }
92
93         switch (p[DIR_POS] & 0x0f) {
94
95         case PT_LANE:
96                 traftype = ATM_LANE;
97                 break;
98
99         case PT_LLC:
100                 traftype = ATM_LLC;
101                 break;
102
103         default:
104                 traftype = ATM_UNKNOWN;
105                 break;
106         }
107
108         vci = EXTRACT_16BITS(&p[VCI_POS]);
109         vpi = p[VPI_POS];
110
111         p += PKT_BEGIN_POS;
112         caplen -= PKT_BEGIN_POS;
113         length -= PKT_BEGIN_POS;
114         atm_print(vpi, vci, traftype, p, length, caplen);
115
116         return (PKT_BEGIN_POS);
117 }