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.
13 #include "bpf_symtab.h"
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
)
31 for (i
= 0; i
< symbol_used
; ++i
)
32 if (!strcmp(symbol_table
[i
].name
, name
))
37 void bpf_symtab_cleanup(void)
41 for (i
= 0; i
< symbol_used
; ++i
)
42 xfree(symbol_table
[i
].name
);
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;
59 int bpf_symtab_type(int idx
)
61 if (idx
< 0 || idx
>= symbol_used
)
64 return symbol_table
[idx
].type
;
67 void bpf_symtab_declare(int idx
)
69 if (idx
< 0 || idx
>= symbol_used
)
72 symbol_table
[idx
].declared
= 1;
75 int bpf_symtab_declared(int idx
)
77 if (idx
< 0 || idx
>= symbol_used
)
80 return symbol_table
[idx
].declared
;
83 const char *bpf_symtab_name(int idx
)
85 if (idx
< 0 || idx
>= symbol_used
)
88 return symbol_table
[idx
].name
;