kmalloc: Avoid code duplication.
[dragonfly.git] / contrib / tcpdump / print-lane.c
blobaa7931154911f5106c984199583949c25ba572a7
1 /*
2 * Marko Kiiskila carnil@cs.tut.fi
4 * Tampere University of Technology - Telecommunications Laboratory
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.
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.
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
28 #ifdef HAVE_CONFIG_H
29 #include "config.h"
30 #endif
32 #include <tcpdump-stdinc.h>
34 #include <stdio.h>
35 #include <pcap.h>
37 #include "interface.h"
38 #include "addrtoname.h"
39 #include "extract.h"
40 #include "ether.h"
41 #include "lane.h"
43 static const struct tok lecop2str[] = {
44 { 0x0001, "configure request" },
45 { 0x0101, "configure response" },
46 { 0x0002, "join request" },
47 { 0x0102, "join response" },
48 { 0x0003, "ready query" },
49 { 0x0103, "ready indication" },
50 { 0x0004, "register request" },
51 { 0x0104, "register response" },
52 { 0x0005, "unregister request" },
53 { 0x0105, "unregister response" },
54 { 0x0006, "ARP request" },
55 { 0x0106, "ARP response" },
56 { 0x0007, "flush request" },
57 { 0x0107, "flush response" },
58 { 0x0008, "NARP request" },
59 { 0x0009, "topology request" },
60 { 0, NULL }
63 static void
64 lane_hdr_print(netdissect_options *ndo, const u_char *bp)
66 (void)ND_PRINT((ndo, "lecid:%x ", EXTRACT_16BITS(bp)));
70 * This is the top level routine of the printer. 'p' points
71 * to the LANE header of the packet, 'h->ts' is the timestamp,
72 * 'h->len' is the length of the packet off the wire, and 'h->caplen'
73 * is the number of bytes actually captured.
75 * This assumes 802.3, not 802.5, LAN emulation.
77 void
78 lane_print(const u_char *p, u_int length, u_int caplen)
80 struct lane_controlhdr *lec;
82 if (caplen < sizeof(struct lane_controlhdr)) {
83 printf("[|lane]");
84 return;
87 lec = (struct lane_controlhdr *)p;
88 if (EXTRACT_16BITS(&lec->lec_header) == 0xff00) {
90 * LE Control.
92 printf("lec: proto %x vers %x %s",
93 lec->lec_proto, lec->lec_vers,
94 tok2str(lecop2str, "opcode-#%u", EXTRACT_16BITS(&lec->lec_opcode)));
95 return;
99 * Go past the LE header.
101 length -= 2;
102 caplen -= 2;
103 p += 2;
106 * Now print the encapsulated frame, under the assumption
107 * that it's an Ethernet frame.
109 ether_print(gndo, p, length, caplen, lane_hdr_print, p - 2);
112 u_int
113 lane_if_print(const struct pcap_pkthdr *h, const u_char *p)
115 lane_print(p, h->len, h->caplen);
117 return (sizeof(struct lecdatahdr_8023));