10f74e101Schristos /* 20f74e101Schristos * Copyright (c) 1993, 1994, 1995, 1996, 1997, 1998 30f74e101Schristos * The Regents of the University of California. All rights reserved. 40f74e101Schristos * 50f74e101Schristos * Redistribution and use in source and binary forms, with or without 60f74e101Schristos * modification, are permitted provided that the following conditions 70f74e101Schristos * are met: 80f74e101Schristos * 1. Redistributions of source code must retain the above copyright 90f74e101Schristos * notice, this list of conditions and the following disclaimer. 100f74e101Schristos * 2. Redistributions in binary form must reproduce the above copyright 110f74e101Schristos * notice, this list of conditions and the following disclaimer in the 120f74e101Schristos * documentation and/or other materials provided with the distribution. 130f74e101Schristos * 3. All advertising materials mentioning features or use of this software 140f74e101Schristos * must display the following acknowledgement: 150f74e101Schristos * This product includes software developed by the Computer Systems 160f74e101Schristos * Engineering Group at Lawrence Berkeley Laboratory. 170f74e101Schristos * 4. Neither the name of the University nor of the Laboratory may be used 180f74e101Schristos * to endorse or promote products derived from this software without 190f74e101Schristos * specific prior written permission. 200f74e101Schristos * 210f74e101Schristos * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 220f74e101Schristos * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 230f74e101Schristos * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 240f74e101Schristos * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 250f74e101Schristos * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 260f74e101Schristos * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 270f74e101Schristos * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 280f74e101Schristos * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 290f74e101Schristos * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 300f74e101Schristos * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 310f74e101Schristos * SUCH DAMAGE. 320f74e101Schristos */ 330f74e101Schristos 34*d881c474Schristos #include <config.h> 350f74e101Schristos 36784088dfSchristos #include <netdissect-stdinc.h> 370f74e101Schristos 380f74e101Schristos #include <pcap.h> 390f74e101Schristos #include <string.h> 400f74e101Schristos 410f74e101Schristos #include "pcap-missing.h" 42784088dfSchristos #include "ascii_strcasecmp.h" 430f74e101Schristos 440f74e101Schristos struct dlt_choice { 450f74e101Schristos const char *name; 460f74e101Schristos const char *description; 470f74e101Schristos int dlt; 480f74e101Schristos }; 490f74e101Schristos 500f74e101Schristos #define DLT_CHOICE(code, description) { #code, description, code } 510f74e101Schristos #define DLT_CHOICE_SENTINEL { NULL, NULL, 0 } 520f74e101Schristos 530f74e101Schristos static struct dlt_choice dlt_choices[] = { 540f74e101Schristos DLT_CHOICE(DLT_NULL, "BSD loopback"), 550f74e101Schristos DLT_CHOICE(DLT_EN10MB, "Ethernet"), 560f74e101Schristos DLT_CHOICE(DLT_IEEE802, "Token ring"), 570f74e101Schristos DLT_CHOICE(DLT_ARCNET, "ARCNET"), 580f74e101Schristos DLT_CHOICE(DLT_SLIP, "SLIP"), 590f74e101Schristos DLT_CHOICE(DLT_PPP, "PPP"), 600f74e101Schristos DLT_CHOICE(DLT_FDDI, "FDDI"), 610f74e101Schristos DLT_CHOICE(DLT_ATM_RFC1483, "RFC 1483 IP-over-ATM"), 620f74e101Schristos DLT_CHOICE(DLT_RAW, "Raw IP"), 630f74e101Schristos #ifdef DLT_SLIP_BSDOS 640f74e101Schristos DLT_CHOICE(DLT_SLIP_BSDOS, "BSD/OS SLIP"), 650f74e101Schristos #endif 660f74e101Schristos #ifdef DLT_PPP_BSDOS 670f74e101Schristos DLT_CHOICE(DLT_PPP_BSDOS, "BSD/OS PPP"), 680f74e101Schristos #endif 690f74e101Schristos #ifdef DLT_ATM_CLIP 700f74e101Schristos DLT_CHOICE(DLT_ATM_CLIP, "Linux Classical IP-over-ATM"), 710f74e101Schristos #endif 720f74e101Schristos #ifdef DLT_PPP_SERIAL 730f74e101Schristos DLT_CHOICE(DLT_PPP_SERIAL, "PPP over serial"), 740f74e101Schristos #endif 750f74e101Schristos #ifdef DLT_PPP_ETHER 760f74e101Schristos DLT_CHOICE(DLT_PPP_ETHER, "PPPoE"), 770f74e101Schristos #endif 780f74e101Schristos #ifdef DLT_C_HDLC 790f74e101Schristos DLT_CHOICE(DLT_C_HDLC, "Cisco HDLC"), 800f74e101Schristos #endif 810f74e101Schristos #ifdef DLT_IEEE802_11 820f74e101Schristos DLT_CHOICE(DLT_IEEE802_11, "802.11"), 830f74e101Schristos #endif 840f74e101Schristos #ifdef DLT_FRELAY 850f74e101Schristos DLT_CHOICE(DLT_FRELAY, "Frame Relay"), 860f74e101Schristos #endif 870f74e101Schristos #ifdef DLT_LOOP 880f74e101Schristos DLT_CHOICE(DLT_LOOP, "OpenBSD loopback"), 890f74e101Schristos #endif 900f74e101Schristos #ifdef DLT_ENC 910f74e101Schristos DLT_CHOICE(DLT_ENC, "OpenBSD encapsulated IP"), 920f74e101Schristos #endif 930f74e101Schristos #ifdef DLT_LINUX_SLL 940f74e101Schristos DLT_CHOICE(DLT_LINUX_SLL, "Linux cooked"), 950f74e101Schristos #endif 960f74e101Schristos #ifdef DLT_LTALK 970f74e101Schristos DLT_CHOICE(DLT_LTALK, "Localtalk"), 980f74e101Schristos #endif 990f74e101Schristos #ifdef DLT_PFLOG 1000f74e101Schristos DLT_CHOICE(DLT_PFLOG, "OpenBSD pflog file"), 1010f74e101Schristos #endif 1020f74e101Schristos #ifdef DLT_PRISM_HEADER 1030f74e101Schristos DLT_CHOICE(DLT_PRISM_HEADER, "802.11 plus Prism header"), 1040f74e101Schristos #endif 1050f74e101Schristos #ifdef DLT_IP_OVER_FC 1060f74e101Schristos DLT_CHOICE(DLT_IP_OVER_FC, "RFC 2625 IP-over-Fibre Channel"), 1070f74e101Schristos #endif 1080f74e101Schristos #ifdef DLT_SUNATM 1090f74e101Schristos DLT_CHOICE(DLT_SUNATM, "Sun raw ATM"), 1100f74e101Schristos #endif 1110f74e101Schristos #ifdef DLT_IEEE802_11_RADIO 1120f74e101Schristos DLT_CHOICE(DLT_IEEE802_11_RADIO, "802.11 plus radio information header"), 1130f74e101Schristos #endif 1140f74e101Schristos #ifdef DLT_ARCNET_LINUX 1150f74e101Schristos DLT_CHOICE(DLT_ARCNET_LINUX, "Linux ARCNET"), 1160f74e101Schristos #endif 1170f74e101Schristos #ifdef DLT_LINUX_IRDA 1180f74e101Schristos DLT_CHOICE(DLT_LINUX_IRDA, "Linux IrDA"), 1190f74e101Schristos #endif 1200f74e101Schristos #ifdef DLT_CIP 1210f74e101Schristos DLT_CHOICE(DLT_CIP, "Linux Classical IP-over-ATM"), 1220f74e101Schristos #endif 1230f74e101Schristos #ifdef DLT_HDLC 1240f74e101Schristos DLT_CHOICE(DLT_HDLC, "Cisco HDLC"), 1250f74e101Schristos #endif 1260f74e101Schristos DLT_CHOICE_SENTINEL 1270f74e101Schristos }; 1280f74e101Schristos 1290f74e101Schristos #ifndef HAVE_PCAP_DATALINK_NAME_TO_VAL 1300f74e101Schristos int 1310f74e101Schristos pcap_datalink_name_to_val(const char *name) 1320f74e101Schristos { 1330f74e101Schristos int i; 1340f74e101Schristos 1350f74e101Schristos for (i = 0; dlt_choices[i].name != NULL; i++) { 136784088dfSchristos if (ascii_strcasecmp(dlt_choices[i].name + sizeof("DLT_") - 1, 1370f74e101Schristos name) == 0) 1380f74e101Schristos return (dlt_choices[i].dlt); 1390f74e101Schristos } 1400f74e101Schristos return (-1); 1410f74e101Schristos } 1420f74e101Schristos 1430f74e101Schristos const char * 1440f74e101Schristos pcap_datalink_val_to_name(int dlt) 1450f74e101Schristos { 1460f74e101Schristos int i; 1470f74e101Schristos 1480f74e101Schristos for (i = 0; dlt_choices[i].name != NULL; i++) { 1490f74e101Schristos if (dlt_choices[i].dlt == dlt) 1500f74e101Schristos return (dlt_choices[i].name + sizeof("DLT_") - 1); 1510f74e101Schristos } 1520f74e101Schristos return (NULL); 1530f74e101Schristos } 1540f74e101Schristos #endif 1550f74e101Schristos 1560f74e101Schristos const char * 1570f74e101Schristos pcap_datalink_val_to_description(int dlt) 1580f74e101Schristos { 1590f74e101Schristos int i; 1600f74e101Schristos 1610f74e101Schristos for (i = 0; dlt_choices[i].name != NULL; i++) { 1620f74e101Schristos if (dlt_choices[i].dlt == dlt) 1630f74e101Schristos return (dlt_choices[i].description); 1640f74e101Schristos } 1650f74e101Schristos return (NULL); 1660f74e101Schristos } 167