2 * netsniff-ng - the packet sniffing beast
3 * Copyright 2009, 2010 Daniel Borkmann.
4 * Subject to the GPL, version 2.
8 #include <netinet/in.h> /* for ntohs() */
17 uint16_t ar_hrd
; /* format of hardware address */
18 uint16_t ar_pro
; /* format of protocol address */
19 uint8_t ar_hln
; /* length of hardware address */
20 uint8_t ar_pln
; /* length of protocol address */
21 uint16_t ar_op
; /* ARP opcode (command) */
22 uint8_t ar_sha
[6]; /* sender hardware address */
23 uint8_t ar_sip
[4]; /* sender IP address */
24 uint8_t ar_tha
[6]; /* target hardware address */
25 uint8_t ar_tip
[4]; /* target IP address */
28 #define ARPHRD_ETHER 1
29 #define ARPHRD_IEEE802 6
30 #define ARPHRD_ARCNET 7
32 #define ARPHRD_ATM2 19
33 #define ARPHRD_SERIAL 20
34 #define ARPHRD_ATM3 21
35 #define ARPHRD_IEEE1394 24
37 #define ARPOP_REQUEST 1 /* ARP request */
38 #define ARPOP_REPLY 2 /* ARP reply */
39 #define ARPOP_RREQUEST 3 /* RARP request */
40 #define ARPOP_RREPLY 4 /* RARP reply */
41 #define ARPOP_InREQUEST 8 /* InARP request */
42 #define ARPOP_InREPLY 9 /* InARP reply */
43 #define ARPOP_NAK 10 /* (ATM)ARP NAK */
45 static void arp(struct pkt_buff
*pkt
)
50 struct arphdr
*arp
= (struct arphdr
*) pkt_pull(pkt
, sizeof(*arp
));
55 switch (ntohs(arp
->ar_hrd
)) {
74 hrd
= "IEEE 1394.1995";
81 pro
= lookup_ether_type(ntohs(arp
->ar_pro
));
85 switch (ntohs(arp
->ar_op
)) {
87 opcode
= "ARP request";
93 opcode
= "RARP request";
96 opcode
= "RARP reply";
99 opcode
= "InARP request";
102 opcode
= "InARP reply";
105 opcode
= "(ATM) ARP NAK";
113 tprintf("Format HA (%u => %s), ", ntohs(arp
->ar_hrd
), hrd
);
114 tprintf("Format Proto (0x%.4x => %s), ", ntohs(arp
->ar_pro
), pro
);
115 tprintf("HA Len (%u), ", arp
->ar_hln
);
116 tprintf("Proto Len (%u), ", arp
->ar_pln
);
117 tprintf("Opcode (%u => %s)", ntohs(arp
->ar_op
), opcode
);
121 static void arp_less(struct pkt_buff
*pkt
)
124 struct arphdr
*arp
= (struct arphdr
*) pkt_pull(pkt
, sizeof(*arp
));
129 switch (ntohs(arp
->ar_op
)) {
131 opcode
= "ARP request";
134 opcode
= "ARP reply";
137 opcode
= "RARP request";
140 opcode
= "RARP reply";
142 case ARPOP_InREQUEST
:
143 opcode
= "InARP request";
146 opcode
= "InARP reply";
149 opcode
= "(ATM) ARP NAK";
156 tprintf(" Op %s", opcode
);
159 struct protocol arp_ops
= {
162 .print_less
= arp_less
,