Debian Codegraph @

listen/arpdump.c

raw
1 /* ARP packet tracing routines
2 * Copyright 1991 Phil Karn, KA9Q
3 */
4 #include <stdio.h>
5 #include "listen.h"
6
7 #define ARP_REQUEST 1
8 #define ARP_REPLY 2
9 #define REVARP_REQUEST 3
10 #define REVARP_REPLY 4
11
12 #define ARP_AX25 3
13
14 #define AXALEN 7
15
16 #define PID_IP 0xCC
17
18 void arp_dump(unsigned char *data, int length)
19 {
20 int is_ip = 0;
21 int hardware;
22 int protocol;
23 int hwlen;
24 int pralen;
25 int operation;
26 unsigned char *shwaddr, *sprotaddr;
27 unsigned char *thwaddr, *tprotaddr;
28 char tmp[25];
29
30 lprintf(T_PROTOCOL, "ARP: ");
31 lprintf(T_IPHDR, "len %d", length);
32 if (length < 16) {
33 lprintf(T_ERROR, " bad packet\n");
34 return;
35 }
36
37 hardware = get16(data + 0);
38 protocol = get16(data + 2);
39 hwlen = data[4];
40 pralen = data[5];
41 operation = get16(data + 6);
42
43 if (hardware != ARP_AX25) {
44 lprintf(T_IPHDR, " non-AX25 ARP packet\n");
45 return;
46 }
47
48 lprintf(T_IPHDR, " hwtype AX25");
49
50 /* Print hardware length only if it doesn't match
51 * the length in the known types table
52 */
53 if (hwlen != AXALEN)
54 lprintf(T_IPHDR, " hwlen %d", hwlen);
55
56 if (protocol == PID_IP) {
57 lprintf(T_IPHDR, " prot IP");
58 is_ip = 1;
59 } else {
60 lprintf(T_IPHDR, " prot 0x%x prlen %d", protocol, pralen);
61 }
62
63 switch (operation) {
64 case ARP_REQUEST:
65 lprintf(T_IPHDR, " op REQUEST");
66 break;
67 case ARP_REPLY:
68 lprintf(T_IPHDR, " op REPLY");
69 break;
70 case REVARP_REQUEST:
71 lprintf(T_IPHDR, " op REVERSE REQUEST");
72 break;
73 case REVARP_REPLY:
74 lprintf(T_IPHDR, " op REVERSE REPLY");
75 break;
76 default:
77 lprintf(T_IPHDR, " op %d", operation);
78 break;
79 }
80
81 shwaddr = data + 8;
82 sprotaddr = shwaddr + hwlen;
83
84 thwaddr = sprotaddr + pralen;
85 tprotaddr = thwaddr + hwlen;
86
87 lprintf(T_IPHDR, "\nsender");
88 if (is_ip)
89 lprintf(T_ADDR, " IPaddr %d.%d.%d.%d",
90 sprotaddr[0], sprotaddr[1],
91 sprotaddr[2], sprotaddr[3]);
92 lprintf(T_IPHDR, " hwaddr %s\n", pax25(tmp, shwaddr));
93
94 lprintf(T_IPHDR, "target");
95 if (is_ip)
96 lprintf(T_ADDR, " IPaddr %d.%d.%d.%d",
97 tprotaddr[0], tprotaddr[1],
98 tprotaddr[2], tprotaddr[3]);
99 if (*thwaddr != 0)
100 lprintf(T_ADDR, " hwaddr %s", pax25(tmp, thwaddr));
101 lprintf(T_IPHDR, "\n");
102 }