-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy patharpdump.c
120 lines (113 loc) · 3.26 KB
/
arpdump.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
/* ARP packet tracing routines
* Copyright 1991 Phil Karn, KA9Q
*/
/* Tracing to sockets, mods April '95 by Johan. K. Reinalda, WG7J */
#include "global.h"
#include "mbuf.h"
#include "arp.h"
#include "netuser.h"
#include "trace.h"
#include "socket.h"
void
arp_dump(s,bpp)
int s;
struct mbuf **bpp;
{
struct arp arp;
struct arp_type *at;
int is_ip = 0;
char tmp[25];
if(bpp == NULLBUFP || *bpp == NULLBUF)
return;
#ifdef MONITOR
if (Trace_compact_header)
{
/* it's different enough that we just do it here */
/* except for the setup, that is... */
if (ntoharp(&arp,bpp) == -1)
{
usprintf(s, "bad packet\n");
return;
}
if (arp.hardware < NHWTYPES)
at = &Arp_type[arp.hardware];
else
at = NULLATYPE;
if (at != NULLATYPE && arp.protocol == at->iptype)
is_ip = 1;
switch (arp.opcode)
{
case ARP_REQUEST:
case REVARP_REQUEST:
usprintf(s, "REQ");
break;
case ARP_REPLY:
case REVARP_REPLY:
usprintf(s, "REP");
break;
default:
usprintf(s, "%u", arp.opcode);
break;
}
if (is_ip)
usprintf(s, " %s@", inet_ntoa(arp.sprotaddr));
if (at)
usprintf(s, "%s->", at->format(tmp, arp.shwaddr));
if (is_ip)
usprintf(s, "%s@", inet_ntoa(arp.tprotaddr));
if (at)
usprintf(s, "%s", at->format(tmp, arp.thwaddr));
usprintf(s, "\n");
return;
}
#endif
usprintf(s,"ARP: len %d",len_p(*bpp));
if(ntoharp(&arp,bpp) == -1){
usprintf(s," bad packet\n");
return;
}
if(arp.hardware < NHWTYPES)
at = &Arp_type[arp.hardware];
else
at = NULLATYPE;
/* Print hardware type in Ascii if known, numerically if not */
usprintf(s," hwtype %s",smsg(Arptypes,NHWTYPES,arp.hardware));
/* Print hardware length only if unknown type, or if it doesn't match
* the length in the known types table
*/
if(at == NULLATYPE || arp.hwalen != at->hwalen)
usprintf(s," hwlen %u",arp.hwalen);
/* Check for most common case -- upper level protocol is IP */
if(at != NULLATYPE && arp.protocol == at->iptype){
usprintf(s," prot IP");
is_ip = 1;
} else {
usprintf(s," prot 0x%x prlen %u",arp.protocol,arp.pralen);
}
switch(arp.opcode){
case ARP_REQUEST:
usprintf(s," op REQUEST");
break;
case ARP_REPLY:
usprintf(s," op REPLY");
break;
case REVARP_REQUEST:
usprintf(s," op REVERSE REQUEST");
break;
case REVARP_REPLY:
usprintf(s," op REVERSE REPLY");
break;
default:
usprintf(s," op %u",arp.opcode);
break;
}
usprintf(s,"\n");
usprintf(s,"sender");
if(is_ip)
usprintf(s," IPaddr %s",inet_ntoa(arp.sprotaddr));
usprintf(s," hwaddr %s\n",at->format(tmp,arp.shwaddr));
usprintf(s,"target");
if(is_ip)
usprintf(s," IPaddr %s",inet_ntoa(arp.tprotaddr));
usprintf(s," hwaddr %s\n",at->format(tmp,arp.thwaddr));
}