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() */
11 #include "dissector_eth.h"
16 uint16_t ar_hrd
; /* format of hardware address */
17 uint16_t ar_pro
; /* format of protocol address */
18 uint8_t ar_hln
; /* length of hardware address */
19 uint8_t ar_pln
; /* length of protocol address */
20 uint16_t ar_op
; /* ARP opcode (command) */
21 uint8_t ar_sha
[6]; /* sender hardware address */
22 uint8_t ar_sip
[4]; /* sender IP address */
23 uint8_t ar_tha
[6]; /* target hardware address */
24 uint8_t ar_tip
[4]; /* target IP address */
27 #define ARPHRD_ETHER 1
28 #define ARPHRD_IEEE802 6
29 #define ARPHRD_ARCNET 7
31 #define ARPHRD_ATM2 19
32 #define ARPHRD_SERIAL 20
33 #define ARPHRD_ATM3 21
34 #define ARPHRD_IEEE1394 24
36 #define ARPOP_REQUEST 1 /* ARP request */
37 #define ARPOP_REPLY 2 /* ARP reply */
38 #define ARPOP_RREQUEST 3 /* RARP request */
39 #define ARPOP_RREPLY 4 /* RARP reply */
40 #define ARPOP_InREQUEST 8 /* InARP request */
41 #define ARPOP_InREPLY 9 /* InARP reply */
42 #define ARPOP_NAK 10 /* (ATM)ARP NAK */
44 static void arp(struct pkt_buff
*pkt
)
49 struct arphdr
*arp
= (struct arphdr
*) pkt_pull(pkt
, sizeof(*arp
));
54 switch (ntohs(arp
->ar_hrd
)) {
73 hrd
= "IEEE 1394.1995";
80 pro
= lookup_ether_type(ntohs(arp
->ar_pro
));
84 switch (ntohs(arp
->ar_op
)) {
86 opcode
= "ARP request";
92 opcode
= "RARP request";
95 opcode
= "RARP reply";
98 opcode
= "InARP request";
101 opcode
= "InARP reply";
104 opcode
= "(ATM) ARP NAK";
112 tprintf("Format HA (%u => %s), ", ntohs(arp
->ar_hrd
), hrd
);
113 tprintf("Format Proto (0x%.4x => %s), ", ntohs(arp
->ar_pro
), pro
);
114 tprintf("HA Len (%u), ", arp
->ar_hln
);
115 tprintf("Proto Len (%u), ", arp
->ar_pln
);
116 tprintf("Opcode (%u => %s)", ntohs(arp
->ar_op
), opcode
);
120 static void arp_less(struct pkt_buff
*pkt
)
123 struct arphdr
*arp
= (struct arphdr
*) pkt_pull(pkt
, sizeof(*arp
));
128 switch (ntohs(arp
->ar_op
)) {
130 opcode
= "ARP request";
133 opcode
= "ARP reply";
136 opcode
= "RARP request";
139 opcode
= "RARP reply";
141 case ARPOP_InREQUEST
:
142 opcode
= "InARP request";
145 opcode
= "InARP reply";
148 opcode
= "(ATM) ARP NAK";
155 tprintf(" Op %s", opcode
);
158 struct protocol arp_ops
= {
161 .print_less
= arp_less
,