summaryrefslogtreecommitdiffstats
path: root/src/fastd.h
diff options
context:
space:
mode:
authorMatthias Schiffer <mschiffer@universe-factory.net>2013-05-19 19:13:33 +0200
committerMatthias Schiffer <mschiffer@universe-factory.net>2013-05-19 19:13:33 +0200
commit31078a8449aadd531dda746da1339098db13e7c0 (patch)
tree92f9cb5ba0a3fc4934e570ee878ff98eae49c2d0 /src/fastd.h
parent933609fc6e464e1259928ff587464841c4e9b953 (diff)
downloadfastd-31078a8449aadd531dda746da1339098db13e7c0.tar
fastd-31078a8449aadd531dda746da1339098db13e7c0.zip
Simplify handling of received packets
Diffstat (limited to 'src/fastd.h')
-rw-r--r--src/fastd.h8
1 files changed, 8 insertions, 0 deletions
diff --git a/src/fastd.h b/src/fastd.h
index e16cbb8..2a4e9ac 100644
--- a/src/fastd.h
+++ b/src/fastd.h
@@ -378,6 +378,8 @@ static inline size_t alignto(size_t l, size_t a) {
return ((l+a-1)/a)*a;
}
+#define FASTD_BUFFER_NULL ((fastd_buffer_t){})
+
static inline fastd_buffer_t fastd_buffer_alloc(const fastd_context_t *ctx, size_t len, size_t head_space, size_t tail_space) {
size_t base_len = head_space+len+tail_space;
void *ptr;
@@ -387,6 +389,12 @@ static inline fastd_buffer_t fastd_buffer_alloc(const fastd_context_t *ctx, size
return (fastd_buffer_t){ .base = ptr, .base_len = base_len, .data = ptr+head_space, .len = len };
}
+static inline fastd_buffer_t fastd_buffer_dup(const fastd_context_t *ctx, fastd_buffer_t buffer, size_t head_space, size_t tail_space) {
+ fastd_buffer_t new_buffer = fastd_buffer_alloc(ctx, buffer.len, head_space, tail_space);
+ memcpy(new_buffer.data, buffer.data, buffer.len);
+ return new_buffer;
+}
+
static inline void fastd_buffer_free(fastd_buffer_t buffer) {
free(buffer.base);
}