diff options
author | Vadim Kochan <vadim4j@gmail.com> | 2016-01-26 22:25:02 +0200 |
---|---|---|
committer | Tobias Klauser <tklauser@distanz.ch> | 2016-01-28 16:15:03 +0100 |
commit | 11a7670eb559580885e096216a494d2c96702645 (patch) | |
tree | a6079c3685719dcafcf26719eaf7782b3d9dd09c /trafgen_l2.c | |
parent | 2ab562f1a46ffbc459146420caa86e400fa1b9e2 (diff) |
trafgen: l2: Add Ethernet protocol header generation
Add trafgen_l2.c module for generating L2 related headers.
Add Ethernet header generating. By default source MAC address
is used from the specified output device.
Signed-off-by: Vadim Kochan <vadim4j@gmail.com>
Signed-off-by: Tobias Klauser <tklauser@distanz.ch>
Diffstat (limited to 'trafgen_l2.c')
-rw-r--r-- | trafgen_l2.c | 32 |
1 files changed, 32 insertions, 0 deletions
diff --git a/trafgen_l2.c b/trafgen_l2.c new file mode 100644 index 0000000..1082049 --- /dev/null +++ b/trafgen_l2.c @@ -0,0 +1,32 @@ +/* + * netsniff-ng - the packet sniffing beast + * Subject to the GPL, version 2. + */ + +#include "built_in.h" +#include "trafgen_l2.h" +#include "trafgen_proto.h" + +struct proto_field eth_fields[] = { + { .id = ETH_DST_ADDR, .len = 6, }, + { .id = ETH_SRC_ADDR, .len = 6, .offset = 6 }, + { .id = ETH_PROTO_ID, .len = 2, .offset = 12 }, +}; + +static void eth_header_init(struct proto_hdr *hdr) +{ + proto_header_fields_add(hdr, eth_fields, array_size(eth_fields)); + + proto_field_set_default_dev_mac(hdr, ETH_SRC_ADDR); +} + +static struct proto_hdr eth_hdr = { + .id = PROTO_ETH, + .layer = PROTO_L2, + .header_init = eth_header_init, +}; + +void protos_l2_init(void) +{ + proto_header_register(ð_hdr); +} |