print-arp.c revision 26183
1/* 2 * Copyright (c) 1988, 1989, 1990, 1991, 1992, 1993, 1994, 1995, 1996 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. 20 */ 21 22#ifndef lint 23static const char rcsid[] = 24 "@(#) $Header: print-arp.c,v 1.41 96/10/27 14:54:50 leres Exp $ (LBL)"; 25#endif 26 27#include <sys/param.h> 28#include <sys/time.h> 29#include <sys/socket.h> 30 31#if __STDC__ 32struct mbuf; 33struct rtentry; 34#endif 35#include <net/if.h> 36#include <net/if_var.h> 37 38#include <netinet/in.h> 39#include <netinet/if_ether.h> 40 41#include <stdio.h> 42#include <string.h> 43 44#include "interface.h" 45#include "addrtoname.h" 46#include "ethertype.h" 47#include "extract.h" /* must come after interface.h */ 48 49/* Compatibility */ 50#ifndef REVARP_REQUEST 51#define REVARP_REQUEST 3 52#endif 53#ifndef REVARP_REPLY 54#define REVARP_REPLY 4 55#endif 56 57static u_char ezero[6]; 58 59void 60arp_print(register const u_char *bp, u_int length, u_int caplen) 61{ 62 register const struct ether_arp *ap; 63 register const struct ether_header *eh; 64 register u_short pro, hrd, op; 65 66 ap = (struct ether_arp *)bp; 67 if ((u_char *)(ap + 1) > snapend) { 68 printf("[|arp]"); 69 return; 70 } 71 if (length < sizeof(struct ether_arp)) { 72 (void)printf("truncated-arp"); 73 default_print((u_char *)ap, length); 74 return; 75 } 76 77 pro = EXTRACT_16BITS(&ap->arp_pro); 78 hrd = EXTRACT_16BITS(&ap->arp_hrd); 79 op = EXTRACT_16BITS(&ap->arp_op); 80 81 if ((pro != ETHERTYPE_IP && pro != ETHERTYPE_TRAIL) 82 || ap->arp_hln != sizeof(SHA(ap)) 83 || ap->arp_pln != sizeof(SPA(ap))) { 84 (void)printf("arp-#%d for proto #%d (%d) hardware #%d (%d)", 85 op, pro, ap->arp_pln, 86 hrd, ap->arp_hln); 87 return; 88 } 89 if (pro == ETHERTYPE_TRAIL) 90 (void)printf("trailer-"); 91 eh = (struct ether_header *)packetp; 92 switch (op) { 93 94 case ARPOP_REQUEST: 95 (void)printf("arp who-has %s", ipaddr_string(TPA(ap))); 96 if (memcmp((char *)ezero, (char *)THA(ap), 6) != 0) 97 (void)printf(" (%s)", etheraddr_string(THA(ap))); 98 (void)printf(" tell %s", ipaddr_string(SPA(ap))); 99 if (memcmp((char *)ESRC(eh), (char *)SHA(ap), 6) != 0) 100 (void)printf(" (%s)", etheraddr_string(SHA(ap))); 101 break; 102 103 case ARPOP_REPLY: 104 (void)printf("arp reply %s", ipaddr_string(SPA(ap))); 105 if (memcmp((char *)ESRC(eh), (char *)SHA(ap), 6) != 0) 106 (void)printf(" (%s)", etheraddr_string(SHA(ap))); 107 (void)printf(" is-at %s", etheraddr_string(SHA(ap))); 108 if (memcmp((char *)EDST(eh), (char *)THA(ap), 6) != 0) 109 (void)printf(" (%s)", etheraddr_string(THA(ap))); 110 break; 111 112 case REVARP_REQUEST: 113 (void)printf("rarp who-is %s tell %s", 114 etheraddr_string(THA(ap)), 115 etheraddr_string(SHA(ap))); 116 break; 117 118 case REVARP_REPLY: 119 (void)printf("rarp reply %s at %s", 120 etheraddr_string(THA(ap)), 121 ipaddr_string(TPA(ap))); 122 break; 123 124 default: 125 (void)printf("arp-#%d", op); 126 default_print((u_char *)ap, caplen); 127 return; 128 } 129 if (hrd != ARPHRD_ETHER) 130 printf(" hardware #%d", hrd); 131} 132