Add proto_field_xxx functions to set/get value via specified proto_field only.
It is good to have such API in case if application needs to set/get value for some custom proto_field instance. Signed-off-by: Vadim Kochan <vadi...@gmail.com> --- trafgen_proto.c | 46 ++++++++++++++++++++++++++++++++++++++++++++++ trafgen_proto.h | 10 ++++++++++ 2 files changed, 56 insertions(+) diff --git a/trafgen_proto.c b/trafgen_proto.c index f862592..e2b80d4 100644 --- a/trafgen_proto.c +++ b/trafgen_proto.c @@ -431,6 +431,52 @@ void proto_hdr_field_set_default_dev_ipv6(struct proto_hdr *hdr, uint32_t fid) __proto_hdr_field_set_dev_ipv6(hdr, fid, true); } +void proto_field_set_u8(struct proto_field *field, uint8_t val) +{ + __proto_field_set_bytes(field, &val, false, false); +} + +uint8_t proto_field_get_u8(struct proto_field *field) +{ + uint8_t val = *__proto_field_get_bytes(field); + + return field_unmask_and_unshift(field, val); +} + +void proto_field_set_u16(struct proto_field *field, uint16_t val) +{ + __proto_field_set_bytes(field, (uint8_t *)&val, false, false); +} + +uint16_t proto_field_get_u16(struct proto_field *field) +{ + uint16_t val = *(uint16_t *)__proto_field_get_bytes(field); + + return field_unmask_and_unshift(field, be16_to_cpu(val)); +} + +void proto_field_set_u32(struct proto_field *field, uint32_t val) +{ + __proto_field_set_bytes(field, (uint8_t *)&val, false, false); +} + +uint32_t proto_field_get_u32(struct proto_field *field) +{ + uint32_t val = *(uint32_t *)__proto_field_get_bytes(field); + + return field_unmask_and_unshift(field, be32_to_cpu(val)); +} + +void proto_field_set_be16(struct proto_field *field, uint16_t val) +{ + __proto_field_set_bytes(field, (uint8_t *)&val, false, true); +} + +void proto_field_set_be32(struct proto_field *field, uint32_t val) +{ + __proto_field_set_bytes(field, (uint8_t *)&val, false, true); +} + void protos_init(const char *dev) { ctx.dev = dev; diff --git a/trafgen_proto.h b/trafgen_proto.h index 927fcb1..d4427e6 100644 --- a/trafgen_proto.h +++ b/trafgen_proto.h @@ -147,4 +147,14 @@ extern void proto_hdr_field_func_add(struct proto_hdr *hdr, uint32_t fid, extern struct proto_field *proto_hdr_field_by_id(struct proto_hdr *hdr, uint32_t fid); + +extern void proto_field_set_u8(struct proto_field *field, uint8_t val); +extern uint8_t proto_field_get_u8(struct proto_field *field); +extern void proto_field_set_u16(struct proto_field *field, uint16_t val); +extern uint16_t proto_field_get_u16(struct proto_field *field); +extern void proto_field_set_u32(struct proto_field *field, uint32_t val); +extern uint32_t proto_field_get_u32(struct proto_field *field); +extern void proto_field_set_be16(struct proto_field *field, uint16_t val); +extern void proto_field_set_be32(struct proto_field *field, uint32_t val); + #endif /* TRAFGEN_PROTO_H */ -- 2.10.2 -- You received this message because you are subscribed to the Google Groups "netsniff-ng" group. To unsubscribe from this group and stop receiving emails from it, send an email to netsniff-ng+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.