make: minor: update comment
[netsniff-ng.git] / proto_arp.c
blob43555046b484b7226eba4a91ea692b2a3d15f672
1 /*
2 * netsniff-ng - the packet sniffing beast
3 * By Daniel Borkmann <daniel@netsniff-ng.org>
4 * Copyright 2009, 2010 Daniel Borkmann.
5 * Subject to the GPL, version 2.
6 */
8 #include <stdint.h>
9 #include <netinet/in.h> /* for ntohs() */
11 #include "proto.h"
12 #include "protos.h"
13 #include "dissector_eth.h"
14 #include "pkt_buff.h"
15 #include "built_in.h"
17 struct arphdr {
18 uint16_t ar_hrd; /* format of hardware address */
19 uint16_t ar_pro; /* format of protocol address */
20 uint8_t ar_hln; /* length of hardware address */
21 uint8_t ar_pln; /* length of protocol address */
22 uint16_t ar_op; /* ARP opcode (command) */
23 uint8_t ar_sha[6]; /* sender hardware address */
24 uint8_t ar_sip[4]; /* sender IP address */
25 uint8_t ar_tha[6]; /* target hardware address */
26 uint8_t ar_tip[4]; /* target IP address */
27 } __packed;
29 #define ARPOP_REQUEST 1 /* ARP request */
30 #define ARPOP_REPLY 2 /* ARP reply */
31 #define ARPOP_RREQUEST 3 /* RARP request */
32 #define ARPOP_RREPLY 4 /* RARP reply */
33 #define ARPOP_InREQUEST 8 /* InARP request */
34 #define ARPOP_InREPLY 9 /* InARP reply */
35 #define ARPOP_NAK 10 /* (ATM)ARP NAK */
37 static void arp(struct pkt_buff *pkt)
39 char *opcode = NULL;
40 struct arphdr *arp = (struct arphdr *) pkt_pull(pkt, sizeof(*arp));
42 if (arp == NULL)
43 return;
45 switch (ntohs(arp->ar_op)) {
46 case ARPOP_REQUEST:
47 opcode = "ARP request";
48 break;
49 case ARPOP_REPLY:
50 opcode = "ARP reply";
51 break;
52 case ARPOP_RREQUEST:
53 opcode = "RARP request";
54 break;
55 case ARPOP_RREPLY:
56 opcode = "RARP reply";
57 break;
58 case ARPOP_InREQUEST:
59 opcode = "InARP request";
60 break;
61 case ARPOP_InREPLY:
62 opcode = "InARP reply";
63 break;
64 case ARPOP_NAK:
65 opcode = "(ATM) ARP NAK";
66 break;
67 default:
68 opcode = "Unknown";
69 break;
72 tprintf(" [ ARP ");
73 tprintf("Format HA (%u), ", ntohs(arp->ar_hrd));
74 tprintf("Format Proto (%u), ", ntohs(arp->ar_pro));
75 tprintf("HA Len (%u), ", ntohs(arp->ar_hln));
76 tprintf("Proto Len (%u), ", ntohs(arp->ar_pln));
77 tprintf("Opcode (%u => %s)", ntohs(arp->ar_op), opcode);
78 tprintf(" ]\n");
81 static void arp_less(struct pkt_buff *pkt)
83 char *opcode = NULL;
84 struct arphdr *arp = (struct arphdr *) pkt_pull(pkt, sizeof(*arp));
86 if (arp == NULL)
87 return;
89 switch (ntohs(arp->ar_op)) {
90 case ARPOP_REQUEST:
91 opcode = "ARP request";
92 break;
93 case ARPOP_REPLY:
94 opcode = "ARP reply";
95 break;
96 case ARPOP_RREQUEST:
97 opcode = "RARP request";
98 break;
99 case ARPOP_RREPLY:
100 opcode = "RARP reply";
101 break;
102 case ARPOP_InREQUEST:
103 opcode = "InARP request";
104 break;
105 case ARPOP_InREPLY:
106 opcode = "InARP reply";
107 break;
108 case ARPOP_NAK:
109 opcode = "(ATM) ARP NAK";
110 break;
111 default:
112 opcode = "Unknown";
113 break;
116 tprintf(" Op %s", opcode);
119 struct protocol arp_ops = {
120 .key = 0x0806,
121 .print_full = arp,
122 .print_less = arp_less,