Project Home
Project Home
Wiki
Wiki
Discussion Forums
Discussions
Project Information
Project Info
Forum Topic - How to set filters for capturing ethernet raw packets in BPF?: (6 Items)
   
How to set filters for capturing ethernet raw packets in BPF?  
Hi,

I want to send and receive ethernet raw packets using BPF interface. 

The ethernet raw packet frame = destination hardware (MAC) address [6 bytes]+	source hardware (MAC) address [6 bytes]  +
 layer-3 protocol type [2 bytes]  + payload [46 - 1500 bytes] +FCS [4 bytes].

While receiveing, how to set filters for capturing ethernet raw packets only in BPF interface? 

Thanks, 
BVB

RE: How to set filters for capturing ethernet raw packets in BPF?  
You can take a look at our filtering wiki page here:

http://community.qnx.com/sf/wiki/do/viewPage/projects.networking/wiki/Fi
ltering_wiki_page

for more information.  It points you to another document that covers BPF
workings.  Note the proviso on using "ioctl_socket" instead of "ioctl"
in your code.

	Robert.

-----Original Message-----
From: Beniz VB [mailto:community-noreply@qnx.com] 
Sent: Monday, January 12, 2009 3:45 AM
To: ionetmig-networking
Subject: How to set filters for capturing ethernet raw packets in BPF?


Hi,

I want to send and receive ethernet raw packets using BPF interface. 

The ethernet raw packet frame = destination hardware (MAC) address [6
bytes]+	source hardware (MAC) address [6 bytes]  + layer-3 protocol type
[2 bytes]  + payload [46 - 1500 bytes] +FCS [4 bytes].

While receiveing, how to set filters for capturing ethernet raw packets
only in BPF interface? 

Thanks,
BVB



_______________________________________________
io-net migration
http://community.qnx.com/sf/go/post19823
Re: RE: How to set filters for capturing ethernet raw packets in BPF?  
Hi Robert,

            Thanks for your reply. I have gone through the links that you have sent to me. But I couldn't implement the 
filter in my program.  I have a doubt whether I should set the filter in assembly level. Can you please send me one 
example C code which can filter raw ethernet messages from the network (in QNX 6.4).

           In my sender program I'll send an ethernet frame (destination hardware (MAC) address [6bytes] + source 
hardware (MAC) address [6 bytes]  + etherl type [2 bytes]  + payload [46 - 1500 bytes] +FCS [4 bytes].)

          In my ethernet frame, I'll put ethertype as 0x9999, inorder to identify it as my frame while receiving. So in 
BPF receiver, I should capture frames which contain ethertype = 0x9999 only. Can u please tell me how to write a bpf 
filter program in C for capturing my frame (QNX 6.4).


Thanks & Regads,
Beniz V B
RE: RE: How to set filters for capturing ethernet raw packets in BPF?  
Hi:
	I'm confused about the comment "set the filter in assembly
language" (?) The BPF header file defines a number of C macros that are
used to set up the BPF structures to do the filtering that you require.
In your other posting, you indicate that you can send and receive the
ethernet packets but I guess that the problem is that you don't have the
filtering set up?

If you take a look here
http://www.gsp.com/cgi-bin/man.cgi?section=4&topic=bpf 
you will see some examples at the end, one of which is how to filter to
accept reverse ARP requests.  You can see how the first thing it does is
filter on the Reverse ARP filter type and this is followed by a filter
on the request field.  You should just be able to remove the check for
the arp request, leaving only the ethertype filter in there.

	Robert.



-----Original Message-----
From: Beniz VB [mailto:community-noreply@qnx.com] 
Sent: Wednesday, February 04, 2009 2:40 AM
To: ionetmig-networking
Subject: Re: RE: How to set filters for capturing ethernet raw packets
in BPF?


Hi Robert,

            Thanks for your reply. I have gone through the links that
you have sent to me. But I couldn't implement the filter in my program.
I have a doubt whether I should set the filter in assembly level. Can
you please send me one example C code which can filter raw ethernet
messages from the network (in QNX 6.4).

           In my sender program I'll send an ethernet frame (destination
hardware (MAC) address [6bytes] + source hardware (MAC) address [6
bytes]  + etherl type [2 bytes]  + payload [46 - 1500 bytes] +FCS [4
bytes].)

          In my ethernet frame, I'll put ethertype as 0x9999, inorder to
identify it as my frame while receiving. So in BPF receiver, I should
capture frames which contain ethertype = 0x9999 only. Can u please tell
me how to write a bpf filter program in C for capturing my frame (QNX
6.4).


Thanks & Regads,
Beniz V B

_______________________________________________
io-net migration
http://community.qnx.com/sf/go/post21380
Re: RE: RE: How to set filters for capturing ethernet raw packets in BPF?  
Hi Robert,

         Thanks for your help. I have gone through the example for bpf filter. I tried to implement the filter in my 
program. Now I have problem in ioctl(iHdl, BIOCSETF, &my_bpf_program). It says invalid argument to ioctl.

        I'm attaching my code. Pls have a look at it and tell me what went wrong in my code. 

Thanks,
Beniz V B
Attachment: Text bpfreceiver.txt 2.79 KB
RE: RE: RE: How to set filters for capturing ethernet raw packets in BPF?  
Hi Beniz:

	Two things...

Firstly, "ioctl" should be replaced with "ioctl_socket" (You can easily
do this by adding a "#define ioctl ioctl_socket" at the start of your
source file) 

Secondly,

my_bpf_program.bpf_len = sizeof(insns) is incorrect.

This should be the number of instructions (4) rather than the size of
the array (32).  This compiled and ran for me.

	Robert.

-----Original Message-----
From: Beniz VB [mailto:community-noreply@qnx.com] 
Sent: Thursday, February 05, 2009 7:32 AM
To: ionetmig-networking
Subject: Re: RE: RE: How to set filters for capturing ethernet raw
packets in BPF?

Hi Robert,

         Thanks for your help. I have gone through the example for bpf
filter. I tried to implement the filter in my program. Now I have
problem in ioctl(iHdl, BIOCSETF, &my_bpf_program). It says invalid
argument to ioctl.

        I'm attaching my code. Pls have a look at it and tell me what
went wrong in my code. 

Thanks,
Beniz V B

_______________________________________________
io-net migration
http://community.qnx.com/sf/go/post21466