The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 1988, 1989, 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1997 |
| 3 | * The Regents of the University of California. All rights reserved. |
| 4 | * |
| 5 | * Redistribution and use in source and binary forms, with or without |
| 6 | * modification, are permitted provided that: (1) source code distributions |
| 7 | * retain the above copyright notice and this paragraph in its entirety, (2) |
| 8 | * distributions including binary code include the above copyright notice and |
| 9 | * this paragraph in its entirety in the documentation or other materials |
| 10 | * provided with the distribution, and (3) all advertising materials mentioning |
| 11 | * features or use of this software display the following acknowledgement: |
| 12 | * ``This product includes software developed by the University of California, |
| 13 | * Lawrence Berkeley Laboratory and its contributors.'' Neither the name of |
| 14 | * the University nor the names of its contributors may be used to endorse |
| 15 | * or promote products derived from this software without specific prior |
| 16 | * written permission. |
| 17 | * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED |
| 18 | * WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF |
| 19 | * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 20 | */ |
| 21 | |
Elliott Hughes | e2e3bd1 | 2017-05-15 10:59:29 -0700 | [diff] [blame] | 22 | /* \summary: AppleTalk printer */ |
| 23 | |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 24 | #ifdef HAVE_CONFIG_H |
Elliott Hughes | 820eced | 2021-08-20 18:00:50 -0700 | [diff] [blame] | 25 | #include <config.h> |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 26 | #endif |
| 27 | |
Elliott Hughes | 820eced | 2021-08-20 18:00:50 -0700 | [diff] [blame] | 28 | #include "netdissect-stdinc.h" |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 29 | |
| 30 | #include <stdio.h> |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 31 | #include <string.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" |
| 35 | #include "ethertype.h" |
Elliott Hughes | e2e3bd1 | 2017-05-15 10:59:29 -0700 | [diff] [blame] | 36 | #include "extract.h" |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 37 | #include "appletalk.h" |
| 38 | |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 39 | |
JP Abgrall | 53f17a9 | 2014-02-12 14:02:41 -0800 | [diff] [blame] | 40 | static const struct tok type2str[] = { |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 41 | { ddpRTMP, "rtmp" }, |
| 42 | { ddpRTMPrequest, "rtmpReq" }, |
| 43 | { ddpECHO, "echo" }, |
| 44 | { ddpIP, "IP" }, |
| 45 | { ddpARP, "ARP" }, |
| 46 | { ddpKLAP, "KLAP" }, |
| 47 | { 0, NULL } |
| 48 | }; |
| 49 | |
| 50 | struct aarp { |
Elliott Hughes | 820eced | 2021-08-20 18:00:50 -0700 | [diff] [blame] | 51 | nd_uint16_t htype, ptype; |
| 52 | nd_uint8_t halen, palen; |
| 53 | nd_uint16_t op; |
| 54 | nd_mac_addr hsaddr; |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 55 | uint8_t psaddr[4]; |
Elliott Hughes | 820eced | 2021-08-20 18:00:50 -0700 | [diff] [blame] | 56 | nd_mac_addr hdaddr; |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 57 | uint8_t pdaddr[4]; |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 58 | }; |
| 59 | |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 60 | static void atp_print(netdissect_options *, const struct atATP *, u_int); |
| 61 | static void atp_bitmap_print(netdissect_options *, u_char); |
| 62 | static void nbp_print(netdissect_options *, const struct atNBP *, u_int, u_short, u_char, u_char); |
| 63 | static const struct atNBPtuple *nbp_tuple_print(netdissect_options *ndo, const struct atNBPtuple *, |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 64 | const u_char *, |
| 65 | u_short, u_char, u_char); |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 66 | static const struct atNBPtuple *nbp_name_print(netdissect_options *, const struct atNBPtuple *, |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 67 | const u_char *); |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 68 | static const char *ataddr_string(netdissect_options *, u_short, u_char); |
Elliott Hughes | 820eced | 2021-08-20 18:00:50 -0700 | [diff] [blame] | 69 | static void ddp_print(netdissect_options *, const u_char *, u_int, u_int, u_short, u_char, u_char); |
| 70 | static const char *ddpskt_string(netdissect_options *, u_int); |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 71 | |
| 72 | /* |
| 73 | * Print LLAP packets received on a physical LocalTalk interface. |
| 74 | */ |
Elliott Hughes | 820eced | 2021-08-20 18:00:50 -0700 | [diff] [blame] | 75 | void |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 76 | ltalk_if_print(netdissect_options *ndo, |
| 77 | const struct pcap_pkthdr *h, const u_char *p) |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 78 | { |
Elliott Hughes | e2e3bd1 | 2017-05-15 10:59:29 -0700 | [diff] [blame] | 79 | u_int hdrlen; |
| 80 | |
Elliott Hughes | 820eced | 2021-08-20 18:00:50 -0700 | [diff] [blame] | 81 | ndo->ndo_protocol = "ltalk"; |
Elliott Hughes | e2e3bd1 | 2017-05-15 10:59:29 -0700 | [diff] [blame] | 82 | hdrlen = llap_print(ndo, p, h->len); |
| 83 | if (hdrlen == 0) { |
| 84 | /* Cut short by the snapshot length. */ |
Elliott Hughes | 820eced | 2021-08-20 18:00:50 -0700 | [diff] [blame] | 85 | ndo->ndo_ll_hdr_len += h->caplen; |
| 86 | return; |
Elliott Hughes | e2e3bd1 | 2017-05-15 10:59:29 -0700 | [diff] [blame] | 87 | } |
Elliott Hughes | 820eced | 2021-08-20 18:00:50 -0700 | [diff] [blame] | 88 | ndo->ndo_ll_hdr_len += hdrlen; |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 89 | } |
| 90 | |
| 91 | /* |
| 92 | * Print AppleTalk LLAP packets. |
| 93 | */ |
| 94 | u_int |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 95 | llap_print(netdissect_options *ndo, |
Elliott Hughes | 820eced | 2021-08-20 18:00:50 -0700 | [diff] [blame] | 96 | const u_char *bp, u_int length) |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 97 | { |
Elliott Hughes | 820eced | 2021-08-20 18:00:50 -0700 | [diff] [blame] | 98 | const struct LAP *lp; |
| 99 | const struct atDDP *dp; |
| 100 | const struct atShortDDP *sdp; |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 101 | u_short snet; |
| 102 | u_int hdrlen; |
| 103 | |
Elliott Hughes | 820eced | 2021-08-20 18:00:50 -0700 | [diff] [blame] | 104 | ndo->ndo_protocol = "llap"; |
JP Abgrall | 53f17a9 | 2014-02-12 14:02:41 -0800 | [diff] [blame] | 105 | if (length < sizeof(*lp)) { |
Elliott Hughes | 820eced | 2021-08-20 18:00:50 -0700 | [diff] [blame] | 106 | ND_PRINT(" [|llap %u]", length); |
JP Abgrall | 53f17a9 | 2014-02-12 14:02:41 -0800 | [diff] [blame] | 107 | return (length); |
| 108 | } |
Elliott Hughes | 820eced | 2021-08-20 18:00:50 -0700 | [diff] [blame] | 109 | if (!ND_TTEST_LEN(bp, sizeof(*lp))) { |
| 110 | nd_print_trunc(ndo); |
Elliott Hughes | e2e3bd1 | 2017-05-15 10:59:29 -0700 | [diff] [blame] | 111 | return (0); /* cut short by the snapshot length */ |
| 112 | } |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 113 | lp = (const struct LAP *)bp; |
| 114 | bp += sizeof(*lp); |
| 115 | length -= sizeof(*lp); |
| 116 | hdrlen = sizeof(*lp); |
Elliott Hughes | 820eced | 2021-08-20 18:00:50 -0700 | [diff] [blame] | 117 | switch (GET_U_1(lp->type)) { |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 118 | |
| 119 | case lapShortDDP: |
| 120 | if (length < ddpSSize) { |
Elliott Hughes | 820eced | 2021-08-20 18:00:50 -0700 | [diff] [blame] | 121 | ND_PRINT(" [|sddp %u]", length); |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 122 | return (length); |
| 123 | } |
Elliott Hughes | 820eced | 2021-08-20 18:00:50 -0700 | [diff] [blame] | 124 | if (!ND_TTEST_LEN(bp, ddpSSize)) { |
| 125 | ND_PRINT(" [|sddp]"); |
Elliott Hughes | e2e3bd1 | 2017-05-15 10:59:29 -0700 | [diff] [blame] | 126 | return (0); /* cut short by the snapshot length */ |
| 127 | } |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 128 | sdp = (const struct atShortDDP *)bp; |
Elliott Hughes | 820eced | 2021-08-20 18:00:50 -0700 | [diff] [blame] | 129 | ND_PRINT("%s.%s", |
| 130 | ataddr_string(ndo, 0, GET_U_1(lp->src)), |
| 131 | ddpskt_string(ndo, GET_U_1(sdp->srcSkt))); |
| 132 | ND_PRINT(" > %s.%s:", |
| 133 | ataddr_string(ndo, 0, GET_U_1(lp->dst)), |
| 134 | ddpskt_string(ndo, GET_U_1(sdp->dstSkt))); |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 135 | bp += ddpSSize; |
| 136 | length -= ddpSSize; |
| 137 | hdrlen += ddpSSize; |
Elliott Hughes | 820eced | 2021-08-20 18:00:50 -0700 | [diff] [blame] | 138 | ddp_print(ndo, bp, length, GET_U_1(sdp->type), 0, |
| 139 | GET_U_1(lp->src), GET_U_1(sdp->srcSkt)); |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 140 | break; |
| 141 | |
| 142 | case lapDDP: |
| 143 | if (length < ddpSize) { |
Elliott Hughes | 820eced | 2021-08-20 18:00:50 -0700 | [diff] [blame] | 144 | ND_PRINT(" [|ddp %u]", length); |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 145 | return (length); |
| 146 | } |
Elliott Hughes | 820eced | 2021-08-20 18:00:50 -0700 | [diff] [blame] | 147 | if (!ND_TTEST_LEN(bp, ddpSize)) { |
| 148 | ND_PRINT(" [|ddp]"); |
Elliott Hughes | e2e3bd1 | 2017-05-15 10:59:29 -0700 | [diff] [blame] | 149 | return (0); /* cut short by the snapshot length */ |
| 150 | } |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 151 | dp = (const struct atDDP *)bp; |
Elliott Hughes | 820eced | 2021-08-20 18:00:50 -0700 | [diff] [blame] | 152 | snet = GET_BE_U_2(dp->srcNet); |
| 153 | ND_PRINT("%s.%s", |
| 154 | ataddr_string(ndo, snet, GET_U_1(dp->srcNode)), |
| 155 | ddpskt_string(ndo, GET_U_1(dp->srcSkt))); |
| 156 | ND_PRINT(" > %s.%s:", |
| 157 | ataddr_string(ndo, GET_BE_U_2(dp->dstNet), GET_U_1(dp->dstNode)), |
| 158 | ddpskt_string(ndo, GET_U_1(dp->dstSkt))); |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 159 | bp += ddpSize; |
| 160 | length -= ddpSize; |
| 161 | hdrlen += ddpSize; |
Elliott Hughes | 820eced | 2021-08-20 18:00:50 -0700 | [diff] [blame] | 162 | ddp_print(ndo, bp, length, GET_U_1(dp->type), snet, |
| 163 | GET_U_1(dp->srcNode), GET_U_1(dp->srcSkt)); |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 164 | break; |
| 165 | |
| 166 | #ifdef notdef |
| 167 | case lapKLAP: |
| 168 | klap_print(bp, length); |
| 169 | break; |
| 170 | #endif |
| 171 | |
| 172 | default: |
Elliott Hughes | 820eced | 2021-08-20 18:00:50 -0700 | [diff] [blame] | 173 | ND_PRINT("%u > %u at-lap#%u %u", |
| 174 | GET_U_1(lp->src), GET_U_1(lp->dst), GET_U_1(lp->type), |
| 175 | length); |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 176 | break; |
| 177 | } |
| 178 | return (hdrlen); |
| 179 | } |
| 180 | |
| 181 | /* |
| 182 | * Print EtherTalk/TokenTalk packets (or FDDITalk, or whatever it's called |
| 183 | * when it runs over FDDI; yes, I've seen FDDI captures with AppleTalk |
| 184 | * packets in them). |
| 185 | */ |
| 186 | void |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 187 | atalk_print(netdissect_options *ndo, |
Elliott Hughes | 820eced | 2021-08-20 18:00:50 -0700 | [diff] [blame] | 188 | const u_char *bp, u_int length) |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 189 | { |
Elliott Hughes | 820eced | 2021-08-20 18:00:50 -0700 | [diff] [blame] | 190 | const struct atDDP *dp; |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 191 | u_short snet; |
| 192 | |
Elliott Hughes | 820eced | 2021-08-20 18:00:50 -0700 | [diff] [blame] | 193 | ndo->ndo_protocol = "atalk"; |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 194 | if(!ndo->ndo_eflag) |
Elliott Hughes | 820eced | 2021-08-20 18:00:50 -0700 | [diff] [blame] | 195 | ND_PRINT("AT "); |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 196 | |
| 197 | if (length < ddpSize) { |
Elliott Hughes | 820eced | 2021-08-20 18:00:50 -0700 | [diff] [blame] | 198 | ND_PRINT(" [|ddp %u]", length); |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 199 | return; |
| 200 | } |
Elliott Hughes | 820eced | 2021-08-20 18:00:50 -0700 | [diff] [blame] | 201 | if (!ND_TTEST_LEN(bp, ddpSize)) { |
| 202 | ND_PRINT(" [|ddp]"); |
Elliott Hughes | e2e3bd1 | 2017-05-15 10:59:29 -0700 | [diff] [blame] | 203 | return; |
| 204 | } |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 205 | dp = (const struct atDDP *)bp; |
Elliott Hughes | 820eced | 2021-08-20 18:00:50 -0700 | [diff] [blame] | 206 | snet = GET_BE_U_2(dp->srcNet); |
| 207 | ND_PRINT("%s.%s", ataddr_string(ndo, snet, GET_U_1(dp->srcNode)), |
| 208 | ddpskt_string(ndo, GET_U_1(dp->srcSkt))); |
| 209 | ND_PRINT(" > %s.%s: ", |
| 210 | ataddr_string(ndo, GET_BE_U_2(dp->dstNet), GET_U_1(dp->dstNode)), |
| 211 | ddpskt_string(ndo, GET_U_1(dp->dstSkt))); |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 212 | bp += ddpSize; |
| 213 | length -= ddpSize; |
Elliott Hughes | 820eced | 2021-08-20 18:00:50 -0700 | [diff] [blame] | 214 | ddp_print(ndo, bp, length, GET_U_1(dp->type), snet, |
| 215 | GET_U_1(dp->srcNode), GET_U_1(dp->srcSkt)); |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 216 | } |
| 217 | |
| 218 | /* XXX should probably pass in the snap header and do checks like arp_print() */ |
| 219 | void |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 220 | aarp_print(netdissect_options *ndo, |
Elliott Hughes | 820eced | 2021-08-20 18:00:50 -0700 | [diff] [blame] | 221 | const u_char *bp, u_int length) |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 222 | { |
Elliott Hughes | 820eced | 2021-08-20 18:00:50 -0700 | [diff] [blame] | 223 | const struct aarp *ap; |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 224 | |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 225 | #define AT(member) ataddr_string(ndo, (ap->member[1]<<8)|ap->member[2],ap->member[3]) |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 226 | |
Elliott Hughes | 820eced | 2021-08-20 18:00:50 -0700 | [diff] [blame] | 227 | ndo->ndo_protocol = "aarp"; |
| 228 | ND_PRINT("aarp "); |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 229 | ap = (const struct aarp *)bp; |
Elliott Hughes | 820eced | 2021-08-20 18:00:50 -0700 | [diff] [blame] | 230 | if (!ND_TTEST_SIZE(ap)) { |
Elliott Hughes | e2e3bd1 | 2017-05-15 10:59:29 -0700 | [diff] [blame] | 231 | /* Just bail if we don't have the whole chunk. */ |
Elliott Hughes | 820eced | 2021-08-20 18:00:50 -0700 | [diff] [blame] | 232 | nd_print_trunc(ndo); |
Elliott Hughes | e2e3bd1 | 2017-05-15 10:59:29 -0700 | [diff] [blame] | 233 | return; |
| 234 | } |
| 235 | if (length < sizeof(*ap)) { |
Elliott Hughes | 820eced | 2021-08-20 18:00:50 -0700 | [diff] [blame] | 236 | ND_PRINT(" [|aarp %u]", length); |
Elliott Hughes | e2e3bd1 | 2017-05-15 10:59:29 -0700 | [diff] [blame] | 237 | return; |
| 238 | } |
Elliott Hughes | 820eced | 2021-08-20 18:00:50 -0700 | [diff] [blame] | 239 | if (GET_BE_U_2(ap->htype) == 1 && |
| 240 | GET_BE_U_2(ap->ptype) == ETHERTYPE_ATALK && |
| 241 | GET_U_1(ap->halen) == MAC_ADDR_LEN && GET_U_1(ap->palen) == 4) |
| 242 | switch (GET_BE_U_2(ap->op)) { |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 243 | |
| 244 | case 1: /* request */ |
Elliott Hughes | 820eced | 2021-08-20 18:00:50 -0700 | [diff] [blame] | 245 | ND_PRINT("who-has %s tell %s", AT(pdaddr), AT(psaddr)); |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 246 | return; |
| 247 | |
| 248 | case 2: /* response */ |
Elliott Hughes | 820eced | 2021-08-20 18:00:50 -0700 | [diff] [blame] | 249 | ND_PRINT("reply %s is-at %s", AT(psaddr), GET_ETHERADDR_STRING(ap->hsaddr)); |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 250 | return; |
| 251 | |
| 252 | case 3: /* probe (oy!) */ |
Elliott Hughes | 820eced | 2021-08-20 18:00:50 -0700 | [diff] [blame] | 253 | ND_PRINT("probe %s tell %s", AT(pdaddr), AT(psaddr)); |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 254 | return; |
| 255 | } |
Elliott Hughes | 820eced | 2021-08-20 18:00:50 -0700 | [diff] [blame] | 256 | ND_PRINT("len %u op %u htype %u ptype %#x halen %u palen %u", |
| 257 | length, GET_BE_U_2(ap->op), GET_BE_U_2(ap->htype), |
| 258 | GET_BE_U_2(ap->ptype), GET_U_1(ap->halen), GET_U_1(ap->palen)); |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 259 | } |
| 260 | |
| 261 | /* |
| 262 | * Print AppleTalk Datagram Delivery Protocol packets. |
| 263 | */ |
| 264 | static void |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 265 | ddp_print(netdissect_options *ndo, |
Elliott Hughes | 820eced | 2021-08-20 18:00:50 -0700 | [diff] [blame] | 266 | const u_char *bp, u_int length, u_int t, |
| 267 | u_short snet, u_char snode, u_char skt) |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 268 | { |
| 269 | |
| 270 | switch (t) { |
| 271 | |
| 272 | case ddpNBP: |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 273 | nbp_print(ndo, (const struct atNBP *)bp, length, snet, snode, skt); |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 274 | break; |
| 275 | |
| 276 | case ddpATP: |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 277 | atp_print(ndo, (const struct atATP *)bp, length); |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 278 | break; |
| 279 | |
| 280 | case ddpEIGRP: |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 281 | eigrp_print(ndo, bp, length); |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 282 | break; |
| 283 | |
| 284 | default: |
Elliott Hughes | 820eced | 2021-08-20 18:00:50 -0700 | [diff] [blame] | 285 | ND_PRINT(" at-%s %u", tok2str(type2str, NULL, t), length); |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 286 | break; |
| 287 | } |
| 288 | } |
| 289 | |
| 290 | static void |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 291 | atp_print(netdissect_options *ndo, |
Elliott Hughes | 820eced | 2021-08-20 18:00:50 -0700 | [diff] [blame] | 292 | const struct atATP *ap, u_int length) |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 293 | { |
Elliott Hughes | 820eced | 2021-08-20 18:00:50 -0700 | [diff] [blame] | 294 | uint8_t control; |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 295 | uint32_t data; |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 296 | |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 297 | if ((const u_char *)(ap + 1) > ndo->ndo_snapend) { |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 298 | /* Just bail if we don't have the whole chunk. */ |
Elliott Hughes | 820eced | 2021-08-20 18:00:50 -0700 | [diff] [blame] | 299 | nd_print_trunc(ndo); |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 300 | return; |
| 301 | } |
JP Abgrall | 53f17a9 | 2014-02-12 14:02:41 -0800 | [diff] [blame] | 302 | if (length < sizeof(*ap)) { |
Elliott Hughes | 820eced | 2021-08-20 18:00:50 -0700 | [diff] [blame] | 303 | ND_PRINT(" [|atp %u]", length); |
JP Abgrall | 53f17a9 | 2014-02-12 14:02:41 -0800 | [diff] [blame] | 304 | return; |
| 305 | } |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 306 | length -= sizeof(*ap); |
Elliott Hughes | 820eced | 2021-08-20 18:00:50 -0700 | [diff] [blame] | 307 | control = GET_U_1(ap->control); |
| 308 | switch (control & 0xc0) { |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 309 | |
| 310 | case atpReqCode: |
Elliott Hughes | 820eced | 2021-08-20 18:00:50 -0700 | [diff] [blame] | 311 | ND_PRINT(" atp-req%s %u", |
| 312 | control & atpXO? " " : "*", |
| 313 | GET_BE_U_2(ap->transID)); |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 314 | |
Elliott Hughes | 820eced | 2021-08-20 18:00:50 -0700 | [diff] [blame] | 315 | atp_bitmap_print(ndo, GET_U_1(ap->bitmap)); |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 316 | |
| 317 | if (length != 0) |
Elliott Hughes | 820eced | 2021-08-20 18:00:50 -0700 | [diff] [blame] | 318 | ND_PRINT(" [len=%u]", length); |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 319 | |
Elliott Hughes | 820eced | 2021-08-20 18:00:50 -0700 | [diff] [blame] | 320 | switch (control & (atpEOM|atpSTS)) { |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 321 | case atpEOM: |
Elliott Hughes | 820eced | 2021-08-20 18:00:50 -0700 | [diff] [blame] | 322 | ND_PRINT(" [EOM]"); |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 323 | break; |
| 324 | case atpSTS: |
Elliott Hughes | 820eced | 2021-08-20 18:00:50 -0700 | [diff] [blame] | 325 | ND_PRINT(" [STS]"); |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 326 | break; |
| 327 | case atpEOM|atpSTS: |
Elliott Hughes | 820eced | 2021-08-20 18:00:50 -0700 | [diff] [blame] | 328 | ND_PRINT(" [EOM,STS]"); |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 329 | break; |
| 330 | } |
| 331 | break; |
| 332 | |
| 333 | case atpRspCode: |
Elliott Hughes | 820eced | 2021-08-20 18:00:50 -0700 | [diff] [blame] | 334 | ND_PRINT(" atp-resp%s%u:%u (%u)", |
| 335 | control & atpEOM? "*" : " ", |
| 336 | GET_BE_U_2(ap->transID), GET_U_1(ap->bitmap), |
| 337 | length); |
| 338 | switch (control & (atpXO|atpSTS)) { |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 339 | case atpXO: |
Elliott Hughes | 820eced | 2021-08-20 18:00:50 -0700 | [diff] [blame] | 340 | ND_PRINT(" [XO]"); |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 341 | break; |
| 342 | case atpSTS: |
Elliott Hughes | 820eced | 2021-08-20 18:00:50 -0700 | [diff] [blame] | 343 | ND_PRINT(" [STS]"); |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 344 | break; |
| 345 | case atpXO|atpSTS: |
Elliott Hughes | 820eced | 2021-08-20 18:00:50 -0700 | [diff] [blame] | 346 | ND_PRINT(" [XO,STS]"); |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 347 | break; |
| 348 | } |
| 349 | break; |
| 350 | |
| 351 | case atpRelCode: |
Elliott Hughes | 820eced | 2021-08-20 18:00:50 -0700 | [diff] [blame] | 352 | ND_PRINT(" atp-rel %u", GET_BE_U_2(ap->transID)); |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 353 | |
Elliott Hughes | 820eced | 2021-08-20 18:00:50 -0700 | [diff] [blame] | 354 | atp_bitmap_print(ndo, GET_U_1(ap->bitmap)); |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 355 | |
| 356 | /* length should be zero */ |
| 357 | if (length) |
Elliott Hughes | 820eced | 2021-08-20 18:00:50 -0700 | [diff] [blame] | 358 | ND_PRINT(" [len=%u]", length); |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 359 | |
| 360 | /* there shouldn't be any control flags */ |
Elliott Hughes | 820eced | 2021-08-20 18:00:50 -0700 | [diff] [blame] | 361 | if (control & (atpXO|atpEOM|atpSTS)) { |
| 362 | char c = '['; |
| 363 | if (control & atpXO) { |
| 364 | ND_PRINT("%cXO", c); |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 365 | c = ','; |
| 366 | } |
Elliott Hughes | 820eced | 2021-08-20 18:00:50 -0700 | [diff] [blame] | 367 | if (control & atpEOM) { |
| 368 | ND_PRINT("%cEOM", c); |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 369 | c = ','; |
| 370 | } |
Elliott Hughes | 820eced | 2021-08-20 18:00:50 -0700 | [diff] [blame] | 371 | if (control & atpSTS) { |
| 372 | ND_PRINT("%cSTS", c); |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 373 | } |
Elliott Hughes | 820eced | 2021-08-20 18:00:50 -0700 | [diff] [blame] | 374 | ND_PRINT("]"); |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 375 | } |
| 376 | break; |
| 377 | |
| 378 | default: |
Elliott Hughes | 820eced | 2021-08-20 18:00:50 -0700 | [diff] [blame] | 379 | ND_PRINT(" atp-0x%x %u (%u)", control, |
| 380 | GET_BE_U_2(ap->transID), length); |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 381 | break; |
| 382 | } |
Elliott Hughes | 820eced | 2021-08-20 18:00:50 -0700 | [diff] [blame] | 383 | data = GET_BE_U_4(ap->userData); |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 384 | if (data != 0) |
Elliott Hughes | 820eced | 2021-08-20 18:00:50 -0700 | [diff] [blame] | 385 | ND_PRINT(" 0x%x", data); |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 386 | } |
| 387 | |
| 388 | static void |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 389 | atp_bitmap_print(netdissect_options *ndo, |
Elliott Hughes | 820eced | 2021-08-20 18:00:50 -0700 | [diff] [blame] | 390 | u_char bm) |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 391 | { |
Elliott Hughes | 820eced | 2021-08-20 18:00:50 -0700 | [diff] [blame] | 392 | u_int i; |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 393 | |
| 394 | /* |
| 395 | * The '& 0xff' below is needed for compilers that want to sign |
| 396 | * extend a u_char, which is the case with the Ultrix compiler. |
| 397 | * (gcc is smart enough to eliminate it, at least on the Sparc). |
| 398 | */ |
| 399 | if ((bm + 1) & (bm & 0xff)) { |
Elliott Hughes | 820eced | 2021-08-20 18:00:50 -0700 | [diff] [blame] | 400 | char c = '<'; |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 401 | for (i = 0; bm; ++i) { |
| 402 | if (bm & 1) { |
Elliott Hughes | 820eced | 2021-08-20 18:00:50 -0700 | [diff] [blame] | 403 | ND_PRINT("%c%u", c, i); |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 404 | c = ','; |
| 405 | } |
| 406 | bm >>= 1; |
| 407 | } |
Elliott Hughes | 820eced | 2021-08-20 18:00:50 -0700 | [diff] [blame] | 408 | ND_PRINT(">"); |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 409 | } else { |
| 410 | for (i = 0; bm; ++i) |
| 411 | bm >>= 1; |
| 412 | if (i > 1) |
Elliott Hughes | 820eced | 2021-08-20 18:00:50 -0700 | [diff] [blame] | 413 | ND_PRINT("<0-%u>", i - 1); |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 414 | else |
Elliott Hughes | 820eced | 2021-08-20 18:00:50 -0700 | [diff] [blame] | 415 | ND_PRINT("<0>"); |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 416 | } |
| 417 | } |
| 418 | |
| 419 | static void |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 420 | nbp_print(netdissect_options *ndo, |
Elliott Hughes | 820eced | 2021-08-20 18:00:50 -0700 | [diff] [blame] | 421 | const struct atNBP *np, u_int length, u_short snet, |
| 422 | u_char snode, u_char skt) |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 423 | { |
Elliott Hughes | 820eced | 2021-08-20 18:00:50 -0700 | [diff] [blame] | 424 | const struct atNBPtuple *tp = |
Elliott Hughes | e2e3bd1 | 2017-05-15 10:59:29 -0700 | [diff] [blame] | 425 | (const struct atNBPtuple *)((const u_char *)np + nbpHeaderSize); |
Elliott Hughes | 820eced | 2021-08-20 18:00:50 -0700 | [diff] [blame] | 426 | uint8_t control; |
| 427 | u_int i; |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 428 | const u_char *ep; |
| 429 | |
| 430 | if (length < nbpHeaderSize) { |
Elliott Hughes | 820eced | 2021-08-20 18:00:50 -0700 | [diff] [blame] | 431 | ND_PRINT(" truncated-nbp %u", length); |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 432 | return; |
| 433 | } |
| 434 | |
| 435 | length -= nbpHeaderSize; |
| 436 | if (length < 8) { |
| 437 | /* must be room for at least one tuple */ |
Elliott Hughes | 820eced | 2021-08-20 18:00:50 -0700 | [diff] [blame] | 438 | ND_PRINT(" truncated-nbp %u", length + nbpHeaderSize); |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 439 | return; |
| 440 | } |
| 441 | /* ep points to end of available data */ |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 442 | ep = ndo->ndo_snapend; |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 443 | if ((const u_char *)tp > ep) { |
Elliott Hughes | 820eced | 2021-08-20 18:00:50 -0700 | [diff] [blame] | 444 | nd_print_trunc(ndo); |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 445 | return; |
| 446 | } |
Elliott Hughes | 820eced | 2021-08-20 18:00:50 -0700 | [diff] [blame] | 447 | control = GET_U_1(np->control); |
| 448 | switch (i = (control & 0xf0)) { |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 449 | |
| 450 | case nbpBrRq: |
| 451 | case nbpLkUp: |
Elliott Hughes | 820eced | 2021-08-20 18:00:50 -0700 | [diff] [blame] | 452 | ND_PRINT(i == nbpLkUp? " nbp-lkup %u:":" nbp-brRq %u:", |
| 453 | GET_U_1(np->id)); |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 454 | if ((const u_char *)(tp + 1) > ep) { |
Elliott Hughes | 820eced | 2021-08-20 18:00:50 -0700 | [diff] [blame] | 455 | nd_print_trunc(ndo); |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 456 | return; |
| 457 | } |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 458 | (void)nbp_name_print(ndo, tp, ep); |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 459 | /* |
| 460 | * look for anomalies: the spec says there can only |
| 461 | * be one tuple, the address must match the source |
| 462 | * address and the enumerator should be zero. |
| 463 | */ |
Elliott Hughes | 820eced | 2021-08-20 18:00:50 -0700 | [diff] [blame] | 464 | if ((control & 0xf) != 1) |
| 465 | ND_PRINT(" [ntup=%u]", control & 0xf); |
| 466 | if (GET_U_1(tp->enumerator)) |
| 467 | ND_PRINT(" [enum=%u]", GET_U_1(tp->enumerator)); |
| 468 | if (GET_BE_U_2(tp->net) != snet || |
| 469 | GET_U_1(tp->node) != snode || |
| 470 | GET_U_1(tp->skt) != skt) |
| 471 | ND_PRINT(" [addr=%s.%u]", |
| 472 | ataddr_string(ndo, GET_BE_U_2(tp->net), |
| 473 | GET_U_1(tp->node)), |
| 474 | GET_U_1(tp->skt)); |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 475 | break; |
| 476 | |
| 477 | case nbpLkUpReply: |
Elliott Hughes | 820eced | 2021-08-20 18:00:50 -0700 | [diff] [blame] | 478 | ND_PRINT(" nbp-reply %u:", GET_U_1(np->id)); |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 479 | |
| 480 | /* print each of the tuples in the reply */ |
Elliott Hughes | 820eced | 2021-08-20 18:00:50 -0700 | [diff] [blame] | 481 | for (i = control & 0xf; i != 0 && tp; i--) |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 482 | tp = nbp_tuple_print(ndo, tp, ep, snet, snode, skt); |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 483 | break; |
| 484 | |
| 485 | default: |
Elliott Hughes | 820eced | 2021-08-20 18:00:50 -0700 | [diff] [blame] | 486 | ND_PRINT(" nbp-0x%x %u (%u)", control, GET_U_1(np->id), |
| 487 | length); |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 488 | break; |
| 489 | } |
| 490 | } |
| 491 | |
| 492 | /* print a counted string */ |
Elliott Hughes | 820eced | 2021-08-20 18:00:50 -0700 | [diff] [blame] | 493 | static const u_char * |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 494 | print_cstring(netdissect_options *ndo, |
Elliott Hughes | 820eced | 2021-08-20 18:00:50 -0700 | [diff] [blame] | 495 | const u_char *cp, const u_char *ep) |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 496 | { |
Elliott Hughes | 820eced | 2021-08-20 18:00:50 -0700 | [diff] [blame] | 497 | u_int length; |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 498 | |
Elliott Hughes | 820eced | 2021-08-20 18:00:50 -0700 | [diff] [blame] | 499 | if (cp >= ep) { |
| 500 | nd_print_trunc(ndo); |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 501 | return (0); |
| 502 | } |
Elliott Hughes | 820eced | 2021-08-20 18:00:50 -0700 | [diff] [blame] | 503 | length = GET_U_1(cp); |
| 504 | cp++; |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 505 | |
| 506 | /* Spec says string can be at most 32 bytes long */ |
| 507 | if (length > 32) { |
Elliott Hughes | 820eced | 2021-08-20 18:00:50 -0700 | [diff] [blame] | 508 | ND_PRINT("[len=%u]", length); |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 509 | return (0); |
| 510 | } |
Elliott Hughes | 820eced | 2021-08-20 18:00:50 -0700 | [diff] [blame] | 511 | while (length != 0) { |
| 512 | if (cp >= ep) { |
| 513 | nd_print_trunc(ndo); |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 514 | return (0); |
| 515 | } |
Elliott Hughes | 820eced | 2021-08-20 18:00:50 -0700 | [diff] [blame] | 516 | fn_print_char(ndo, GET_U_1(cp)); |
| 517 | cp++; |
| 518 | length--; |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 519 | } |
| 520 | return (cp); |
| 521 | } |
| 522 | |
| 523 | static const struct atNBPtuple * |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 524 | nbp_tuple_print(netdissect_options *ndo, |
Elliott Hughes | 820eced | 2021-08-20 18:00:50 -0700 | [diff] [blame] | 525 | const struct atNBPtuple *tp, const u_char *ep, |
| 526 | u_short snet, u_char snode, u_char skt) |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 527 | { |
Elliott Hughes | 820eced | 2021-08-20 18:00:50 -0700 | [diff] [blame] | 528 | const struct atNBPtuple *tpn; |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 529 | |
| 530 | if ((const u_char *)(tp + 1) > ep) { |
Elliott Hughes | 820eced | 2021-08-20 18:00:50 -0700 | [diff] [blame] | 531 | nd_print_trunc(ndo); |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 532 | return 0; |
| 533 | } |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 534 | tpn = nbp_name_print(ndo, tp, ep); |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 535 | |
| 536 | /* if the enumerator isn't 1, print it */ |
Elliott Hughes | 820eced | 2021-08-20 18:00:50 -0700 | [diff] [blame] | 537 | if (GET_U_1(tp->enumerator) != 1) |
| 538 | ND_PRINT("(%u)", GET_U_1(tp->enumerator)); |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 539 | |
| 540 | /* if the socket doesn't match the src socket, print it */ |
Elliott Hughes | 820eced | 2021-08-20 18:00:50 -0700 | [diff] [blame] | 541 | if (GET_U_1(tp->skt) != skt) |
| 542 | ND_PRINT(" %u", GET_U_1(tp->skt)); |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 543 | |
| 544 | /* if the address doesn't match the src address, it's an anomaly */ |
Elliott Hughes | 820eced | 2021-08-20 18:00:50 -0700 | [diff] [blame] | 545 | if (GET_BE_U_2(tp->net) != snet || |
| 546 | GET_U_1(tp->node) != snode) |
| 547 | ND_PRINT(" [addr=%s]", |
| 548 | ataddr_string(ndo, GET_BE_U_2(tp->net), GET_U_1(tp->node))); |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 549 | |
| 550 | return (tpn); |
| 551 | } |
| 552 | |
| 553 | static const struct atNBPtuple * |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 554 | nbp_name_print(netdissect_options *ndo, |
Elliott Hughes | 820eced | 2021-08-20 18:00:50 -0700 | [diff] [blame] | 555 | const struct atNBPtuple *tp, const u_char *ep) |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 556 | { |
Elliott Hughes | 820eced | 2021-08-20 18:00:50 -0700 | [diff] [blame] | 557 | const u_char *cp = (const u_char *)tp + nbpTupleSize; |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 558 | |
Elliott Hughes | 820eced | 2021-08-20 18:00:50 -0700 | [diff] [blame] | 559 | ND_PRINT(" "); |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 560 | |
| 561 | /* Object */ |
Elliott Hughes | 820eced | 2021-08-20 18:00:50 -0700 | [diff] [blame] | 562 | ND_PRINT("\""); |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 563 | if ((cp = print_cstring(ndo, cp, ep)) != NULL) { |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 564 | /* Type */ |
Elliott Hughes | 820eced | 2021-08-20 18:00:50 -0700 | [diff] [blame] | 565 | ND_PRINT(":"); |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 566 | if ((cp = print_cstring(ndo, cp, ep)) != NULL) { |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 567 | /* Zone */ |
Elliott Hughes | 820eced | 2021-08-20 18:00:50 -0700 | [diff] [blame] | 568 | ND_PRINT("@"); |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 569 | if ((cp = print_cstring(ndo, cp, ep)) != NULL) |
Elliott Hughes | 820eced | 2021-08-20 18:00:50 -0700 | [diff] [blame] | 570 | ND_PRINT("\""); |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 571 | } |
| 572 | } |
| 573 | return ((const struct atNBPtuple *)cp); |
| 574 | } |
| 575 | |
| 576 | |
| 577 | #define HASHNAMESIZE 4096 |
| 578 | |
| 579 | struct hnamemem { |
Elliott Hughes | 820eced | 2021-08-20 18:00:50 -0700 | [diff] [blame] | 580 | u_int addr; |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 581 | char *name; |
| 582 | struct hnamemem *nxt; |
| 583 | }; |
| 584 | |
| 585 | static struct hnamemem hnametable[HASHNAMESIZE]; |
| 586 | |
| 587 | static const char * |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 588 | ataddr_string(netdissect_options *ndo, |
| 589 | u_short atnet, u_char athost) |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 590 | { |
Elliott Hughes | 820eced | 2021-08-20 18:00:50 -0700 | [diff] [blame] | 591 | struct hnamemem *tp, *tp2; |
| 592 | u_int i = (atnet << 8) | athost; |
JP Abgrall | 53f17a9 | 2014-02-12 14:02:41 -0800 | [diff] [blame] | 593 | char nambuf[256+1]; |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 594 | static int first = 1; |
| 595 | FILE *fp; |
| 596 | |
| 597 | /* |
Elliott Hughes | 820eced | 2021-08-20 18:00:50 -0700 | [diff] [blame] | 598 | * Are we doing address to name resolution? |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 599 | */ |
Elliott Hughes | 820eced | 2021-08-20 18:00:50 -0700 | [diff] [blame] | 600 | if (!ndo->ndo_nflag) { |
| 601 | /* |
| 602 | * Yes. Have we tried to open and read an AppleTalk |
| 603 | * number to name map file? |
| 604 | */ |
| 605 | if (!first) { |
| 606 | /* |
| 607 | * No; try to do so. |
| 608 | */ |
| 609 | first = 0; |
| 610 | fp = fopen("/etc/atalk.names", "r"); |
| 611 | if (fp != NULL) { |
| 612 | char line[256]; |
| 613 | u_int i1, i2; |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 614 | |
Elliott Hughes | 820eced | 2021-08-20 18:00:50 -0700 | [diff] [blame] | 615 | while (fgets(line, sizeof(line), fp)) { |
| 616 | if (line[0] == '\n' || line[0] == 0 || |
| 617 | line[0] == '#') |
| 618 | continue; |
| 619 | if (sscanf(line, "%u.%u %256s", &i1, |
| 620 | &i2, nambuf) == 3) |
| 621 | /* got a hostname. */ |
| 622 | i2 |= (i1 << 8); |
| 623 | else if (sscanf(line, "%u %256s", &i1, |
| 624 | nambuf) == 2) |
| 625 | /* got a net name */ |
| 626 | i2 = (i1 << 8) | 255; |
| 627 | else |
| 628 | continue; |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 629 | |
Elliott Hughes | 820eced | 2021-08-20 18:00:50 -0700 | [diff] [blame] | 630 | for (tp = &hnametable[i2 & (HASHNAMESIZE-1)]; |
| 631 | tp->nxt; tp = tp->nxt) |
| 632 | ; |
| 633 | tp->addr = i2; |
| 634 | tp->nxt = newhnamemem(ndo); |
| 635 | tp->name = strdup(nambuf); |
| 636 | if (tp->name == NULL) |
| 637 | (*ndo->ndo_error)(ndo, |
| 638 | S_ERR_ND_MEM_ALLOC, |
| 639 | "%s: strdup(nambuf)", __func__); |
| 640 | } |
| 641 | fclose(fp); |
| 642 | } |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 643 | } |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 644 | } |
| 645 | |
Elliott Hughes | 820eced | 2021-08-20 18:00:50 -0700 | [diff] [blame] | 646 | /* |
| 647 | * Now try to look up the address in the table. |
| 648 | */ |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 649 | for (tp = &hnametable[i & (HASHNAMESIZE-1)]; tp->nxt; tp = tp->nxt) |
| 650 | if (tp->addr == i) |
| 651 | return (tp->name); |
| 652 | |
| 653 | /* didn't have the node name -- see if we've got the net name */ |
| 654 | i |= 255; |
| 655 | for (tp2 = &hnametable[i & (HASHNAMESIZE-1)]; tp2->nxt; tp2 = tp2->nxt) |
| 656 | if (tp2->addr == i) { |
| 657 | tp->addr = (atnet << 8) | athost; |
Elliott Hughes | e2e3bd1 | 2017-05-15 10:59:29 -0700 | [diff] [blame] | 658 | tp->nxt = newhnamemem(ndo); |
Elliott Hughes | 820eced | 2021-08-20 18:00:50 -0700 | [diff] [blame] | 659 | (void)snprintf(nambuf, sizeof(nambuf), "%s.%u", |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 660 | tp2->name, athost); |
| 661 | tp->name = strdup(nambuf); |
Elliott Hughes | e2e3bd1 | 2017-05-15 10:59:29 -0700 | [diff] [blame] | 662 | if (tp->name == NULL) |
Elliott Hughes | 820eced | 2021-08-20 18:00:50 -0700 | [diff] [blame] | 663 | (*ndo->ndo_error)(ndo, S_ERR_ND_MEM_ALLOC, |
| 664 | "%s: strdup(nambuf)", __func__); |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 665 | return (tp->name); |
| 666 | } |
| 667 | |
| 668 | tp->addr = (atnet << 8) | athost; |
Elliott Hughes | e2e3bd1 | 2017-05-15 10:59:29 -0700 | [diff] [blame] | 669 | tp->nxt = newhnamemem(ndo); |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 670 | if (athost != 255) |
Elliott Hughes | 820eced | 2021-08-20 18:00:50 -0700 | [diff] [blame] | 671 | (void)snprintf(nambuf, sizeof(nambuf), "%u.%u", atnet, athost); |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 672 | else |
Elliott Hughes | 820eced | 2021-08-20 18:00:50 -0700 | [diff] [blame] | 673 | (void)snprintf(nambuf, sizeof(nambuf), "%u", atnet); |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 674 | tp->name = strdup(nambuf); |
Elliott Hughes | e2e3bd1 | 2017-05-15 10:59:29 -0700 | [diff] [blame] | 675 | if (tp->name == NULL) |
Elliott Hughes | 820eced | 2021-08-20 18:00:50 -0700 | [diff] [blame] | 676 | (*ndo->ndo_error)(ndo, S_ERR_ND_MEM_ALLOC, |
| 677 | "%s: strdup(nambuf)", __func__); |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 678 | |
| 679 | return (tp->name); |
| 680 | } |
| 681 | |
JP Abgrall | 53f17a9 | 2014-02-12 14:02:41 -0800 | [diff] [blame] | 682 | static const struct tok skt2str[] = { |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 683 | { rtmpSkt, "rtmp" }, /* routing table maintenance */ |
| 684 | { nbpSkt, "nis" }, /* name info socket */ |
| 685 | { echoSkt, "echo" }, /* AppleTalk echo protocol */ |
| 686 | { zipSkt, "zip" }, /* zone info protocol */ |
| 687 | { 0, NULL } |
| 688 | }; |
| 689 | |
| 690 | static const char * |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 691 | ddpskt_string(netdissect_options *ndo, |
Elliott Hughes | 820eced | 2021-08-20 18:00:50 -0700 | [diff] [blame] | 692 | u_int skt) |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 693 | { |
| 694 | static char buf[8]; |
| 695 | |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 696 | if (ndo->ndo_nflag) { |
Elliott Hughes | 820eced | 2021-08-20 18:00:50 -0700 | [diff] [blame] | 697 | (void)snprintf(buf, sizeof(buf), "%u", skt); |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 698 | return (buf); |
| 699 | } |
Elliott Hughes | 820eced | 2021-08-20 18:00:50 -0700 | [diff] [blame] | 700 | return (tok2str(skt2str, "%u", skt)); |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 701 | } |