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 | 5447d6c44b63354b11ceb648e199282dbb65f623 (patch) | |
tree | 762b9ea294024b359d37d7cd6b649158666591cc /package/wprobe/src/filter/pfc.c | |
parent | 069dbf6fd412aa01e384c8ca5fd2b51306a51412 (diff) | |
download | upstream-5447d6c44b63354b11ceb648e199282dbb65f623.tar.gz upstream-5447d6c44b63354b11ceb648e199282dbb65f623.tar.bz2 upstream-5447d6c44b63354b11ceb648e199282dbb65f623.zip |
upgrade to the new version of wprobe - includes reconfigurable layer 2 statistics, remote access, more configuration options and many bugfixes
SVN-Revision: 16719
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; +} |