proto_80211_mac_hdr.c: partly implement "measurement request" element
[netsniff-ng.git] / src / bpf_symtab.c
blob933574d0ab33c45082a28b4bf9b31c58d2b5cf67
1 /*
2 * netsniff-ng - the packet sniffing beast
3 * By Daniel Borkmann <daniel@netsniff-ng.org>
4 * Copyright 2012 Daniel Borkmann <dborkma@tik.ee.ethz.ch>,
5 * Swiss federal institute of technology (ETH Zurich)
6 * Subject to the GPL, version 2.
7 */
9 #include <stdio.h>
10 #include <stdlib.h>
11 #include <string.h>
13 #include "bpf_symtab.h"
14 #include "die.h"
15 #include "xmalloc.h"
17 struct sym_entry {
18 char *name;
19 int type, declared;
22 #define MAX_SYMBOLS 512
24 static struct sym_entry symbol_table[MAX_SYMBOLS];
25 static size_t symbol_used = 0;
27 int bpf_symtab_find(const char *name)
29 int i;
31 for (i = 0; i < symbol_used; ++i)
32 if (!strcmp(symbol_table[i].name, name))
33 return i;
34 return -1;
37 void bpf_symtab_cleanup(void)
39 int i;
41 for (i = 0; i < symbol_used; ++i)
42 xfree(symbol_table[i].name);
44 symbol_used = 0;
47 int bpf_symtab_insert(const char *name, int type)
49 if (symbol_used >= MAX_SYMBOLS)
50 panic("Symbol table overflow, %zu entries!\n", symbol_used);
52 symbol_table[symbol_used].name = xstrdup(name);
53 symbol_table[symbol_used].type = type;
54 symbol_table[symbol_used].declared = 0;
56 return symbol_used++;
59 int bpf_symtab_type(int idx)
61 if (idx < 0 || idx >= symbol_used)
62 return -1;
64 return symbol_table[idx].type;
67 void bpf_symtab_declare(int idx)
69 if (idx < 0 || idx >= symbol_used)
70 return;
72 symbol_table[idx].declared = 1;
75 int bpf_symtab_declared(int idx)
77 if (idx < 0 || idx >= symbol_used)
78 return -1;
80 return symbol_table[idx].declared;
83 const char *bpf_symtab_name(int idx)
85 if (idx < 0 || idx >= symbol_used)
86 return NULL;
88 return symbol_table[idx].name;