BPF Devices


I am using QNX 6.3.2. In /dev/socket/ there is one bpf device with name bpf.
I did a sample program to open bpf device and attached with en0. It is successful. Now I need to get data from multiple interfaces ,say en0,en1 …and so. Can I attache the same bpf to multiple interfaces??
For example:
if ( 0 > ( fd = open( “/dev/bpf0”, O_RDWR ) ) )
err( 1, “open” );

Attaching to “en0”, bound_if has “en0”
if( ioctl( fd, BIOCSETIF, &bound_if ) > 0 )

Now can I attach same ‘fd’ to en1?? If I can,do it gets detach from en0?
Please provide me some idea.Thanks in advance.

You may know more about this than I do, but I can’t tell from your post whether that is true or whether you are lost.

I would never open the /dev/bpf device and attach it they way you have.
Instead I would configure en0 with ifconfig.
As far as “receiving data from multiple interfaces”, I would use the socket interface to create a server program that can receive connections on any interface. The connections can then be either TCP or UDP depending on your needs.

Hi maschoen,
Thanks for your reply.
Actual motive behind using BPF is to receive all kinds of packets,not only TCP/IP. We need to receive raw ethernet packets on my interface. For this the only way to achive in QNX 6.3.2 is to use BPF. That is the reason I am opening a bpf device and attaching to interface.
So could you please let me know,whether I can attach a file descriptor to multiple interfaces?

Well I understand that you want to get all packets, raw and otherwise.

I’m not that familiar with the QNX 6 raw packet interface. But something doesn’t sound right about what you are doing. As I understand it io-pkt(-v4) is the process that you are getting information from. Various types of drivers can attach to this process at various points in the stack, on the top or bottom. NIC drivers are at one end, filters and protocols in the middle.

What doesn’t sound right is that you are attaching to an “interface”. My understanding of an interface is that it is the IP protocol’s virtualized notion of a hardware NIC. So you configure an interface with an IP address. On a Unix system this might be the way to do things, but in QNX I would suspect you want to create a component that sits on the stack above the NIC drivers and watch the packets go by.

Now I need to get data from multiple interfaces ,say en0,en1 …and so. Can I attache the same bpf to multiple interfaces??

Not sure about 6.3.2 (io-net) but with io-pkt-v4… here is some working code to transmit and receive a frame with arbitrary id between locally connected macs. See readme.txt.