10f74e101Schristos /* 20f74e101Schristos * Copyright (c) 1997 Yen Yen Lim and North Dakota State University 30f74e101Schristos * 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 Yen Yen Lim and 160f74e101Schristos North Dakota State University 170f74e101Schristos * 4. The name of the author may not be used to endorse or promote products 180f74e101Schristos * derived from this software without specific prior written permission. 190f74e101Schristos * 200f74e101Schristos * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 210f74e101Schristos * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 220f74e101Schristos * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 230f74e101Schristos * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, 240f74e101Schristos * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 250f74e101Schristos * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 260f74e101Schristos * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 270f74e101Schristos * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 280f74e101Schristos * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN 290f74e101Schristos * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 300f74e101Schristos * POSSIBILITY OF SUCH DAMAGE. 310f74e101Schristos */ 32b3a00663Schristos 3311b3aaa1Schristos #include <sys/cdefs.h> 340f74e101Schristos #ifndef lint 35*26ba0b50Schristos __RCSID("$NetBSD: print-sunatm.c,v 1.8 2024/09/02 16:15:33 christos Exp $"); 360f74e101Schristos #endif 370f74e101Schristos 38dc860a36Sspz /* \summary: SunATM DLPI capture printer */ 39dc860a36Sspz 40c74ad251Schristos #include <config.h> 410f74e101Schristos 42c74ad251Schristos #include "netdissect-stdinc.h" 430f74e101Schristos 44c74ad251Schristos #define ND_LONGJMP_FROM_TCHECK 45fdccd7e4Schristos #include "netdissect.h" 460f74e101Schristos #include "extract.h" 470f74e101Schristos 480f74e101Schristos #include "atm.h" 490f74e101Schristos 500f74e101Schristos /* SunATM header for ATM packet */ 510f74e101Schristos #define DIR_POS 0 /* Direction (0x80 = transmit, 0x00 = receive) */ 520f74e101Schristos #define VPI_POS 1 /* VPI */ 530f74e101Schristos #define VCI_POS 2 /* VCI */ 540f74e101Schristos #define PKT_BEGIN_POS 4 /* Start of the ATM packet */ 550f74e101Schristos 560f74e101Schristos /* Protocol type values in the bottom for bits of the byte at SUNATM_DIR_POS. */ 570f74e101Schristos #define PT_LANE 0x01 /* LANE */ 580f74e101Schristos #define PT_LLC 0x02 /* LLC encapsulation */ 590f74e101Schristos 600f74e101Schristos /* 610f74e101Schristos * This is the top level routine of the printer. 'p' points 620f74e101Schristos * to the SunATM pseudo-header for the packet, 'h->ts' is the timestamp, 630f74e101Schristos * 'h->len' is the length of the packet off the wire, and 'h->caplen' 640f74e101Schristos * is the number of bytes actually captured. 650f74e101Schristos */ 66c74ad251Schristos void 67b3a00663Schristos sunatm_if_print(netdissect_options *ndo, 68b3a00663Schristos const struct pcap_pkthdr *h, const u_char *p) 690f74e101Schristos { 700f74e101Schristos u_int caplen = h->caplen; 710f74e101Schristos u_int length = h->len; 720f74e101Schristos u_short vci; 730f74e101Schristos u_char vpi; 740f74e101Schristos u_int traftype; 750f74e101Schristos 76c74ad251Schristos ndo->ndo_protocol = "sunatm"; 770f74e101Schristos 78b3a00663Schristos if (ndo->ndo_eflag) { 79c74ad251Schristos ND_PRINT(GET_U_1(p + DIR_POS) & 0x80 ? "Tx: " : "Rx: "); 800f74e101Schristos } 810f74e101Schristos 82c74ad251Schristos switch (GET_U_1(p + DIR_POS) & 0x0f) { 830f74e101Schristos 840f74e101Schristos case PT_LANE: 850f74e101Schristos traftype = ATM_LANE; 860f74e101Schristos break; 870f74e101Schristos 880f74e101Schristos case PT_LLC: 890f74e101Schristos traftype = ATM_LLC; 900f74e101Schristos break; 910f74e101Schristos 920f74e101Schristos default: 930f74e101Schristos traftype = ATM_UNKNOWN; 940f74e101Schristos break; 950f74e101Schristos } 960f74e101Schristos 97c74ad251Schristos vpi = GET_U_1(p + VPI_POS); 98c74ad251Schristos vci = GET_BE_U_2(p + VCI_POS); 990f74e101Schristos 1000f74e101Schristos p += PKT_BEGIN_POS; 1010f74e101Schristos caplen -= PKT_BEGIN_POS; 1020f74e101Schristos length -= PKT_BEGIN_POS; 103c74ad251Schristos ndo->ndo_ll_hdr_len += PKT_BEGIN_POS; 104b3a00663Schristos atm_print(ndo, vpi, vci, traftype, p, length, caplen); 1050f74e101Schristos } 106