docs: add todo's from Sibir's repo
[netsniff-ng.git] / src / proto_arp.c
blobc420a1e8a3f1f2d42518e171981cfa5a5ff56c86
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 <stdint.h>
10 #include <netinet/in.h> /* for ntohs() */
12 #include "proto.h"
13 #include "protos.h"
14 #include "dissector_eth.h"
15 #include "pkt_buff.h"
16 #include "built_in.h"
18 struct arphdr {
19 uint16_t ar_hrd; /* format of hardware address */
20 uint16_t ar_pro; /* format of protocol address */
21 uint8_t ar_hln; /* length of hardware address */
22 uint8_t ar_pln; /* length of protocol address */
23 uint16_t ar_op; /* ARP opcode (command) */
24 uint8_t ar_sha[6]; /* sender hardware address */
25 uint8_t ar_sip[4]; /* sender IP address */
26 uint8_t ar_tha[6]; /* target hardware address */
27 uint8_t ar_tip[4]; /* target IP address */
28 } __packed;
30 #define ARPOP_REQUEST 1 /* ARP request */
31 #define ARPOP_REPLY 2 /* ARP reply */
32 #define ARPOP_RREQUEST 3 /* RARP request */
33 #define ARPOP_RREPLY 4 /* RARP reply */
34 #define ARPOP_InREQUEST 8 /* InARP request */
35 #define ARPOP_InREPLY 9 /* InARP reply */
36 #define ARPOP_NAK 10 /* (ATM)ARP NAK */
38 static void arp(struct pkt_buff *pkt)
40 char *opcode = NULL;
41 struct arphdr *arp = (struct arphdr *) pkt_pull(pkt, sizeof(*arp));
43 if (arp == NULL)
44 return;
46 switch (ntohs(arp->ar_op)) {
47 case ARPOP_REQUEST:
48 opcode = "ARP request";
49 break;
50 case ARPOP_REPLY:
51 opcode = "ARP reply";
52 break;
53 case ARPOP_RREQUEST:
54 opcode = "RARP request";
55 break;
56 case ARPOP_RREPLY:
57 opcode = "RARP reply";
58 break;
59 case ARPOP_InREQUEST:
60 opcode = "InARP request";
61 break;
62 case ARPOP_InREPLY:
63 opcode = "InARP reply";
64 break;
65 case ARPOP_NAK:
66 opcode = "(ATM) ARP NAK";
67 break;
68 default:
69 opcode = "Unknown";
70 break;
73 tprintf(" [ ARP ");
74 tprintf("Format HA (%u), ", ntohs(arp->ar_hrd));
75 tprintf("Format Proto (%u), ", ntohs(arp->ar_pro));
76 tprintf("HA Len (%u), ", ntohs(arp->ar_hln));
77 tprintf("Proto Len (%u), ", ntohs(arp->ar_pln));
78 tprintf("Opcode (%u => %s)", ntohs(arp->ar_op), opcode);
79 tprintf(" ]\n");
82 static void arp_less(struct pkt_buff *pkt)
84 char *opcode = NULL;
85 struct arphdr *arp = (struct arphdr *) pkt_pull(pkt, sizeof(*arp));
87 if (arp == NULL)
88 return;
90 switch (ntohs(arp->ar_op)) {
91 case ARPOP_REQUEST:
92 opcode = "ARP request";
93 break;
94 case ARPOP_REPLY:
95 opcode = "ARP reply";
96 break;
97 case ARPOP_RREQUEST:
98 opcode = "RARP request";
99 break;
100 case ARPOP_RREPLY:
101 opcode = "RARP reply";
102 break;
103 case ARPOP_InREQUEST:
104 opcode = "InARP request";
105 break;
106 case ARPOP_InREPLY:
107 opcode = "InARP reply";
108 break;
109 case ARPOP_NAK:
110 opcode = "(ATM) ARP NAK";
111 break;
112 default:
113 opcode = "Unknown";
114 break;
117 tprintf(" Op %s", opcode);
120 struct protocol arp_ops = {
121 .key = 0x0806,
122 .print_full = arp,
123 .print_less = arp_less,
126 EXPORT_SYMBOL(arp_ops);