The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 1997 Yen Yen Lim and North Dakota State University |
| 3 | * All rights reserved. |
| 4 | * |
| 5 | * Redistribution and use in source and binary forms, with or without |
| 6 | * modification, are permitted provided that the following conditions |
| 7 | * are met: |
| 8 | * 1. Redistributions of source code must retain the above copyright |
| 9 | * notice, this list of conditions and the following disclaimer. |
| 10 | * 2. Redistributions in binary form must reproduce the above copyright |
| 11 | * notice, this list of conditions and the following disclaimer in the |
| 12 | * documentation and/or other materials provided with the distribution. |
| 13 | * 3. All advertising materials mentioning features or use of this software |
| 14 | * must display the following acknowledgement: |
| 15 | * This product includes software developed by Yen Yen Lim and |
| 16 | North Dakota State University |
| 17 | * 4. The name of the author may not be used to endorse or promote products |
| 18 | * derived from this software without specific prior written permission. |
| 19 | * |
| 20 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR |
| 21 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED |
| 22 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE |
| 23 | * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, |
| 24 | * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES |
| 25 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR |
| 26 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) |
| 27 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, |
| 28 | * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN |
| 29 | * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
| 30 | * POSSIBILITY OF SUCH DAMAGE. |
| 31 | */ |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 32 | |
Elliott Hughes | e2e3bd1 | 2017-05-15 10:59:29 -0700 | [diff] [blame] | 33 | /* \summary: SunATM DLPI capture printer */ |
| 34 | |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 35 | #ifdef HAVE_CONFIG_H |
| 36 | #include "config.h" |
| 37 | #endif |
| 38 | |
Elliott Hughes | e2e3bd1 | 2017-05-15 10:59:29 -0700 | [diff] [blame] | 39 | #include <netdissect-stdinc.h> |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 40 | |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 41 | struct mbuf; |
| 42 | struct rtentry; |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 43 | |
Elliott Hughes | e2e3bd1 | 2017-05-15 10:59:29 -0700 | [diff] [blame] | 44 | #include "netdissect.h" |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 45 | #include "extract.h" |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 46 | |
| 47 | #include "atm.h" |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 48 | |
| 49 | /* SunATM header for ATM packet */ |
| 50 | #define DIR_POS 0 /* Direction (0x80 = transmit, 0x00 = receive) */ |
| 51 | #define VPI_POS 1 /* VPI */ |
| 52 | #define VCI_POS 2 /* VCI */ |
| 53 | #define PKT_BEGIN_POS 4 /* Start of the ATM packet */ |
| 54 | |
| 55 | /* Protocol type values in the bottom for bits of the byte at SUNATM_DIR_POS. */ |
| 56 | #define PT_LANE 0x01 /* LANE */ |
| 57 | #define PT_LLC 0x02 /* LLC encapsulation */ |
| 58 | |
| 59 | /* |
| 60 | * This is the top level routine of the printer. 'p' points |
| 61 | * to the SunATM pseudo-header for the packet, 'h->ts' is the timestamp, |
| 62 | * 'h->len' is the length of the packet off the wire, and 'h->caplen' |
| 63 | * is the number of bytes actually captured. |
| 64 | */ |
| 65 | u_int |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 66 | sunatm_if_print(netdissect_options *ndo, |
| 67 | const struct pcap_pkthdr *h, const u_char *p) |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 68 | { |
| 69 | u_int caplen = h->caplen; |
| 70 | u_int length = h->len; |
| 71 | u_short vci; |
| 72 | u_char vpi; |
| 73 | u_int traftype; |
| 74 | |
| 75 | if (caplen < PKT_BEGIN_POS) { |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 76 | ND_PRINT((ndo, "[|atm]")); |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 77 | return (caplen); |
| 78 | } |
| 79 | |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 80 | if (ndo->ndo_eflag) { |
| 81 | ND_PRINT((ndo, p[DIR_POS] & 0x80 ? "Tx: " : "Rx: ")); |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 82 | } |
| 83 | |
| 84 | switch (p[DIR_POS] & 0x0f) { |
| 85 | |
| 86 | case PT_LANE: |
| 87 | traftype = ATM_LANE; |
| 88 | break; |
| 89 | |
| 90 | case PT_LLC: |
| 91 | traftype = ATM_LLC; |
| 92 | break; |
| 93 | |
| 94 | default: |
| 95 | traftype = ATM_UNKNOWN; |
| 96 | break; |
| 97 | } |
| 98 | |
| 99 | vci = EXTRACT_16BITS(&p[VCI_POS]); |
| 100 | vpi = p[VPI_POS]; |
| 101 | |
| 102 | p += PKT_BEGIN_POS; |
| 103 | caplen -= PKT_BEGIN_POS; |
| 104 | length -= PKT_BEGIN_POS; |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 105 | atm_print(ndo, vpi, vci, traftype, p, length, caplen); |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 106 | |
| 107 | return (PKT_BEGIN_POS); |
| 108 | } |