Project Home
Project Home
Wiki
Wiki
Discussion Forums
Discussions
Project Information
Project Info
Forum Topic - Send packet with BPF: (9 Items)
   
Send packet with BPF  
Hey

I'm wondering how to send an packet with BPF.

Reading packet i send it working perfectly but send a packet is not working yet.

The device is opened with

if ((bpf = open(bpf_dev, O_RDWR)) < 0) {
	      perror("open");
}

I have tried to write to the file with the function write but cant got it to work. I think the problem cant be that i do
 not activate an send flag or something similar to driver.

Another way i have tryed is to send packet with the sendto function. It look likes

		  if (sendto(s, &dgram, 276, 0, (struct sockaddr *)&daddr,
			     sizeof(daddr)) < 0) {
		    perror("sendto");
		  }

 
Re: Send packet with BPF  
On Fri, Jan 09, 2009 at 08:32:30AM -0500, Lasse Skov wrote:
> Hey
> 
> I'm wondering how to send an packet with BPF.
> 
> Reading packet i send it working perfectly but send a packet is not working yet.
> 
> The device is opened with
> 
> if ((bpf = open(bpf_dev, O_RDWR)) < 0) {
> 	      perror("open");
> }
> 
> I have tried to write to the file with the function write but cant got it to work. I think the problem cant be that i 
do not activate an send flag or something similar to driver.
> 
> Another way i have tryed is to send packet with the sendto function. It look likes
> 
> 		  if (sendto(s, &dgram, 276, 0, (struct sockaddr *)&daddr,
> 			     sizeof(daddr)) < 0) {
> 		    perror("sendto");
> 		  }

Can you post a complete test case?

Thanks,

-seanb
Re: Send packet with BPF  
Yes here is my example code

-lskov
Attachment: Text PacketFilterWrite.c 5.12 KB
RE: Send packet with BPF  
Can you try replacing "ioctl" with "ioctl_socket" instead?  Any of the
ioctl calls which have imbedded pointers need to handled specially.

	Robert.

-----Original Message-----
From: Lasse Skov [mailto:community-noreply@qnx.com] 
Sent: Saturday, January 10, 2009 10:17 AM
To: general-networking
Subject: Re: Send packet with BPF

Yes here is my example code

-lskov

_______________________________________________
General
http://community.qnx.com/sf/go/post19807
Re: RE: Send packet with BPF  
Just to be sure would it be possible to fetch the packet with tcpdump -iwm0 -XXX and se the packet, send with BPF on the
 device.

I have tryed with at wireshak direct connected to the net card but it do not sniff any packets. An neither do tcpdump.

What is the normal way to do when send packet with BPF?

I forgot to write that I have tried to use the functions below instead of sendto function. And with the same code.

write(s, &dgram, sizeof(dgram));
send(s, dgram, sizeof(dgram), MSG_OOB); 
RE: Send packet with BPF  
I should be a bit clearer.  In your original code (not the code example
using "sendto"), replace ioctl with ioctl_socket.  I haven't had a
chance to try it yet, but maybe this example will help:

http://canmore.annwfn.net/freebsd/bpf.html

	Robert.

-----Original Message-----
From: Lasse Skov [mailto:community-noreply@qnx.com] 
Sent: Saturday, January 10, 2009 10:17 AM
To: general-networking
Subject: Re: Send packet with BPF

Yes here is my example code

-lskov

_______________________________________________
General
http://community.qnx.com/sf/go/post19807
Re: Send packet with BPF  
On Sat, Jan 10, 2009 at 10:17:11AM -0500, Lasse Skov wrote:
> Yes here is my example code
> 
> -lskov

You're mixing approaches in that code.  Either use socket
with IP_HDRINCL or use the bpf descriptor.  The bpf method
wants the ethernet header in the buffer.  Attached is
your code slightly modified.  When compiled as is you can
see the packets via tcpdump sent out with the IP_HDRINCL
method.  When compiled with USEBPF you can see packets
like the following where 00:15:c5:a8:bd:7e is my link
level addr but 45:1b:14:01:01:00 is taken from your
buffer (you didn't include the ethernet header).

-seanb


/home/seanb >op tcpdump -ien0 -n -e
tcpdump: verbose output suppressed, use -v or -vv for full protocol decode
listening on en0, link-type EN10MB (Ethernet), capture size 96 bytes
13:50:55.746859 00:15:c5:a8:bd:7e > 45:1b:14:01:01:00, ethertype Unknown (0x0a14), length 276:
        0x0000:  0383 0a14 0382 00ff 0009 0100 1b1b 1b1b  ................
        0x0010:  1b1b 1b1b 1b1b 1b1b 1b1b 1b1b 1b1b 1b1b  ................
        0x0020:  1b1b 1b1b 1b1b 1b1b 1b1b 1b1b 1b1b 1b1b  ................
        0x0030:  1b1b 1b1b 1b1b 1b1b 1b1b 1b1b 1b1b 1b1b  ................
        0x0040:  1b1b 1b1b 1b1b 1b1b 1b1b 1b1b 1b1b 1b1b  ................
        0x0050:  1b1b                                     ..
13:50:55.746859 00:15:c5:a8:bd:7e > 45:1b:14:01:01:00, ethertype Unknown (0x0a14), length 276:
        0x0000:  0383 0a14 0382 4242 4242 4242 4242 4242  ......BBBBBBBBBB
        0x0010:  4242 4242 4242 4242 4242 4242 4242 4242  BBBBBBBBBBBBBBBB
        0x0020:  4242 4242 4242 4242 4242 4242 4242 4242  BBBBBBBBBBBBBBBB
        0x0030:  4242 4242 4242 4242 4242 4242 4242 4242  BBBBBBBBBBBBBBBB
        0x0040:  4242 4242 4242 4242 4242 4242 4242 4242  BBBBBBBBBBBBBBBB
        0x0050:  4242                                     BB
13:50:55.746859 00:15:c5:a8:bd:7e > 45:1b:14:01:02:00, ethertype Unknown (0x0a14), length 276:
        0x0000:  0383 0a14 0382 00ff 0007 0100 4242 4242  ............BBBB
        0x0010:  4242 4242 4242 4242 4242 4242 4242 4242  BBBBBBBBBBBBBBBB
        0x0020:  4242 4242 4242 4242 4242 4242 4242 4242  BBBBBBBBBBBBBBBB
        0x0030:  4242 4242 4242 4242 4242 4242 4242 4242  BBBBBBBBBBBBBBBB
        0x0040:  4242 4242 4242 4242 4242 4242 4242 4242  BBBBBBBBBBBBBBBB
        0x0050:  4242                                     BB
13:50:55.746859 00:15:c5:a8:bd:7e > 45:1b:14:01:02:00, ethertype Unknown (0x0a14), length 276:
        0x0000:  0383 0a14 0382 0000 0000 0000 0000 0000  ................
        0x0010:  0000 0000 0000 0000 0000 0000 0000 0000  ................
        0x0020:  0000 0000 0000 0000 0000 0000 0000 0000  ................
        0x0030:  0000 0000 0000 0000 0000 0000 0000 0000  ................
        0x0040:  0000 0000 0000 0000 0000 0000 0000 0000  ................
        0x0050:  0000                                     ..
Attachment: Text PacketFilterWrite.c 5.11 KB
Re: Send packet with BPF  
Thanks for your answer sean.

Now i think i understand the syntax in the BPF....

-LSkov
Re: Send packet with BPF  
Can you show me how to read a packet using a BPF.

Mohammad