14edb46e9SPaul Traina /* 2699fc314SBill Fenner * Copyright (c) 1988, 1989, 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1997 34edb46e9SPaul Traina * The Regents of the University of California. All rights reserved. 44edb46e9SPaul Traina * 54edb46e9SPaul Traina * Redistribution and use in source and binary forms, with or without 64edb46e9SPaul Traina * modification, are permitted provided that: (1) source code distributions 74edb46e9SPaul Traina * retain the above copyright notice and this paragraph in its entirety, (2) 84edb46e9SPaul Traina * distributions including binary code include the above copyright notice and 94edb46e9SPaul Traina * this paragraph in its entirety in the documentation or other materials 104edb46e9SPaul Traina * provided with the distribution, and (3) all advertising materials mentioning 114edb46e9SPaul Traina * features or use of this software display the following acknowledgement: 124edb46e9SPaul Traina * ``This product includes software developed by the University of California, 134edb46e9SPaul Traina * Lawrence Berkeley Laboratory and its contributors.'' Neither the name of 144edb46e9SPaul Traina * the University nor the names of its contributors may be used to endorse 154edb46e9SPaul Traina * or promote products derived from this software without specific prior 164edb46e9SPaul Traina * written permission. 174edb46e9SPaul Traina * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED 184edb46e9SPaul Traina * WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF 194edb46e9SPaul Traina * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. 20a88113a8SBill Fenner * 21a88113a8SBill Fenner * $FreeBSD$ 224edb46e9SPaul Traina */ 234edb46e9SPaul Traina 244edb46e9SPaul Traina #ifndef lint 25cc391cceSBruce M Simpson static const char rcsid[] _U_ = 26a5779b6eSRui Paulo "@(#) $Header: /tcpdump/master/tcpdump/print-arp.c,v 1.66 2006-03-03 22:53:21 hannes Exp $ (LBL)"; 27a88113a8SBill Fenner #endif 28a88113a8SBill Fenner 29a88113a8SBill Fenner #ifdef HAVE_CONFIG_H 30a88113a8SBill Fenner #include "config.h" 314edb46e9SPaul Traina #endif 324edb46e9SPaul Traina 33cc391cceSBruce M Simpson #include <tcpdump-stdinc.h> 344edb46e9SPaul Traina 354edb46e9SPaul Traina #include <stdio.h> 364edb46e9SPaul Traina #include <string.h> 374edb46e9SPaul Traina 38c1ad1296SSam Leffler #include "netdissect.h" 394edb46e9SPaul Traina #include "addrtoname.h" 40943ee2b1SBill Fenner #include "ether.h" 414edb46e9SPaul Traina #include "ethertype.h" 424edb46e9SPaul Traina #include "extract.h" /* must come after interface.h */ 434edb46e9SPaul Traina 44943ee2b1SBill Fenner /* 45943ee2b1SBill Fenner * Address Resolution Protocol. 46943ee2b1SBill Fenner * 47943ee2b1SBill Fenner * See RFC 826 for protocol description. ARP packets are variable 48943ee2b1SBill Fenner * in size; the arphdr structure defines the fixed-length portion. 49943ee2b1SBill Fenner * Protocol type values are the same as those for 10 Mb/s Ethernet. 50943ee2b1SBill Fenner * It is followed by the variable-sized fields ar_sha, arp_spa, 51943ee2b1SBill Fenner * arp_tha and arp_tpa in that order, according to the lengths 52943ee2b1SBill Fenner * specified. Field names used correspond to RFC 826. 53943ee2b1SBill Fenner */ 540e0def19SBill Fenner struct arp_pkthdr { 55943ee2b1SBill Fenner u_short ar_hrd; /* format of hardware address */ 56943ee2b1SBill Fenner #define ARPHRD_ETHER 1 /* ethernet hardware format */ 57943ee2b1SBill Fenner #define ARPHRD_IEEE802 6 /* token-ring hardware format */ 58a1c2090eSBill Fenner #define ARPHRD_ARCNET 7 /* arcnet hardware format */ 59943ee2b1SBill Fenner #define ARPHRD_FRELAY 15 /* frame relay hardware format */ 60a5779b6eSRui Paulo #define ARPHRD_ATM2225 19 /* ATM (RFC 2225) */ 61a1c2090eSBill Fenner #define ARPHRD_STRIP 23 /* Ricochet Starmode Radio hardware format */ 62a1c2090eSBill Fenner #define ARPHRD_IEEE1394 24 /* IEEE 1394 (FireWire) hardware format */ 63943ee2b1SBill Fenner u_short ar_pro; /* format of protocol address */ 64943ee2b1SBill Fenner u_char ar_hln; /* length of hardware address */ 65943ee2b1SBill Fenner u_char ar_pln; /* length of protocol address */ 66943ee2b1SBill Fenner u_short ar_op; /* one of: */ 67943ee2b1SBill Fenner #define ARPOP_REQUEST 1 /* request to resolve address */ 68943ee2b1SBill Fenner #define ARPOP_REPLY 2 /* response to previous request */ 69943ee2b1SBill Fenner #define ARPOP_REVREQUEST 3 /* request protocol address given hardware */ 70943ee2b1SBill Fenner #define ARPOP_REVREPLY 4 /* response giving protocol address */ 71943ee2b1SBill Fenner #define ARPOP_INVREQUEST 8 /* request to identify peer */ 72943ee2b1SBill Fenner #define ARPOP_INVREPLY 9 /* response identifying peer */ 73a5779b6eSRui Paulo #define ARPOP_NAK 10 /* NAK - only valif for ATM ARP */ 74a5779b6eSRui Paulo 75943ee2b1SBill Fenner /* 76943ee2b1SBill Fenner * The remaining fields are variable in size, 77943ee2b1SBill Fenner * according to the sizes above. 78943ee2b1SBill Fenner */ 79943ee2b1SBill Fenner #ifdef COMMENT_ONLY 80943ee2b1SBill Fenner u_char ar_sha[]; /* sender hardware address */ 81943ee2b1SBill Fenner u_char ar_spa[]; /* sender protocol address */ 82943ee2b1SBill Fenner u_char ar_tha[]; /* target hardware address */ 83943ee2b1SBill Fenner u_char ar_tpa[]; /* target protocol address */ 84943ee2b1SBill Fenner #endif 850e0def19SBill Fenner #define ar_sha(ap) (((const u_char *)((ap)+1))+0) 860e0def19SBill Fenner #define ar_spa(ap) (((const u_char *)((ap)+1))+ (ap)->ar_hln) 870e0def19SBill Fenner #define ar_tha(ap) (((const u_char *)((ap)+1))+ (ap)->ar_hln+(ap)->ar_pln) 880e0def19SBill Fenner #define ar_tpa(ap) (((const u_char *)((ap)+1))+2*(ap)->ar_hln+(ap)->ar_pln) 89943ee2b1SBill Fenner }; 90943ee2b1SBill Fenner 91943ee2b1SBill Fenner #define ARP_HDRLEN 8 92943ee2b1SBill Fenner 93cc391cceSBruce M Simpson #define HRD(ap) EXTRACT_16BITS(&(ap)->ar_hrd) 94a5779b6eSRui Paulo #define HRD_LEN(ap) ((ap)->ar_hln) 95a5779b6eSRui Paulo #define PROTO_LEN(ap) ((ap)->ar_pln) 96cc391cceSBruce M Simpson #define OP(ap) EXTRACT_16BITS(&(ap)->ar_op) 97cc391cceSBruce M Simpson #define PRO(ap) EXTRACT_16BITS(&(ap)->ar_pro) 98a1c2090eSBill Fenner #define SHA(ap) (ar_sha(ap)) 99a1c2090eSBill Fenner #define SPA(ap) (ar_spa(ap)) 100a1c2090eSBill Fenner #define THA(ap) (ar_tha(ap)) 101a1c2090eSBill Fenner #define TPA(ap) (ar_tpa(ap)) 1024edb46e9SPaul Traina 103a5779b6eSRui Paulo 104a5779b6eSRui Paulo struct tok arpop_values[] = { 105a5779b6eSRui Paulo { ARPOP_REQUEST, "Request" }, 106a5779b6eSRui Paulo { ARPOP_REPLY, "Reply" }, 107a5779b6eSRui Paulo { ARPOP_REVREQUEST, "Reverse Request" }, 108a5779b6eSRui Paulo { ARPOP_REVREPLY, "Reverse Reply" }, 109a5779b6eSRui Paulo { ARPOP_INVREQUEST, "Inverse Request" }, 110a5779b6eSRui Paulo { ARPOP_INVREPLY, "Inverse Reply" }, 111a5779b6eSRui Paulo { ARPOP_NAK, "NACK Reply" }, 112a5779b6eSRui Paulo { 0, NULL } 113a5779b6eSRui Paulo }; 114a5779b6eSRui Paulo 115a5779b6eSRui Paulo struct tok arphrd_values[] = { 116a5779b6eSRui Paulo { ARPHRD_ETHER, "Ethernet" }, 117a5779b6eSRui Paulo { ARPHRD_IEEE802, "TokenRing" }, 118a5779b6eSRui Paulo { ARPHRD_ARCNET, "ArcNet" }, 119a5779b6eSRui Paulo { ARPHRD_FRELAY, "FrameRelay" }, 120a5779b6eSRui Paulo { ARPHRD_STRIP, "Strip" }, 121a5779b6eSRui Paulo { ARPHRD_IEEE1394, "IEEE 1394" }, 122a5779b6eSRui Paulo { ARPHRD_ATM2225, "ATM" }, 123a5779b6eSRui Paulo { 0, NULL } 124a5779b6eSRui Paulo }; 125a5779b6eSRui Paulo 126cc391cceSBruce M Simpson /* 127cc391cceSBruce M Simpson * ATM Address Resolution Protocol. 128cc391cceSBruce M Simpson * 129cc391cceSBruce M Simpson * See RFC 2225 for protocol description. ATMARP packets are similar 130cc391cceSBruce M Simpson * to ARP packets, except that there are no length fields for the 131cc391cceSBruce M Simpson * protocol address - instead, there are type/length fields for 132cc391cceSBruce M Simpson * the ATM number and subaddress - and the hardware addresses consist 133cc391cceSBruce M Simpson * of an ATM number and an ATM subaddress. 134cc391cceSBruce M Simpson */ 135cc391cceSBruce M Simpson struct atmarp_pkthdr { 136cc391cceSBruce M Simpson u_short aar_hrd; /* format of hardware address */ 137cc391cceSBruce M Simpson u_short aar_pro; /* format of protocol address */ 138cc391cceSBruce M Simpson u_char aar_shtl; /* length of source ATM number */ 139cc391cceSBruce M Simpson u_char aar_sstl; /* length of source ATM subaddress */ 140cc391cceSBruce M Simpson #define ATMARP_IS_E164 0x40 /* bit in type/length for E.164 format */ 141cc391cceSBruce M Simpson #define ATMARP_LEN_MASK 0x3F /* length of {sub}address in type/length */ 142cc391cceSBruce M Simpson u_short aar_op; /* same as regular ARP */ 143cc391cceSBruce M Simpson u_char aar_spln; /* length of source protocol address */ 144cc391cceSBruce M Simpson u_char aar_thtl; /* length of target ATM number */ 145cc391cceSBruce M Simpson u_char aar_tstl; /* length of target ATM subaddress */ 146cc391cceSBruce M Simpson u_char aar_tpln; /* length of target protocol address */ 147cc391cceSBruce M Simpson /* 148cc391cceSBruce M Simpson * The remaining fields are variable in size, 149cc391cceSBruce M Simpson * according to the sizes above. 150cc391cceSBruce M Simpson */ 151cc391cceSBruce M Simpson #ifdef COMMENT_ONLY 152cc391cceSBruce M Simpson u_char aar_sha[]; /* source ATM number */ 153cc391cceSBruce M Simpson u_char aar_ssa[]; /* source ATM subaddress */ 154cc391cceSBruce M Simpson u_char aar_spa[]; /* sender protocol address */ 155cc391cceSBruce M Simpson u_char aar_tha[]; /* target ATM number */ 156cc391cceSBruce M Simpson u_char aar_tsa[]; /* target ATM subaddress */ 157cc391cceSBruce M Simpson u_char aar_tpa[]; /* target protocol address */ 158cc391cceSBruce M Simpson #endif 159cc391cceSBruce M Simpson 160cc391cceSBruce M Simpson #define ATMHRD(ap) EXTRACT_16BITS(&(ap)->aar_hrd) 161a5779b6eSRui Paulo #define ATMSHRD_LEN(ap) ((ap)->aar_shtl & ATMARP_LEN_MASK) 162cc391cceSBruce M Simpson #define ATMSSLN(ap) ((ap)->aar_sstl & ATMARP_LEN_MASK) 163a5779b6eSRui Paulo #define ATMSPROTO_LEN(ap) ((ap)->aar_spln) 164cc391cceSBruce M Simpson #define ATMOP(ap) EXTRACT_16BITS(&(ap)->aar_op) 165cc391cceSBruce M Simpson #define ATMPRO(ap) EXTRACT_16BITS(&(ap)->aar_pro) 166a5779b6eSRui Paulo #define ATMTHRD_LEN(ap) ((ap)->aar_thtl & ATMARP_LEN_MASK) 167cc391cceSBruce M Simpson #define ATMTSLN(ap) ((ap)->aar_tstl & ATMARP_LEN_MASK) 168a5779b6eSRui Paulo #define ATMTPROTO_LEN(ap) ((ap)->aar_tpln) 169cc391cceSBruce M Simpson #define aar_sha(ap) ((const u_char *)((ap)+1)) 170a5779b6eSRui Paulo #define aar_ssa(ap) (aar_sha(ap) + ATMSHRD_LEN(ap)) 171cc391cceSBruce M Simpson #define aar_spa(ap) (aar_ssa(ap) + ATMSSLN(ap)) 172a5779b6eSRui Paulo #define aar_tha(ap) (aar_spa(ap) + ATMSPROTO_LEN(ap)) 173a5779b6eSRui Paulo #define aar_tsa(ap) (aar_tha(ap) + ATMTHRD_LEN(ap)) 174cc391cceSBruce M Simpson #define aar_tpa(ap) (aar_tsa(ap) + ATMTSLN(ap)) 175cc391cceSBruce M Simpson }; 176cc391cceSBruce M Simpson 177cc391cceSBruce M Simpson #define ATMSHA(ap) (aar_sha(ap)) 178cc391cceSBruce M Simpson #define ATMSSA(ap) (aar_ssa(ap)) 179cc391cceSBruce M Simpson #define ATMSPA(ap) (aar_spa(ap)) 180cc391cceSBruce M Simpson #define ATMTHA(ap) (aar_tha(ap)) 181cc391cceSBruce M Simpson #define ATMTSA(ap) (aar_tsa(ap)) 182cc391cceSBruce M Simpson #define ATMTPA(ap) (aar_tpa(ap)) 183cc391cceSBruce M Simpson 1844edb46e9SPaul Traina static u_char ezero[6]; 1854edb46e9SPaul Traina 186cc391cceSBruce M Simpson static void 187c1ad1296SSam Leffler atmarp_addr_print(netdissect_options *ndo, 188c1ad1296SSam Leffler const u_char *ha, u_int ha_len, const u_char *srca, 189cc391cceSBruce M Simpson u_int srca_len) 190cc391cceSBruce M Simpson { 191cc391cceSBruce M Simpson if (ha_len == 0) 192c1ad1296SSam Leffler ND_PRINT((ndo, "<No address>")); 193cc391cceSBruce M Simpson else { 194a5779b6eSRui Paulo ND_PRINT((ndo, "%s", linkaddr_string(ha, LINKADDR_ATM, ha_len))); 195cc391cceSBruce M Simpson if (srca_len != 0) 196c1ad1296SSam Leffler ND_PRINT((ndo, ",%s", 197a5779b6eSRui Paulo linkaddr_string(srca, LINKADDR_ATM, srca_len))); 198cc391cceSBruce M Simpson } 199cc391cceSBruce M Simpson } 200cc391cceSBruce M Simpson 201cc391cceSBruce M Simpson static void 202c1ad1296SSam Leffler atmarp_print(netdissect_options *ndo, 203c1ad1296SSam Leffler const u_char *bp, u_int length, u_int caplen) 204cc391cceSBruce M Simpson { 205cc391cceSBruce M Simpson const struct atmarp_pkthdr *ap; 206cc391cceSBruce M Simpson u_short pro, hrd, op; 207cc391cceSBruce M Simpson 208cc391cceSBruce M Simpson ap = (const struct atmarp_pkthdr *)bp; 209c1ad1296SSam Leffler ND_TCHECK(*ap); 210cc391cceSBruce M Simpson 211cc391cceSBruce M Simpson hrd = ATMHRD(ap); 212cc391cceSBruce M Simpson pro = ATMPRO(ap); 213cc391cceSBruce M Simpson op = ATMOP(ap); 214cc391cceSBruce M Simpson 215a5779b6eSRui Paulo if (!ND_TTEST2(*aar_tpa(ap), ATMTPROTO_LEN(ap))) { 216a5779b6eSRui Paulo ND_PRINT((ndo, "[|ARP]")); 217c1ad1296SSam Leffler ND_DEFAULTPRINT((const u_char *)ap, length); 218cc391cceSBruce M Simpson return; 219cc391cceSBruce M Simpson } 220cc391cceSBruce M Simpson 221a5779b6eSRui Paulo if (!ndo->ndo_eflag) { 222a5779b6eSRui Paulo ND_PRINT((ndo, "ARP, ")); 223cc391cceSBruce M Simpson } 224a5779b6eSRui Paulo 225a5779b6eSRui Paulo if ((pro != ETHERTYPE_IP && pro != ETHERTYPE_TRAIL) || 226a5779b6eSRui Paulo ATMSPROTO_LEN(ap) != 4 || 227a5779b6eSRui Paulo ATMTPROTO_LEN(ap) != 4 || 228a5779b6eSRui Paulo ndo->ndo_vflag) { 229a5779b6eSRui Paulo ND_PRINT((ndo, "%s, %s (len %u/%u)", 230a5779b6eSRui Paulo tok2str(arphrd_values, "Unknown Hardware (%u)", hrd), 231a5779b6eSRui Paulo tok2str(ethertype_values, "Unknown Protocol (0x%04x)", pro), 232a5779b6eSRui Paulo ATMSPROTO_LEN(ap), 233a5779b6eSRui Paulo ATMTPROTO_LEN(ap))); 234a5779b6eSRui Paulo 235a5779b6eSRui Paulo /* don't know know about the address formats */ 236a5779b6eSRui Paulo if (!ndo->ndo_vflag) { 237a5779b6eSRui Paulo goto out; 238a5779b6eSRui Paulo } 239a5779b6eSRui Paulo } 240a5779b6eSRui Paulo 241a5779b6eSRui Paulo /* print operation */ 242a5779b6eSRui Paulo printf("%s%s ", 243a5779b6eSRui Paulo ndo->ndo_vflag ? ", " : "", 244a5779b6eSRui Paulo tok2str(arpop_values, "Unknown (%u)", op)); 245a5779b6eSRui Paulo 246cc391cceSBruce M Simpson switch (op) { 247cc391cceSBruce M Simpson 248cc391cceSBruce M Simpson case ARPOP_REQUEST: 249a5779b6eSRui Paulo ND_PRINT((ndo, "who-has %s", ipaddr_string(ATMTPA(ap)))); 250a5779b6eSRui Paulo if (ATMTHRD_LEN(ap) != 0) { 251c1ad1296SSam Leffler ND_PRINT((ndo, " (")); 252a5779b6eSRui Paulo atmarp_addr_print(ndo, ATMTHA(ap), ATMTHRD_LEN(ap), 253cc391cceSBruce M Simpson ATMTSA(ap), ATMTSLN(ap)); 254c1ad1296SSam Leffler ND_PRINT((ndo, ")")); 255cc391cceSBruce M Simpson } 256c1ad1296SSam Leffler ND_PRINT((ndo, "tell %s", ipaddr_string(ATMSPA(ap)))); 257cc391cceSBruce M Simpson break; 258cc391cceSBruce M Simpson 259cc391cceSBruce M Simpson case ARPOP_REPLY: 260a5779b6eSRui Paulo ND_PRINT((ndo, "%s is-at ", ipaddr_string(ATMSPA(ap)))); 261a5779b6eSRui Paulo atmarp_addr_print(ndo, ATMSHA(ap), ATMSHRD_LEN(ap), ATMSSA(ap), 262cc391cceSBruce M Simpson ATMSSLN(ap)); 263cc391cceSBruce M Simpson break; 264cc391cceSBruce M Simpson 265cc391cceSBruce M Simpson case ARPOP_INVREQUEST: 266a5779b6eSRui Paulo ND_PRINT((ndo, "who-is ")); 267a5779b6eSRui Paulo atmarp_addr_print(ndo, ATMTHA(ap), ATMTHRD_LEN(ap), ATMTSA(ap), 268cc391cceSBruce M Simpson ATMTSLN(ap)); 269c1ad1296SSam Leffler ND_PRINT((ndo, " tell ")); 270a5779b6eSRui Paulo atmarp_addr_print(ndo, ATMSHA(ap), ATMSHRD_LEN(ap), ATMSSA(ap), 271cc391cceSBruce M Simpson ATMSSLN(ap)); 272cc391cceSBruce M Simpson break; 273cc391cceSBruce M Simpson 274cc391cceSBruce M Simpson case ARPOP_INVREPLY: 275a5779b6eSRui Paulo atmarp_addr_print(ndo, ATMSHA(ap), ATMSHRD_LEN(ap), ATMSSA(ap), 276cc391cceSBruce M Simpson ATMSSLN(ap)); 277c1ad1296SSam Leffler ND_PRINT((ndo, "at %s", ipaddr_string(ATMSPA(ap)))); 278cc391cceSBruce M Simpson break; 279cc391cceSBruce M Simpson 280a5779b6eSRui Paulo case ARPOP_NAK: 281a5779b6eSRui Paulo ND_PRINT((ndo, "for %s", ipaddr_string(ATMSPA(ap)))); 282cc391cceSBruce M Simpson break; 283cc391cceSBruce M Simpson 284cc391cceSBruce M Simpson default: 285c1ad1296SSam Leffler ND_DEFAULTPRINT((const u_char *)ap, caplen); 286cc391cceSBruce M Simpson return; 287cc391cceSBruce M Simpson } 288a5779b6eSRui Paulo 289a5779b6eSRui Paulo out: 290a5779b6eSRui Paulo ND_PRINT((ndo, ", length %u", length)); 291cc391cceSBruce M Simpson return; 292a5779b6eSRui Paulo 293cc391cceSBruce M Simpson trunc: 294a5779b6eSRui Paulo ND_PRINT((ndo, "[|ARP]")); 295cc391cceSBruce M Simpson } 296cc391cceSBruce M Simpson 2974edb46e9SPaul Traina void 298c1ad1296SSam Leffler arp_print(netdissect_options *ndo, 299c1ad1296SSam Leffler const u_char *bp, u_int length, u_int caplen) 3004edb46e9SPaul Traina { 3010e0def19SBill Fenner const struct arp_pkthdr *ap; 302a5779b6eSRui Paulo u_short pro, hrd, op, linkaddr; 3034edb46e9SPaul Traina 3040e0def19SBill Fenner ap = (const struct arp_pkthdr *)bp; 305c1ad1296SSam Leffler ND_TCHECK(*ap); 306a5779b6eSRui Paulo 307cc391cceSBruce M Simpson hrd = HRD(ap); 308cc391cceSBruce M Simpson pro = PRO(ap); 309cc391cceSBruce M Simpson op = OP(ap); 310cc391cceSBruce M Simpson 311a5779b6eSRui Paulo 312a5779b6eSRui Paulo /* if its ATM then call the ATM ARP printer 313a5779b6eSRui Paulo for Frame-relay ARP most of the fields 314a5779b6eSRui Paulo are similar to Ethernet so overload the Ethernet Printer 315a5779b6eSRui Paulo and set the linkaddr type for linkaddr_string() accordingly */ 316a5779b6eSRui Paulo 317a5779b6eSRui Paulo switch(hrd) { 318a5779b6eSRui Paulo case ARPHRD_ATM2225: 319a5779b6eSRui Paulo atmarp_print(ndo, bp, length, caplen); 320a5779b6eSRui Paulo return; 321a5779b6eSRui Paulo case ARPHRD_FRELAY: 322a5779b6eSRui Paulo linkaddr = LINKADDR_FRELAY; 323a5779b6eSRui Paulo default: 324a5779b6eSRui Paulo linkaddr = LINKADDR_ETHER; 325a5779b6eSRui Paulo break; 326a5779b6eSRui Paulo } 327a5779b6eSRui Paulo 328a5779b6eSRui Paulo if (!ND_TTEST2(*ar_tpa(ap), PROTO_LEN(ap))) { 329a5779b6eSRui Paulo ND_PRINT((ndo, "[|ARP]")); 330c1ad1296SSam Leffler ND_DEFAULTPRINT((const u_char *)ap, length); 3314edb46e9SPaul Traina return; 3324edb46e9SPaul Traina } 3334edb46e9SPaul Traina 334a5779b6eSRui Paulo if (!ndo->ndo_eflag) { 335a5779b6eSRui Paulo ND_PRINT((ndo, "ARP, ")); 3364edb46e9SPaul Traina } 337a5779b6eSRui Paulo 338a5779b6eSRui Paulo /* print hardware type/len and proto type/len */ 339a5779b6eSRui Paulo if ((pro != ETHERTYPE_IP && pro != ETHERTYPE_TRAIL) || 340a5779b6eSRui Paulo PROTO_LEN(ap) != 4 || 341a5779b6eSRui Paulo HRD_LEN(ap) == 0 || 342a5779b6eSRui Paulo ndo->ndo_vflag) { 343a5779b6eSRui Paulo ND_PRINT((ndo, "%s (len %u), %s (len %u)", 344a5779b6eSRui Paulo tok2str(arphrd_values, "Unknown Hardware (%u)", hrd), 345a5779b6eSRui Paulo HRD_LEN(ap), 346a5779b6eSRui Paulo tok2str(ethertype_values, "Unknown Protocol (0x%04x)", pro), 347a5779b6eSRui Paulo PROTO_LEN(ap))); 348a5779b6eSRui Paulo 349a5779b6eSRui Paulo /* don't know know about the address formats */ 350a5779b6eSRui Paulo if (!ndo->ndo_vflag) { 351a5779b6eSRui Paulo goto out; 352a5779b6eSRui Paulo } 353a5779b6eSRui Paulo } 354a5779b6eSRui Paulo 355a5779b6eSRui Paulo /* print operation */ 356a5779b6eSRui Paulo printf("%s%s ", 357a5779b6eSRui Paulo ndo->ndo_vflag ? ", " : "", 358a5779b6eSRui Paulo tok2str(arpop_values, "Unknown (%u)", op)); 359a5779b6eSRui Paulo 3604edb46e9SPaul Traina switch (op) { 3614edb46e9SPaul Traina 3624edb46e9SPaul Traina case ARPOP_REQUEST: 363a5779b6eSRui Paulo ND_PRINT((ndo, "who-has %s", ipaddr_string(TPA(ap)))); 364a5779b6eSRui Paulo if (memcmp((const char *)ezero, (const char *)THA(ap), HRD_LEN(ap)) != 0) 365c1ad1296SSam Leffler ND_PRINT((ndo, " (%s)", 366a5779b6eSRui Paulo linkaddr_string(THA(ap), linkaddr, HRD_LEN(ap)))); 367c1ad1296SSam Leffler ND_PRINT((ndo, " tell %s", ipaddr_string(SPA(ap)))); 3684edb46e9SPaul Traina break; 3694edb46e9SPaul Traina 3704edb46e9SPaul Traina case ARPOP_REPLY: 371a5779b6eSRui Paulo ND_PRINT((ndo, "%s is-at %s", 372a5779b6eSRui Paulo ipaddr_string(SPA(ap)), 373a5779b6eSRui Paulo linkaddr_string(SHA(ap), linkaddr, HRD_LEN(ap)))); 3744edb46e9SPaul Traina break; 3754edb46e9SPaul Traina 376a1c2090eSBill Fenner case ARPOP_REVREQUEST: 377a5779b6eSRui Paulo ND_PRINT((ndo, "who-is %s tell %s", 378a5779b6eSRui Paulo linkaddr_string(THA(ap), linkaddr, HRD_LEN(ap)), 379a5779b6eSRui Paulo linkaddr_string(SHA(ap), linkaddr, HRD_LEN(ap)))); 3804edb46e9SPaul Traina break; 3814edb46e9SPaul Traina 382a1c2090eSBill Fenner case ARPOP_REVREPLY: 383a5779b6eSRui Paulo ND_PRINT((ndo, "%s at %s", 384a5779b6eSRui Paulo linkaddr_string(THA(ap), linkaddr, HRD_LEN(ap)), 385c1ad1296SSam Leffler ipaddr_string(TPA(ap)))); 3864edb46e9SPaul Traina break; 3874edb46e9SPaul Traina 388cc391cceSBruce M Simpson case ARPOP_INVREQUEST: 389a5779b6eSRui Paulo ND_PRINT((ndo, "who-is %s tell %s", 390a5779b6eSRui Paulo linkaddr_string(THA(ap), linkaddr, HRD_LEN(ap)), 391a5779b6eSRui Paulo linkaddr_string(SHA(ap), linkaddr, HRD_LEN(ap)))); 392cc391cceSBruce M Simpson break; 393cc391cceSBruce M Simpson 394cc391cceSBruce M Simpson case ARPOP_INVREPLY: 395a5779b6eSRui Paulo ND_PRINT((ndo,"%s at %s", 396a5779b6eSRui Paulo linkaddr_string(THA(ap), linkaddr, HRD_LEN(ap)), 397c1ad1296SSam Leffler ipaddr_string(TPA(ap)))); 398cc391cceSBruce M Simpson break; 399cc391cceSBruce M Simpson 4004edb46e9SPaul Traina default: 401c1ad1296SSam Leffler ND_DEFAULTPRINT((const u_char *)ap, caplen); 4024edb46e9SPaul Traina return; 4034edb46e9SPaul Traina } 404a5779b6eSRui Paulo 405a5779b6eSRui Paulo out: 406a5779b6eSRui Paulo ND_PRINT((ndo, ", length %u", length)); 407a5779b6eSRui Paulo 408a1c2090eSBill Fenner return; 409a1c2090eSBill Fenner trunc: 410a5779b6eSRui Paulo ND_PRINT((ndo, "[|ARP]")); 4114edb46e9SPaul Traina } 412c1ad1296SSam Leffler 413c1ad1296SSam Leffler /* 414c1ad1296SSam Leffler * Local Variables: 415c1ad1296SSam Leffler * c-style: bsd 416c1ad1296SSam Leffler * End: 417c1ad1296SSam Leffler */ 418c1ad1296SSam Leffler 419