summaryrefslogtreecommitdiff
path: root/pkt.h
diff options
context:
space:
mode:
Diffstat (limited to 'pkt.h')
-rw-r--r--pkt.h15
1 files changed, 14 insertions, 1 deletions
diff --git a/pkt.h b/pkt.h
index bb2b717..70591b5 100644
--- a/pkt.h
+++ b/pkt.h
@@ -1,7 +1,7 @@
/*
* Packet buffer structure and utilities.
*
- * Copyright (C) 2015 Tobias Klauser <tklauser@distanz.ch>
+ * Copyright (C) 2015-2017 Tobias Klauser <tklauser@distanz.ch>
*
* Based on pkt_buff.h from the netsniff-ng toolkit which is:
*
@@ -108,4 +108,17 @@ DEFINE_PKT_PUT(8)
DEFINE_PKT_PUT(16)
DEFINE_PKT_PUT(32)
+/* extract values from struct pkt in an alignment-safe way */
+#define DEFINE_PKT_PUT_EXTRACT(__bitwidth) \
+static inline uint##__bitwidth##_t pkt_put_extract_u##__bitwidth(struct pkt *p) \
+{ \
+ uint##__bitwidth##_t val; \
+ memcpy(&val, pkt_put(p, sizeof(val)), sizeof(val)); \
+ return val; \
+}
+
+DEFINE_PKT_PUT_EXTRACT(8)
+DEFINE_PKT_PUT_EXTRACT(16)
+DEFINE_PKT_PUT_EXTRACT(32)
+
#endif /* PKT_H */