]> The Tcpdump Group git mirrors - tcpdump/blob - missing/dlnames.c
NetBSD support for multiple data link types on an interface, from David
[tcpdump] / missing / dlnames.c
1 /*
2 * Copyright (c) 1993, 1994, 1995, 1996, 1997, 1998
3 * The Regents of the University of California. 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 the Computer Systems
16 * Engineering Group at Lawrence Berkeley Laboratory.
17 * 4. Neither the name of the University nor of the Laboratory may be used
18 * to endorse or promote products derived from this software without
19 * specific prior written permission.
20 *
21 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
22 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
25 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
26 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
27 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
28 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
29 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
30 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
31 * SUCH DAMAGE.
32 */
33
34 #ifndef lint
35 static const char rcsid[] =
36 "@(#) $Header: /tcpdump/master/tcpdump/missing/dlnames.c,v 1.1 2002-12-19 09:27:58 guy Exp $ (LBL)";
37 #endif
38
39 #ifdef HAVE_CONFIG_H
40 #include "config.h"
41 #endif
42
43 #include <tcpdump-stdinc.h>
44
45 #include <pcap.h>
46 #include <string.h>
47
48 #include "pcap-missing.h"
49
50 struct dlt_choice {
51 const char *name;
52 int dlt;
53 };
54
55 #define DLT_CHOICE(code) { #code, code }
56 #define DLT_CHOICE_SENTINEL { NULL, 0 }
57
58 static struct dlt_choice dlt_choices[] = {
59 DLT_CHOICE(DLT_ARCNET),
60 DLT_CHOICE(DLT_EN10MB),
61 DLT_CHOICE(DLT_SLIP),
62 DLT_CHOICE(DLT_SLIP_BSDOS),
63 DLT_CHOICE(DLT_NULL),
64 #ifdef DLT_LOOP
65 DLT_CHOICE(DLT_LOOP),
66 #endif
67 DLT_CHOICE(DLT_PPP),
68 #ifdef DLT_C_HDLC
69 DLT_CHOICE(DLT_C_HDLC),
70 #endif
71 #ifdef DLT_PPP_SERIAL
72 DLT_CHOICE(DLT_PPP_SERIAL),
73 #endif
74 #ifdef DLT_PPP_ETHER
75 DLT_CHOICE(DLT_PPP_ETHER),
76 #endif
77 DLT_CHOICE(DLT_PPP_BSDOS),
78 DLT_CHOICE(DLT_FDDI),
79 DLT_CHOICE(DLT_IEEE802),
80 #ifdef DLT_IEEE802_11
81 DLT_CHOICE(DLT_IEEE802_11),
82 #endif
83 #ifdef DLT_PRISM_HEADER
84 DLT_CHOICE(DLT_PRISM_HEADER),
85 #endif
86 #ifdef DLT_IEEE802_11_RADIO
87 DLT_CHOICE(DLT_IEEE802_11_RADIO),
88 #endif
89 DLT_CHOICE(DLT_ATM_RFC1483),
90 #ifdef DLT_ATM_CLIP
91 DLT_CHOICE(DLT_ATM_CLIP),
92 #endif
93 #ifdef DLT_SUNATM
94 DLT_CHOICE(DLT_SUNATM),
95 #endif
96 DLT_CHOICE(DLT_RAW),
97 #ifdef DLT_LINUX_SLL
98 DLT_CHOICE(DLT_LINUX_SLL),
99 #endif
100 #ifdef DLT_LTALK
101 DLT_CHOICE(DLT_LTALK),
102 #endif
103 #ifdef DLT_IP_OVER_FC
104 DLT_CHOICE(DLT_IP_OVER_FC),
105 #endif
106 #ifdef DLT_FRELAY
107 DLT_CHOICE(DLT_FRELAY),
108 #endif
109
110 #ifdef DLT_LANE8023
111 DLT_CHOICE(DLT_LANE8023),
112 #endif
113 #ifdef DLT_CIP
114 DLT_CHOICE(DLT_CIP),
115 #endif
116 #ifdef DLT_HDLC
117 DLT_CHOICE(DLT_HDLC),
118 #endif
119 #ifdef DLT_PFLOG
120 DLT_CHOICE(DLT_PFLOG),
121 #endif
122 DLT_CHOICE_SENTINEL
123 };
124
125 int
126 pcap_datalink_name_to_val(const char *name)
127 {
128 int i;
129
130 for (i = 0; dlt_choices[i].name != NULL; i++) {
131 if (strcasecmp(dlt_choices[i].name + sizeof("DLT_") - 1,
132 name) == 0)
133 return (dlt_choices[i].dlt);
134 }
135 return (-1);
136 }
137
138 const char *
139 pcap_datalink_val_to_name(int dlt)
140 {
141 int i;
142
143 for (i = 0; dlt_choices[i].name != NULL; i++) {
144 if (dlt_choices[i].dlt == dlt)
145 return (dlt_choices[i].name + sizeof("DLT_") - 1);
146 }
147 return (NULL);
148 }