1 /*
2  * Copyright (c) 1988-1990 The Regents of the University of California.
3  * 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
23 static char rcsid[] =
24     "@(#) $Header: print-arp.c,v 1.16 91/04/19 10:45:56 mccanne Exp $ (LBL)";
25 #endif
26 
27 #include <sys/param.h>
28 #include <sys/types.h>
29 #include <sys/socket.h>
30 #include <net/if.h>
31 #include <netinet/in.h>
32 #include <netinet/if_ether.h>
33 
34 #include "interface.h"
35 #include "addrtoname.h"
36 
37 void
38 arp_print(ap, length, caplen)
39 	register struct ether_arp *ap;
40 	int length;
41 	int caplen;
42 {
43 	if ((u_char *)(ap + 1) > snapend) {
44 		printf("[|arp]");
45 		return;
46 	}
47 	if (length < sizeof(struct ether_arp)) {
48 		(void)printf("truncated-arp");
49 		default_print((u_short *)ap, length);
50 		return;
51 	}
52 
53 	NTOHS(ap->arp_hrd);
54 	NTOHS(ap->arp_pro);
55 	NTOHS(ap->arp_op);
56 
57 	if (ap->arp_hrd != ARPHRD_ETHER
58 	    || (ap->arp_pro != ETHERTYPE_IP
59 		&& ap->arp_pro != ETHERTYPE_TRAIL)
60 	    || ap->arp_hln != sizeof(SHA(ap))
61 	    || ap->arp_pln != sizeof(SPA(ap))) {
62 		(void)printf("arp-req #%d for proto #%d (%d) hardware %d (%d)",
63 				ap->arp_op, ap->arp_pro, ap->arp_pln,
64 				ap->arp_hrd, ap->arp_hln);
65 		return;
66 	}
67 	if (ap->arp_pro == ETHERTYPE_TRAIL)
68 		(void)printf("trailer");
69 	switch (ap->arp_op) {
70 
71 	case ARPOP_REQUEST:
72 		(void)printf("arp who-has %s tell %s",
73 			ipaddr_string(TPA(ap)),
74 			ipaddr_string(SPA(ap)));
75 		break;
76 
77 	case ARPOP_REPLY:
78 		(void)printf("arp reply %s is-at %s",
79 			ipaddr_string(SPA(ap)),
80 			etheraddr_string(SHA(ap)));
81 		break;
82 
83 	case REVARP_REQUEST:
84 		(void)printf("rarp who-is %s tell %s",
85 			etheraddr_string(THA(ap)),
86 			etheraddr_string(SHA(ap)));
87 		break;
88 
89 	case REVARP_REPLY:
90 		(void)printf("rarp reply %s at %s",
91 			etheraddr_string(THA(ap)),
92 			ipaddr_string(TPA(ap)));
93 		break;
94 
95 	default:
96 		(void)printf("arp-%d", ap->arp_op);
97 		default_print((u_short *)ap, caplen);
98 		break;
99 	}
100 }
101