Linux Socket Filter help/example code?

Eric Smith (eric@brouhaha.com)
19 Sep 1999 08:30:59 -0000


Does anyone have any examples of how to use the Linux Socket Filter? Yes,
I have read the documentation, and it doesn't really address my questions.
I'm trying to port a program that uses BPF, and it's somewhat frustrating,
because all the structs and fields have different names for no readily
apparent reason, and some of the structs don't seem to exist.

I started by doing this:

#ifndef __linux__
/* the original includes */
#include <net/pfilt.h>
#include <net/bpf.h>
#else
/* the linux includes */
#include <linux/types.h>
#undef __KERNEL__
#include <linux/filter.h>
/* Linux has different names for everything, sigh. */
#define bpf_insn sock_filter
#define bpf_program sock_fprog
#define bf_len len
#define bf_insns filter
#endif

Between that, and changing the way the filter is installed, that got me
part way there. But at the moment I'm stuck because the program has
references to a struct bpf_hdr that the filter is supposed to put at the
start of captured packets. I've looked through the system includes, and I
can't seem to find any equivalent, but surely it must be defined somewhere?

Thanks for any suggestions or advice!

Eric

-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.rutgers.edu
Please read the FAQ at http://www.tux.org/lkml/