1127668Sbms/* 2127668Sbms * Copyright (c) 1993, 1994, 1995, 1996, 1997, 1998 3127668Sbms * The Regents of the University of California. All rights reserved. 4127668Sbms * 5127668Sbms * Redistribution and use in source and binary forms, with or without 6127668Sbms * modification, are permitted provided that the following conditions 7127668Sbms * are met: 8127668Sbms * 1. Redistributions of source code must retain the above copyright 9127668Sbms * notice, this list of conditions and the following disclaimer. 10127668Sbms * 2. Redistributions in binary form must reproduce the above copyright 11127668Sbms * notice, this list of conditions and the following disclaimer in the 12127668Sbms * documentation and/or other materials provided with the distribution. 13127668Sbms * 3. All advertising materials mentioning features or use of this software 14127668Sbms * must display the following acknowledgement: 15127668Sbms * This product includes software developed by the Computer Systems 16127668Sbms * Engineering Group at Lawrence Berkeley Laboratory. 17127668Sbms * 4. Neither the name of the University nor of the Laboratory may be used 18127668Sbms * to endorse or promote products derived from this software without 19127668Sbms * specific prior written permission. 20127668Sbms * 21127668Sbms * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 22127668Sbms * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 23127668Sbms * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 24127668Sbms * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 25127668Sbms * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 26127668Sbms * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 27127668Sbms * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 28127668Sbms * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 29127668Sbms * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 30127668Sbms * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 31127668Sbms * SUCH DAMAGE. 32127668Sbms */ 33127668Sbms 34127668Sbms#ifdef HAVE_CONFIG_H 35127668Sbms#include "config.h" 36127668Sbms#endif 37127668Sbms 38313537Sglebius#include <netdissect-stdinc.h> 39127668Sbms 40127668Sbms#include <pcap.h> 41127668Sbms#include <string.h> 42127668Sbms 43127668Sbms#include "pcap-missing.h" 44313537Sglebius#include "ascii_strcasecmp.h" 45127668Sbms 46127668Sbmsstruct dlt_choice { 47127668Sbms const char *name; 48127668Sbms const char *description; 49127668Sbms int dlt; 50127668Sbms}; 51127668Sbms 52127668Sbms#define DLT_CHOICE(code, description) { #code, description, code } 53127668Sbms#define DLT_CHOICE_SENTINEL { NULL, NULL, 0 } 54127668Sbms 55127668Sbmsstatic struct dlt_choice dlt_choices[] = { 56127668Sbms DLT_CHOICE(DLT_NULL, "BSD loopback"), 57127668Sbms DLT_CHOICE(DLT_EN10MB, "Ethernet"), 58127668Sbms DLT_CHOICE(DLT_IEEE802, "Token ring"), 59127668Sbms DLT_CHOICE(DLT_ARCNET, "ARCNET"), 60127668Sbms DLT_CHOICE(DLT_SLIP, "SLIP"), 61127668Sbms DLT_CHOICE(DLT_PPP, "PPP"), 62127668Sbms DLT_CHOICE(DLT_FDDI, "FDDI"), 63127668Sbms DLT_CHOICE(DLT_ATM_RFC1483, "RFC 1483 IP-over-ATM"), 64127668Sbms DLT_CHOICE(DLT_RAW, "Raw IP"), 65127668Sbms#ifdef DLT_SLIP_BSDOS 66127668Sbms DLT_CHOICE(DLT_SLIP_BSDOS, "BSD/OS SLIP"), 67127668Sbms#endif 68127668Sbms#ifdef DLT_PPP_BSDOS 69127668Sbms DLT_CHOICE(DLT_PPP_BSDOS, "BSD/OS PPP"), 70127668Sbms#endif 71127668Sbms#ifdef DLT_ATM_CLIP 72127668Sbms DLT_CHOICE(DLT_ATM_CLIP, "Linux Classical IP-over-ATM"), 73127668Sbms#endif 74127668Sbms#ifdef DLT_PPP_SERIAL 75127668Sbms DLT_CHOICE(DLT_PPP_SERIAL, "PPP over serial"), 76127668Sbms#endif 77127668Sbms#ifdef DLT_PPP_ETHER 78127668Sbms DLT_CHOICE(DLT_PPP_ETHER, "PPPoE"), 79127668Sbms#endif 80127668Sbms#ifdef DLT_C_HDLC 81127668Sbms DLT_CHOICE(DLT_C_HDLC, "Cisco HDLC"), 82127668Sbms#endif 83127668Sbms#ifdef DLT_IEEE802_11 84127668Sbms DLT_CHOICE(DLT_IEEE802_11, "802.11"), 85127668Sbms#endif 86127668Sbms#ifdef DLT_FRELAY 87127668Sbms DLT_CHOICE(DLT_FRELAY, "Frame Relay"), 88127668Sbms#endif 89127668Sbms#ifdef DLT_LOOP 90127668Sbms DLT_CHOICE(DLT_LOOP, "OpenBSD loopback"), 91127668Sbms#endif 92127668Sbms#ifdef DLT_ENC 93127668Sbms DLT_CHOICE(DLT_ENC, "OpenBSD encapsulated IP"), 94127668Sbms#endif 95127668Sbms#ifdef DLT_LINUX_SLL 96127668Sbms DLT_CHOICE(DLT_LINUX_SLL, "Linux cooked"), 97127668Sbms#endif 98127668Sbms#ifdef DLT_LTALK 99127668Sbms DLT_CHOICE(DLT_LTALK, "Localtalk"), 100127668Sbms#endif 101127668Sbms#ifdef DLT_PFLOG 102127668Sbms DLT_CHOICE(DLT_PFLOG, "OpenBSD pflog file"), 103127668Sbms#endif 104127668Sbms#ifdef DLT_PRISM_HEADER 105127668Sbms DLT_CHOICE(DLT_PRISM_HEADER, "802.11 plus Prism header"), 106127668Sbms#endif 107127668Sbms#ifdef DLT_IP_OVER_FC 108127668Sbms DLT_CHOICE(DLT_IP_OVER_FC, "RFC 2625 IP-over-Fibre Channel"), 109127668Sbms#endif 110127668Sbms#ifdef DLT_SUNATM 111127668Sbms DLT_CHOICE(DLT_SUNATM, "Sun raw ATM"), 112127668Sbms#endif 113127668Sbms#ifdef DLT_IEEE802_11_RADIO 114127668Sbms DLT_CHOICE(DLT_IEEE802_11_RADIO, "802.11 plus radio information header"), 115127668Sbms#endif 116127668Sbms#ifdef DLT_ARCNET_LINUX 117127668Sbms DLT_CHOICE(DLT_ARCNET_LINUX, "Linux ARCNET"), 118127668Sbms#endif 119127668Sbms#ifdef DLT_LINUX_IRDA 120127668Sbms DLT_CHOICE(DLT_LINUX_IRDA, "Linux IrDA"), 121127668Sbms#endif 122127668Sbms#ifdef DLT_LANE8023 123127668Sbms DLT_CHOICE(DLT_LANE8023, "Linux 802.3 LANE"), 124127668Sbms#endif 125127668Sbms#ifdef DLT_CIP 126127668Sbms DLT_CHOICE(DLT_CIP, "Linux Classical IP-over-ATM"), 127127668Sbms#endif 128127668Sbms#ifdef DLT_HDLC 129127668Sbms DLT_CHOICE(DLT_HDLC, "Cisco HDLC"), 130127668Sbms#endif 131127668Sbms DLT_CHOICE_SENTINEL 132127668Sbms}; 133127668Sbms 134127668Sbms#ifndef HAVE_PCAP_DATALINK_NAME_TO_VAL 135127668Sbmsint 136127668Sbmspcap_datalink_name_to_val(const char *name) 137127668Sbms{ 138127668Sbms int i; 139127668Sbms 140127668Sbms for (i = 0; dlt_choices[i].name != NULL; i++) { 141313537Sglebius if (ascii_strcasecmp(dlt_choices[i].name + sizeof("DLT_") - 1, 142127668Sbms name) == 0) 143127668Sbms return (dlt_choices[i].dlt); 144127668Sbms } 145127668Sbms return (-1); 146127668Sbms} 147127668Sbms 148127668Sbmsconst char * 149127668Sbmspcap_datalink_val_to_name(int dlt) 150127668Sbms{ 151127668Sbms int i; 152127668Sbms 153127668Sbms for (i = 0; dlt_choices[i].name != NULL; i++) { 154127668Sbms if (dlt_choices[i].dlt == dlt) 155127668Sbms return (dlt_choices[i].name + sizeof("DLT_") - 1); 156127668Sbms } 157127668Sbms return (NULL); 158127668Sbms} 159127668Sbms#endif 160127668Sbms 161127668Sbmsconst char * 162127668Sbmspcap_datalink_val_to_description(int dlt) 163127668Sbms{ 164127668Sbms int i; 165127668Sbms 166127668Sbms for (i = 0; dlt_choices[i].name != NULL; i++) { 167127668Sbms if (dlt_choices[i].dlt == dlt) 168127668Sbms return (dlt_choices[i].description); 169127668Sbms } 170127668Sbms return (NULL); 171127668Sbms} 172