]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - contrib/tcpdump/print-lane.c
This commit was generated by cvs2svn to compensate for changes in r91586,
[FreeBSD/FreeBSD.git] / contrib / tcpdump / print-lane.c
1 /*
2  * Marko Kiiskila carnil@cs.tut.fi 
3  * 
4  * Tampere University of Technology - Telecommunications Laboratory
5  *
6  * Permission to use, copy, modify and distribute this
7  * software and its documentation is hereby granted,
8  * provided that both the copyright notice and this
9  * permission notice appear in all copies of the software,
10  * derivative works or modified versions, and any portions
11  * thereof, that both notices appear in supporting
12  * documentation, and that the use of this software is
13  * acknowledged in any publications resulting from using
14  * the software.
15  * 
16  * TUT ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS"
17  * CONDITION AND DISCLAIMS ANY LIABILITY OF ANY KIND FOR
18  * ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS
19  * SOFTWARE.
20  * 
21  */
22
23 #ifndef lint
24 static const char rcsid[] =
25     "@(#) $Header: /tcpdump/master/tcpdump/print-lane.c,v 1.11 2000/12/22 22:45:11 guy Exp $ (LBL)";
26 #endif
27
28 #ifdef HAVE_CONFIG_H
29 #include "config.h"
30 #endif
31
32 #include <sys/param.h>
33 #include <sys/time.h>
34 #include <sys/types.h>
35 #include <sys/socket.h>
36
37
38 #include <netinet/in.h>
39
40 #include <stdio.h>
41 #include <pcap.h>
42
43 #include "interface.h"
44 #include "addrtoname.h"
45 #include "ether.h"
46 #include "lane.h"
47
48 static inline void
49 lane_print(register const u_char *bp, int length)
50 {
51         register const struct lecdatahdr_8023 *ep;
52
53         ep = (const struct lecdatahdr_8023 *)bp;
54         if (qflag)
55                 (void)printf("lecid:%d %s %s %d: ",
56                              ntohs(ep->le_header),
57                              etheraddr_string(ep->h_source),
58                              etheraddr_string(ep->h_dest),
59                              length);
60         else
61                 (void)printf("lecid:%d %s %s %s %d: ",
62                              ntohs(ep->le_header),
63                              etheraddr_string(ep->h_source),
64                              etheraddr_string(ep->h_dest),
65                              etherproto_string(ep->h_type),
66                              length);
67 }
68
69 /*
70  * This is the top level routine of the printer.  'p' is the points
71  * to the ether header of the packet, 'h->tv' is the timestamp,
72  * 'h->length' is the length of the packet off the wire, and 'h->caplen'
73  * is the number of bytes actually captured.
74  */
75 void
76 lane_if_print(u_char *user, const struct pcap_pkthdr *h, const u_char *p)
77 {
78         int caplen = h->caplen;
79         int length = h->len;
80         struct lecdatahdr_8023 *ep;
81         u_short ether_type;
82         u_short extracted_ethertype;
83
84         ts_print(&h->ts);
85
86         if (caplen < sizeof(struct lecdatahdr_8023)) {
87                 printf("[|lane]");
88                 goto out;
89         }
90
91         if (eflag)
92                 lane_print(p, length);
93
94         /*
95          * Some printers want to get back at the ethernet addresses,
96          * and/or check that they're not walking off the end of the packet.
97          * Rather than pass them all the way down, we set these globals.
98          */
99         packetp = p;
100         snapend = p + caplen;
101
102         length -= sizeof(struct lecdatahdr_8023);
103         caplen -= sizeof(struct lecdatahdr_8023);
104         ep = (struct lecdatahdr_8023 *)p;
105         p += sizeof(struct lecdatahdr_8023);
106
107         ether_type = ntohs(ep->h_type);
108
109         /*
110          * Is it (gag) an 802.3 encapsulation?
111          */
112         extracted_ethertype = 0;
113         if (ether_type < ETHERMTU) {
114                 /* Try to print the LLC-layer header & higher layers */
115                 if (llc_print(p, length, caplen, ep->h_source, ep->h_dest,
116                     &extracted_ethertype) == 0) {
117                         /* ether_type not known, print raw packet */
118                         if (!eflag)
119                                 lane_print((u_char *)ep, length + sizeof(*ep));
120                         if (extracted_ethertype) {
121                                 printf("(LLC %s) ",
122                                etherproto_string(htons(extracted_ethertype)));
123                         }
124                         if (!xflag && !qflag)
125                                 default_print(p, caplen);
126                 }
127         } else if (ether_encap_print(ether_type, p, length, caplen,
128             &extracted_ethertype) == 0) {
129                 /* ether_type not known, print raw packet */
130                 if (!eflag)
131                         lane_print((u_char *)ep, length + sizeof(*ep));
132                 if (!xflag && !qflag)
133                         default_print(p, caplen);
134         }
135         if (xflag)
136                 default_print(p, caplen);
137  out:
138         putchar('\n');
139 }