The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Marko Kiiskila carnil@cs.tut.fi |
| 3 | * |
| 4 | * Tampere University of Technology - Telecommunications Laboratory |
| 5 | * |
| 6 | * Permission to use, copy, modify and distribute this |
| 7 | * software and its documentation is hereby granted, |
| 8 | * provided that both the copyright notice and this |
| 9 | * permission notice appear in all copies of the software, |
| 10 | * derivative works or modified versions, and any portions |
| 11 | * thereof, that both notices appear in supporting |
| 12 | * documentation, and that the use of this software is |
| 13 | * acknowledged in any publications resulting from using |
| 14 | * the software. |
| 15 | * |
| 16 | * TUT ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS" |
| 17 | * CONDITION AND DISCLAIMS ANY LIABILITY OF ANY KIND FOR |
| 18 | * ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS |
| 19 | * SOFTWARE. |
| 20 | * |
| 21 | */ |
| 22 | |
Elliott Hughes | e2e3bd1 | 2017-05-15 10:59:29 -0700 | [diff] [blame] | 23 | /* \summary: Classical-IP over ATM printer */ |
| 24 | |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 25 | #ifdef HAVE_CONFIG_H |
| 26 | #include "config.h" |
| 27 | #endif |
| 28 | |
| 29 | #include <string.h> |
| 30 | |
Elliott Hughes | e2e3bd1 | 2017-05-15 10:59:29 -0700 | [diff] [blame] | 31 | #include <netdissect-stdinc.h> |
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 | #include "netdissect.h" |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 34 | #include "addrtoname.h" |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 35 | |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 36 | static const unsigned char rfcllc[] = { |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 37 | 0xaa, /* DSAP: non-ISO */ |
| 38 | 0xaa, /* SSAP: non-ISO */ |
| 39 | 0x03, /* Ctrl: Unnumbered Information Command PDU */ |
| 40 | 0x00, /* OUI: EtherType */ |
| 41 | 0x00, |
| 42 | 0x00 }; |
| 43 | |
| 44 | static inline void |
Elliott Hughes | e2e3bd1 | 2017-05-15 10:59:29 -0700 | [diff] [blame] | 45 | cip_print(netdissect_options *ndo, u_int length) |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 46 | { |
| 47 | /* |
| 48 | * There is no MAC-layer header, so just print the length. |
| 49 | */ |
Elliott Hughes | e2e3bd1 | 2017-05-15 10:59:29 -0700 | [diff] [blame] | 50 | ND_PRINT((ndo, "%u: ", length)); |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 51 | } |
| 52 | |
| 53 | /* |
| 54 | * This is the top level routine of the printer. 'p' points |
| 55 | * to the LLC/SNAP or raw header of the packet, 'h->ts' is the timestamp, |
| 56 | * 'h->len' is the length of the packet off the wire, and 'h->caplen' |
| 57 | * is the number of bytes actually captured. |
| 58 | */ |
| 59 | u_int |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 60 | cip_if_print(netdissect_options *ndo, const struct pcap_pkthdr *h, const u_char *p) |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 61 | { |
| 62 | u_int caplen = h->caplen; |
| 63 | u_int length = h->len; |
Elliott Hughes | e2e3bd1 | 2017-05-15 10:59:29 -0700 | [diff] [blame] | 64 | size_t cmplen; |
| 65 | int llc_hdrlen; |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 66 | |
Elliott Hughes | e2e3bd1 | 2017-05-15 10:59:29 -0700 | [diff] [blame] | 67 | cmplen = sizeof(rfcllc); |
| 68 | if (cmplen > caplen) |
| 69 | cmplen = caplen; |
| 70 | if (cmplen > length) |
| 71 | cmplen = length; |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 72 | |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 73 | if (ndo->ndo_eflag) |
| 74 | cip_print(ndo, length); |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 75 | |
Elliott Hughes | e2e3bd1 | 2017-05-15 10:59:29 -0700 | [diff] [blame] | 76 | if (cmplen == 0) { |
| 77 | ND_PRINT((ndo, "[|cip]")); |
| 78 | return 0; |
| 79 | } |
| 80 | if (memcmp(rfcllc, p, cmplen) == 0) { |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 81 | /* |
| 82 | * LLC header is present. Try to print it & higher layers. |
| 83 | */ |
Elliott Hughes | e2e3bd1 | 2017-05-15 10:59:29 -0700 | [diff] [blame] | 84 | llc_hdrlen = llc_print(ndo, p, length, caplen, NULL, NULL); |
| 85 | if (llc_hdrlen < 0) { |
| 86 | /* packet type not known, print raw packet */ |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 87 | if (!ndo->ndo_suppress_default_print) |
| 88 | ND_DEFAULTPRINT(p, caplen); |
Elliott Hughes | e2e3bd1 | 2017-05-15 10:59:29 -0700 | [diff] [blame] | 89 | llc_hdrlen = -llc_hdrlen; |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 90 | } |
| 91 | } else { |
| 92 | /* |
| 93 | * LLC header is absent; treat it as just IP. |
| 94 | */ |
Elliott Hughes | e2e3bd1 | 2017-05-15 10:59:29 -0700 | [diff] [blame] | 95 | llc_hdrlen = 0; |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 96 | ip_print(ndo, p, length); |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 97 | } |
| 98 | |
Elliott Hughes | e2e3bd1 | 2017-05-15 10:59:29 -0700 | [diff] [blame] | 99 | return (llc_hdrlen); |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 100 | } |
| 101 | |
| 102 | |
| 103 | /* |
| 104 | * Local Variables: |
| 105 | * c-style: whitesmith |
| 106 | * c-basic-offset: 8 |
| 107 | * End: |
| 108 | */ |