diff options
author | Felix Fietkau <nbd@openwrt.org> | 2009-07-06 19:05:24 +0000 |
---|---|---|
committer | Felix Fietkau <nbd@openwrt.org> | 2009-07-06 19:05:24 +0000 |
commit | 1dfb0952090b3b355e088afc4d54263f46d5848f (patch) | |
tree | bc41c65f68f683771e511a61ca9833e24d07fdf2 /package/wprobe/src/filter/pfc.c | |
parent | 6fbd31d2386a669270a9588c549f935e9d1185c7 (diff) | |
download | upstream-1dfb0952090b3b355e088afc4d54263f46d5848f.tar.gz upstream-1dfb0952090b3b355e088afc4d54263f46d5848f.tar.bz2 upstream-1dfb0952090b3b355e088afc4d54263f46d5848f.zip |
upgrade to the new version of wprobe - includes reconfigurable layer 2 statistics, remote access, more configuration options and many bugfixes
git-svn-id: svn://svn.openwrt.org/openwrt/trunk@16719 3c298f89-4303-0410-b956-a3cf2f4a3e73
Diffstat (limited to 'package/wprobe/src/filter/pfc.c')
-rw-r--r-- | package/wprobe/src/filter/pfc.c | 58 |
1 files changed, 58 insertions, 0 deletions
diff --git a/package/wprobe/src/filter/pfc.c b/package/wprobe/src/filter/pfc.c new file mode 100644 index 0000000000..76fb1412aa --- /dev/null +++ b/package/wprobe/src/filter/pfc.c @@ -0,0 +1,58 @@ +#include <arpa/inet.h> +#include <sys/types.h> +#include <sys/time.h> +#include <string.h> +#include <stdint.h> +#include <stdlib.h> + +#include <pcap.h> +#include <pcap-bpf.h> + +struct wprobe_filter_hdr { + char name[32]; + uint32_t len; +} hdr; + +int main (int argc, char ** argv) +{ + struct bpf_program filter; + pcap_t *pc; + int i; + + if (argc != 3) + { + fprintf(stderr, "Usage: %s <name> <expression>\n", argv[0]); + return 1; + } + + pc = pcap_open_dead(DLT_IEEE802_11_RADIO, 256); + if (pcap_compile(pc, &filter, argv[2], 1, 0) != 0) + { + pcap_perror(pc, argv[0]); + exit(1); + } + + /* fix up for linux */ + for (i = 0; i < filter.bf_len; i++) { + struct bpf_insn *bi = &filter.bf_insns[i]; + switch(BPF_CLASS(bi->code)) { + case BPF_RET: + if (BPF_MODE(bi->code) == BPF_K) { + if (bi->k != 0) + bi->k = 65535; + } + break; + } + bi->code = ntohs(bi->code); + bi->k = ntohl(bi->k); + } + + memset(&hdr, 0, sizeof(hdr)); + strncpy(hdr.name, argv[1], sizeof(hdr.name)); + hdr.len = htonl(filter.bf_len); + fwrite(&hdr, sizeof(hdr), 1, stdout); + fwrite(filter.bf_insns, 8, filter.bf_len, stdout); + fflush(stdout); + + return 0; +} |