proto_ipv6_mobility_hdr.h: Headerfixing
[netsniff-ng.git] / src / proto_arp.h
blob3d08a6d8330f716c326b5186b47e509a309b5d1a
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 #ifndef PROTO_ARP_H
9 #define PROTO_ARP_H
11 #include <stdint.h>
12 #include <stdint.h>
13 #include <netinet/in.h> /* for ntohs() */
15 #include "proto_struct.h"
16 #include "dissector_eth.h"
17 #include "pkt_buff.h"
18 #include "built_in.h"
20 struct arphdr {
21 uint16_t ar_hrd; /* format of hardware address */
22 uint16_t ar_pro; /* format of protocol address */
23 uint8_t ar_hln; /* length of hardware address */
24 uint8_t ar_pln; /* length of protocol address */
25 uint16_t ar_op; /* ARP opcode (command) */
26 uint8_t ar_sha[6]; /* sender hardware address */
27 uint8_t ar_sip[4]; /* sender IP address */
28 uint8_t ar_tha[6]; /* target hardware address */
29 uint8_t ar_tip[4]; /* target IP address */
30 } __packed;
32 #define ARPOP_REQUEST 1 /* ARP request */
33 #define ARPOP_REPLY 2 /* ARP reply */
34 #define ARPOP_RREQUEST 3 /* RARP request */
35 #define ARPOP_RREPLY 4 /* RARP reply */
36 #define ARPOP_InREQUEST 8 /* InARP request */
37 #define ARPOP_InREPLY 9 /* InARP reply */
38 #define ARPOP_NAK 10 /* (ATM)ARP NAK */
40 static inline void arp(struct pkt_buff *pkt)
42 char *opcode = NULL;
43 struct arphdr *arp = (struct arphdr *) pkt_pull(pkt, sizeof(*arp));
45 if (arp == NULL)
46 return;
48 switch (ntohs(arp->ar_op)) {
49 case ARPOP_REQUEST:
50 opcode = "ARP request";
51 break;
52 case ARPOP_REPLY:
53 opcode = "ARP reply";
54 break;
55 case ARPOP_RREQUEST:
56 opcode = "RARP request";
57 break;
58 case ARPOP_RREPLY:
59 opcode = "RARP reply";
60 break;
61 case ARPOP_InREQUEST:
62 opcode = "InARP request";
63 break;
64 case ARPOP_InREPLY:
65 opcode = "InARP reply";
66 break;
67 case ARPOP_NAK:
68 opcode = "(ATM) ARP NAK";
69 break;
70 default:
71 opcode = "Unknown";
72 break;
75 tprintf(" [ ARP ");
76 tprintf("Format HA (%u), ", ntohs(arp->ar_hrd));
77 tprintf("Format Proto (%u), ", ntohs(arp->ar_pro));
78 tprintf("HA Len (%u), ", ntohs(arp->ar_hln));
79 tprintf("Proto Len (%u), ", ntohs(arp->ar_pln));
80 tprintf("Opcode (%u => %s)", ntohs(arp->ar_op), opcode);
81 tprintf(" ]\n");
84 static inline void arp_less(struct pkt_buff *pkt)
86 char *opcode = NULL;
87 struct arphdr *arp = (struct arphdr *) pkt_pull(pkt, sizeof(*arp));
89 if (arp == NULL)
90 return;
92 switch (ntohs(arp->ar_op)) {
93 case ARPOP_REQUEST:
94 opcode = "ARP request";
95 break;
96 case ARPOP_REPLY:
97 opcode = "ARP reply";
98 break;
99 case ARPOP_RREQUEST:
100 opcode = "RARP request";
101 break;
102 case ARPOP_RREPLY:
103 opcode = "RARP reply";
104 break;
105 case ARPOP_InREQUEST:
106 opcode = "InARP request";
107 break;
108 case ARPOP_InREPLY:
109 opcode = "InARP reply";
110 break;
111 case ARPOP_NAK:
112 opcode = "(ATM) ARP NAK";
113 break;
114 default:
115 opcode = "Unknown";
116 break;
119 tprintf(" Op %s", opcode);
122 struct protocol arp_ops = {
123 .key = 0x0806,
124 .print_full = arp,
125 .print_less = arp_less,
128 #endif /* PROTO_ARP_H */