141c99275SPeter Avalos /*
241c99275SPeter Avalos * Copyright (c) 1997 Yen Yen Lim and North Dakota State University
341c99275SPeter Avalos * All rights reserved.
441c99275SPeter Avalos *
541c99275SPeter Avalos * Redistribution and use in source and binary forms, with or without
641c99275SPeter Avalos * modification, are permitted provided that the following conditions
741c99275SPeter Avalos * are met:
841c99275SPeter Avalos * 1. Redistributions of source code must retain the above copyright
941c99275SPeter Avalos * notice, this list of conditions and the following disclaimer.
1041c99275SPeter Avalos * 2. Redistributions in binary form must reproduce the above copyright
1141c99275SPeter Avalos * notice, this list of conditions and the following disclaimer in the
1241c99275SPeter Avalos * documentation and/or other materials provided with the distribution.
1341c99275SPeter Avalos * 3. All advertising materials mentioning features or use of this software
1441c99275SPeter Avalos * must display the following acknowledgement:
1541c99275SPeter Avalos * This product includes software developed by Yen Yen Lim and
1641c99275SPeter Avalos North Dakota State University
1741c99275SPeter Avalos * 4. The name of the author may not be used to endorse or promote products
1841c99275SPeter Avalos * derived from this software without specific prior written permission.
1941c99275SPeter Avalos *
2041c99275SPeter Avalos * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
2141c99275SPeter Avalos * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
2241c99275SPeter Avalos * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
2341c99275SPeter Avalos * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT,
2441c99275SPeter Avalos * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
2541c99275SPeter Avalos * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
2641c99275SPeter Avalos * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
2741c99275SPeter Avalos * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
2841c99275SPeter Avalos * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
2941c99275SPeter Avalos * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
3041c99275SPeter Avalos * POSSIBILITY OF SUCH DAMAGE.
3141c99275SPeter Avalos */
32411677aeSAaron LI
33411677aeSAaron LI /* \summary: SunATM DLPI capture printer */
3441c99275SPeter Avalos
3541c99275SPeter Avalos #ifdef HAVE_CONFIG_H
36*ed775ee7SAntonio Huete Jimenez #include <config.h>
3741c99275SPeter Avalos #endif
3841c99275SPeter Avalos
39*ed775ee7SAntonio Huete Jimenez #include "netdissect-stdinc.h"
4041c99275SPeter Avalos
41*ed775ee7SAntonio Huete Jimenez #define ND_LONGJMP_FROM_TCHECK
42411677aeSAaron LI #include "netdissect.h"
4341c99275SPeter Avalos #include "extract.h"
4441c99275SPeter Avalos
4541c99275SPeter Avalos #include "atm.h"
4641c99275SPeter Avalos
4741c99275SPeter Avalos /* SunATM header for ATM packet */
4841c99275SPeter Avalos #define DIR_POS 0 /* Direction (0x80 = transmit, 0x00 = receive) */
4941c99275SPeter Avalos #define VPI_POS 1 /* VPI */
5041c99275SPeter Avalos #define VCI_POS 2 /* VCI */
5141c99275SPeter Avalos #define PKT_BEGIN_POS 4 /* Start of the ATM packet */
5241c99275SPeter Avalos
5341c99275SPeter Avalos /* Protocol type values in the bottom for bits of the byte at SUNATM_DIR_POS. */
5441c99275SPeter Avalos #define PT_LANE 0x01 /* LANE */
5541c99275SPeter Avalos #define PT_LLC 0x02 /* LLC encapsulation */
5641c99275SPeter Avalos
5741c99275SPeter Avalos /*
5841c99275SPeter Avalos * This is the top level routine of the printer. 'p' points
5941c99275SPeter Avalos * to the SunATM pseudo-header for the packet, 'h->ts' is the timestamp,
6041c99275SPeter Avalos * 'h->len' is the length of the packet off the wire, and 'h->caplen'
6141c99275SPeter Avalos * is the number of bytes actually captured.
6241c99275SPeter Avalos */
63*ed775ee7SAntonio Huete Jimenez void
sunatm_if_print(netdissect_options * ndo,const struct pcap_pkthdr * h,const u_char * p)64411677aeSAaron LI sunatm_if_print(netdissect_options *ndo,
65411677aeSAaron LI const struct pcap_pkthdr *h, const u_char *p)
6641c99275SPeter Avalos {
6741c99275SPeter Avalos u_int caplen = h->caplen;
6841c99275SPeter Avalos u_int length = h->len;
6941c99275SPeter Avalos u_short vci;
7041c99275SPeter Avalos u_char vpi;
7141c99275SPeter Avalos u_int traftype;
7241c99275SPeter Avalos
73*ed775ee7SAntonio Huete Jimenez ndo->ndo_protocol = "sunatm";
7441c99275SPeter Avalos
75411677aeSAaron LI if (ndo->ndo_eflag) {
76*ed775ee7SAntonio Huete Jimenez ND_PRINT(GET_U_1(p + DIR_POS) & 0x80 ? "Tx: " : "Rx: ");
7741c99275SPeter Avalos }
7841c99275SPeter Avalos
79*ed775ee7SAntonio Huete Jimenez switch (GET_U_1(p + DIR_POS) & 0x0f) {
8041c99275SPeter Avalos
8141c99275SPeter Avalos case PT_LANE:
8241c99275SPeter Avalos traftype = ATM_LANE;
8341c99275SPeter Avalos break;
8441c99275SPeter Avalos
8541c99275SPeter Avalos case PT_LLC:
8641c99275SPeter Avalos traftype = ATM_LLC;
8741c99275SPeter Avalos break;
8841c99275SPeter Avalos
8941c99275SPeter Avalos default:
9041c99275SPeter Avalos traftype = ATM_UNKNOWN;
9141c99275SPeter Avalos break;
9241c99275SPeter Avalos }
9341c99275SPeter Avalos
94*ed775ee7SAntonio Huete Jimenez vpi = GET_U_1(p + VPI_POS);
95*ed775ee7SAntonio Huete Jimenez vci = GET_BE_U_2(p + VCI_POS);
9641c99275SPeter Avalos
9741c99275SPeter Avalos p += PKT_BEGIN_POS;
9841c99275SPeter Avalos caplen -= PKT_BEGIN_POS;
9941c99275SPeter Avalos length -= PKT_BEGIN_POS;
100*ed775ee7SAntonio Huete Jimenez ndo->ndo_ll_hdr_len += PKT_BEGIN_POS;
101411677aeSAaron LI atm_print(ndo, vpi, vci, traftype, p, length, caplen);
10241c99275SPeter Avalos }
103