2 * netsniff-ng - the packet sniffing beast
3 * Subject to the GPL, version 2.
6 #include <net/if_arp.h>
7 #include <linux/if_ether.h>
10 #include "trafgen_l2.h"
11 #include "trafgen_proto.h"
13 struct proto_field eth_fields
[] = {
14 { .id
= ETH_DST_ADDR
, .len
= 6, },
15 { .id
= ETH_SRC_ADDR
, .len
= 6, .offset
= 6 },
16 { .id
= ETH_PROTO_ID
, .len
= 2, .offset
= 12 },
19 static void eth_header_init(struct proto_hdr
*hdr
)
21 proto_header_fields_add(hdr
, eth_fields
, array_size(eth_fields
));
23 proto_field_set_default_dev_mac(hdr
, ETH_SRC_ADDR
);
26 static struct proto_hdr eth_hdr
= {
29 .header_init
= eth_header_init
,
32 static struct proto_field arp_fields
[] = {
33 { .id
= ARP_HTYPE
, .len
= 2 },
34 { .id
= ARP_PTYPE
, .len
= 2, .offset
= 2 },
35 { .id
= ARP_HLEN
, .len
= 1, .offset
= 4 },
36 { .id
= ARP_PLEN
, .len
= 1, .offset
= 5 },
37 { .id
= ARP_OPER
, .len
= 2, .offset
= 6 },
38 { .id
= ARP_SHA
, .len
= 6, .offset
= 8 },
39 { .id
= ARP_SPA
, .len
= 4, .offset
= 14 },
40 { .id
= ARP_THA
, .len
= 6, .offset
= 18 },
41 { .id
= ARP_TPA
, .len
= 4, .offset
= 24 },
44 static void arp_header_init(struct proto_hdr
*hdr
)
46 struct proto_hdr
*lower
;
48 proto_lower_default_add(PROTO_ETH
);
50 lower
= proto_current_header();
52 if (lower
->id
== PROTO_ETH
) {
53 uint8_t bcast
[6] = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff };
55 proto_field_set_default_bytes(lower
, ETH_DST_ADDR
, bcast
);
56 proto_field_set_default_be16(lower
, ETH_PROTO_ID
, ETH_P_ARP
);
59 proto_header_fields_add(hdr
, arp_fields
, array_size(arp_fields
));
61 /* Generate Announce request by default */
62 proto_field_set_default_be16(hdr
, ARP_HTYPE
, ARPHRD_ETHER
);
63 proto_field_set_default_be16(hdr
, ARP_PTYPE
, ETH_P_IP
);
64 proto_field_set_default_u8(hdr
, ARP_HLEN
, 6);
65 proto_field_set_default_u8(hdr
, ARP_PLEN
, 4);
66 proto_field_set_default_be16(hdr
, ARP_OPER
, ARPOP_REQUEST
);
67 proto_field_set_default_dev_mac(hdr
, ARP_SHA
);
68 proto_field_set_default_dev_ipv4(hdr
, ARP_SPA
);
69 proto_field_set_default_dev_ipv4(hdr
, ARP_TPA
);
72 static struct proto_hdr arp_hdr
= {
75 .header_init
= arp_header_init
,
78 void protos_l2_init(void)
80 proto_header_register(ð_hdr
);
81 proto_header_register(&arp_hdr
);