]> The Tcpdump Group git mirrors - tcpdump/blob - print-lane.c
Merge branch 'master' of git+ssh://bpf.tcpdump.org/tcpdump/master/git/tcpdump
[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[] _U_ =
25 "@(#) $Header: /tcpdump/master/tcpdump/print-lane.c,v 1.25 2005-11-13 12:12:42 guy Exp $ (LBL)";
26 #endif
27
28 #ifdef HAVE_CONFIG_H
29 #include "config.h"
30 #endif
31
32 #include <tcpdump-stdinc.h>
33
34 #include <stdio.h>
35 #include <pcap.h>
36
37 #include "interface.h"
38 #include "addrtoname.h"
39 #include "extract.h"
40 #include "ether.h"
41
42 #ifndef ETHER_ADDR_LEN
43 #define ETHER_ADDR_LEN 6
44 #endif
45
46 struct lecdatahdr_8023 {
47 u_int16_t le_header;
48 u_int8_t h_dest[ETHER_ADDR_LEN];
49 u_int8_t h_source[ETHER_ADDR_LEN];
50 u_int16_t h_type;
51 };
52
53 struct lane_controlhdr {
54 u_int16_t lec_header;
55 u_int8_t lec_proto;
56 u_int8_t lec_vers;
57 u_int16_t lec_opcode;
58 };
59
60 static const struct tok lecop2str[] = {
61 { 0x0001, "configure request" },
62 { 0x0101, "configure response" },
63 { 0x0002, "join request" },
64 { 0x0102, "join response" },
65 { 0x0003, "ready query" },
66 { 0x0103, "ready indication" },
67 { 0x0004, "register request" },
68 { 0x0104, "register response" },
69 { 0x0005, "unregister request" },
70 { 0x0105, "unregister response" },
71 { 0x0006, "ARP request" },
72 { 0x0106, "ARP response" },
73 { 0x0007, "flush request" },
74 { 0x0107, "flush response" },
75 { 0x0008, "NARP request" },
76 { 0x0009, "topology request" },
77 { 0, NULL }
78 };
79
80 static void
81 lane_hdr_print(netdissect_options *ndo, const u_char *bp)
82 {
83 (void)ND_PRINT((ndo, "lecid:%x ", EXTRACT_16BITS(bp)));
84 }
85
86 /*
87 * This is the top level routine of the printer. 'p' points
88 * to the LANE header of the packet, 'h->ts' is the timestamp,
89 * 'h->len' is the length of the packet off the wire, and 'h->caplen'
90 * is the number of bytes actually captured.
91 *
92 * This assumes 802.3, not 802.5, LAN emulation.
93 */
94 void
95 lane_print(const u_char *p, u_int length, u_int caplen)
96 {
97 struct lane_controlhdr *lec;
98
99 if (caplen < sizeof(struct lane_controlhdr)) {
100 printf("[|lane]");
101 return;
102 }
103
104 lec = (struct lane_controlhdr *)p;
105 if (EXTRACT_16BITS(&lec->lec_header) == 0xff00) {
106 /*
107 * LE Control.
108 */
109 printf("lec: proto %x vers %x %s",
110 lec->lec_proto, lec->lec_vers,
111 tok2str(lecop2str, "opcode-#%u", EXTRACT_16BITS(&lec->lec_opcode)));
112 return;
113 }
114
115 /*
116 * Go past the LE header.
117 */
118 length -= 2;
119 caplen -= 2;
120 p += 2;
121
122 /*
123 * Now print the encapsulated frame, under the assumption
124 * that it's an Ethernet frame.
125 */
126 ether_print(gndo, p, length, caplen, lane_hdr_print, p - 2);
127 }
128
129 u_int
130 lane_if_print(const struct pcap_pkthdr *h, const u_char *p)
131 {
132 lane_print(p, h->len, h->caplen);
133
134 return (sizeof(struct lecdatahdr_8023));
135 }