1127668Sbms/* 2127668Sbms * Copyright (c) 1997 Yen Yen Lim and North Dakota State University 3127668Sbms * 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 Yen Yen Lim and 16127668Sbms North Dakota State University 17127668Sbms * 4. The name of the author may not be used to endorse or promote products 18127668Sbms * derived from this software without specific prior written permission. 19127668Sbms * 20127668Sbms * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 21127668Sbms * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 22127668Sbms * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 23127668Sbms * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, 24127668Sbms * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 25127668Sbms * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 26127668Sbms * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 27127668Sbms * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 28127668Sbms * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN 29127668Sbms * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 30127668Sbms * POSSIBILITY OF SUCH DAMAGE. 31127668Sbms */ 32127668Sbms#ifndef lint 33127668Sbmsstatic const char rcsid[] _U_ = 34190207Srpaulo "@(#) $Header: /tcpdump/master/tcpdump/print-sunatm.c,v 1.8 2004-03-17 23:24:38 guy Exp $ (LBL)"; 35127668Sbms#endif 36127668Sbms 37127668Sbms#ifdef HAVE_CONFIG_H 38127668Sbms#include "config.h" 39127668Sbms#endif 40127668Sbms 41127668Sbms#include <tcpdump-stdinc.h> 42127668Sbms 43127668Sbmsstruct mbuf; 44127668Sbmsstruct rtentry; 45127668Sbms 46127668Sbms#include <stdio.h> 47127668Sbms#include <pcap.h> 48127668Sbms 49127668Sbms#include "interface.h" 50127668Sbms#include "extract.h" 51127668Sbms#include "addrtoname.h" 52127668Sbms 53127668Sbms#include "atm.h" 54127668Sbms#include "atmuni31.h" 55127668Sbms 56127668Sbms/* SunATM header for ATM packet */ 57127668Sbms#define DIR_POS 0 /* Direction (0x80 = transmit, 0x00 = receive) */ 58127668Sbms#define VPI_POS 1 /* VPI */ 59127668Sbms#define VCI_POS 2 /* VCI */ 60127668Sbms#define PKT_BEGIN_POS 4 /* Start of the ATM packet */ 61127668Sbms 62127668Sbms/* Protocol type values in the bottom for bits of the byte at SUNATM_DIR_POS. */ 63127668Sbms#define PT_LANE 0x01 /* LANE */ 64127668Sbms#define PT_LLC 0x02 /* LLC encapsulation */ 65127668Sbms 66127668Sbms/* 67127668Sbms * This is the top level routine of the printer. 'p' points 68127668Sbms * to the SunATM pseudo-header for the packet, 'h->ts' is the timestamp, 69146773Ssam * 'h->len' is the length of the packet off the wire, and 'h->caplen' 70127668Sbms * is the number of bytes actually captured. 71127668Sbms */ 72127668Sbmsu_int 73127668Sbmssunatm_if_print(const struct pcap_pkthdr *h, const u_char *p) 74127668Sbms{ 75127668Sbms u_int caplen = h->caplen; 76127668Sbms u_int length = h->len; 77127668Sbms u_short vci; 78127668Sbms u_char vpi; 79127668Sbms u_int traftype; 80127668Sbms 81127668Sbms if (caplen < PKT_BEGIN_POS) { 82127668Sbms printf("[|atm]"); 83127668Sbms return (caplen); 84127668Sbms } 85127668Sbms 86127668Sbms if (eflag) { 87127668Sbms if (p[DIR_POS] & 0x80) 88127668Sbms printf("Tx: "); 89127668Sbms else 90127668Sbms printf("Rx: "); 91127668Sbms } 92127668Sbms 93127668Sbms switch (p[DIR_POS] & 0x0f) { 94127668Sbms 95127668Sbms case PT_LANE: 96127668Sbms traftype = ATM_LANE; 97127668Sbms break; 98127668Sbms 99127668Sbms case PT_LLC: 100127668Sbms traftype = ATM_LLC; 101127668Sbms break; 102127668Sbms 103127668Sbms default: 104127668Sbms traftype = ATM_UNKNOWN; 105127668Sbms break; 106127668Sbms } 107127668Sbms 108127668Sbms vci = EXTRACT_16BITS(&p[VCI_POS]); 109127668Sbms vpi = p[VPI_POS]; 110127668Sbms 111127668Sbms p += PKT_BEGIN_POS; 112127668Sbms caplen -= PKT_BEGIN_POS; 113127668Sbms length -= PKT_BEGIN_POS; 114127668Sbms atm_print(vpi, vci, traftype, p, length, caplen); 115127668Sbms 116127668Sbms return (PKT_BEGIN_POS); 117127668Sbms} 118