diff options
author | Alexander Wirt <formorer@debian.org> | 2013-05-18 21:48:14 +0200 |
---|---|---|
committer | Alexander Wirt <formorer@debian.org> | 2013-05-18 21:48:14 +0200 |
commit | 484ed0908b6415ea847a4ba42dcb7dbebe81831d (patch) | |
tree | 671e8b11fae025390feb87a678689ba8f4f4acee /src/stack.c | |
parent | 095df096593fa957706bff1a552b072ae079d7fb (diff) | |
parent | 6b61aefbf3de71852386f5f26d60c10ef62407d3 (diff) | |
download | conntrack-tools-484ed0908b6415ea847a4ba42dcb7dbebe81831d.tar.gz conntrack-tools-484ed0908b6415ea847a4ba42dcb7dbebe81831d.zip |
Merge tag 'upstream/1.4.1'
Upstream version 1.4.1
Diffstat (limited to 'src/stack.c')
-rw-r--r-- | src/stack.c | 56 |
1 files changed, 56 insertions, 0 deletions
diff --git a/src/stack.c b/src/stack.c new file mode 100644 index 0000000..104b7ba --- /dev/null +++ b/src/stack.c @@ -0,0 +1,56 @@ +/* + * (C) 2005-2012 by Pablo Neira Ayuso <pablo@netfilter.org> + * + * This program is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + */ + +#include <stdio.h> +#include <stdlib.h> +#include <string.h> +#include <errno.h> + +#include "stack.h" + +struct stack_item * +stack_item_alloc(int type, size_t data_len) +{ + struct stack_item *e; + + e = calloc(1, sizeof(struct stack_item) + data_len); + if (e == NULL) + return NULL; + + e->data_len = data_len; + e->type = type; + + return e; +} + +void stack_item_free(struct stack_item *e) +{ + free(e); +} + +void stack_item_push(struct stack *s, struct stack_item *e) +{ + list_add(&e->head, &s->list); +} + +struct stack_item *stack_item_pop(struct stack *s, int type) +{ + struct stack_item *cur, *tmp, *found = NULL; + + list_for_each_entry_safe(cur, tmp, &s->list, head) { + if (cur->type != type && type != -1) + continue; + + list_del(&cur->head); + found = cur; + break; + } + + return found; +} |