Send/Recv of ethernet packets useing raw sockets

Send/Recv of ethernet packets useing raw sockets

Post by Someone Insignifican » Sun, 29 Jul 2001 21:34:41



Greetings Everyone !

Im looking for a tutorial, or explanations on useing raw sockets to
send and receive raw ethernet packets on linux.

Ive found some example of the basics, but there are caveats to the
process that dont seem to be documented. For example, how to
get the interface index given the ethernet device name, whether the
socket needs to be in blocking/non-blocking mode, can I simply
stuff a socket buffer on an interfaces outgoing queue without useing
the socket functions, relevant ioctls, etc, etc.

If anyone has any information or knows where I can find a tutorial
on this, please let me know.

Thanks !

Mike

p.s. I need to send raw ethernet frames for a new protocol im
developing. IP/UDP/TCP packets just doesnt cut it in this case.

 
 
 

Send/Recv of ethernet packets useing raw sockets

Post by Morris Dove » Sun, 29 Jul 2001 22:42:21



> Im looking for a tutorial, or explanations on useing raw sockets to
> send and receive raw ethernet packets on linux.

> Ive found some example of the basics, but there are caveats to the
> process that dont seem to be documented. For example, how to
> get the interface index given the ethernet device name, whether the
> socket needs to be in blocking/non-blocking mode, can I simply
> stuff a socket buffer on an interfaces outgoing queue without useing
> the socket functions, relevant ioctls, etc, etc.

> If anyone has any information or knows where I can find a tutorial
> on this, please let me know.

> p.s. I need to send raw ethernet frames for a new protocol im
> developing. IP/UDP/TCP packets just doesnt cut it in this case.

Mike...

Have you tried just opening the device (/dev/eth0 or whatever) and
talking to it? You'll probably need to use ioctls to configure its
behavior and you'll probably still need to carefully prepare standard
packet headers.

NIC manufacturers don't, in general, seem very helpful in providing
information about their products.

You might gain useful information from reading the ethernet driver and
header file source code. I found "FAST Ethernet" by Liam B. Quinn and
Richard G. Russell to be an easy and worthwhile read. The IEEE ethernet
standard would be nice to have at hand (but probably would not be more
helpful than the Quinn/Russell book -- and it'd be much more costly to
buy.)

HTH
--
Morris Dovey
West Des Moines, Iowa USA
Available for embedded C contract work

 
 
 

Send/Recv of ethernet packets useing raw sockets

Post by Chris Friese » Sun, 29 Jul 2001 23:47:51



> Greetings Everyone !

> Im looking for a tutorial, or explanations on useing raw sockets to
> send and receive raw ethernet packets on linux.

The easiest is to simply do some searches on google groups.  There are code
samples archived.

The process is fairly straightforward:

open a packet socket
use an ioctl call to get the interface index
fill in the address struct (sockaddr_ll, I think)
make your packet
send it using sendto()

 
 
 

Send/Recv of ethernet packets useing raw sockets

Post by Grant Edwar » Tue, 31 Jul 2001 01:52:32




>> Im looking for a tutorial, or explanations on useing raw
>> sockets to send and receive raw ethernet packets on linux.

>Have you tried just opening the device (/dev/eth0 or whatever)
>and talking to it?

Eh?  You've got a /dev/eth0 on your system?

Wierd.

Quote:>You'll probably need to use ioctls to configure its behavior
>and you'll probably still need to carefully prepare standard
>packet headers.

Probably so -- if there was a /dev/ethX

Quote:>NIC manufacturers don't, in general, seem very helpful in
>providing information about their products.

Not needed.

$ man packet

--
Grant Edwards                   grante             Yow!  When you get your
                                  at               PH.D. will you get able to
                               visi.com            work at BURGER KING?

 
 
 

Send/Recv of ethernet packets useing raw sockets

Post by Morris Dove » Tue, 31 Jul 2001 22:44:24



> Probably so -- if there was a /dev/ethX

Absolutely correct. Not sure what I was thinking at the time.
--
Morris Dovey
 
 
 

Send/Recv of ethernet packets useing raw sockets

Post by Grant Edwar » Wed, 01 Aug 2001 00:10:56




>> Probably so -- if there was a /dev/ethX

>Absolutely correct. Not sure what I was thinking at the time.

Well, it would be the obvious and most Unixesque way to do
it.  :)

--
Grant Edwards                   grante             Yow!  I want to read my new
                                  at               poem about pork brains and
                               visi.com            outer space...

 
 
 

1. Best approach to send/recv raw ethernet

Hi,
I need to send and receive raw ethernet and am trying to figure out the
best approach. The possibilities I've been able to identify so far are
libpcap, PF_PACKET with SOCK_DGRAM/SOCK_RAW, PF_INET with SOCK_RAW, and
PF_INET with SOCK_PACKET.

libpcap doesn't seem to have the ability to send, so unless someone points
out that I misunderstood it's not an option.

PF_PACKET looks promising and indeed I have coded up a prototype that uses
it to send and receive packets. I'm having difficulty receiving packets
after binding the socket, and in my google searches I have come across
some disheartening messages indicating that PF_PACKET is quite slow.
Time is a premium in this application. I need to be able to receive a
packet and send a response in about 50-100 microseconds.

PF_INET with SOCK_RAW looks like it might work but if it did it would
almost certainly be a hack, because my application and the data going over
the wire will have absolutely nothing to do with IP - it's just raw 802.3.

PF_INET with SOCK_PACKET is strongly deprecated in favor of PF_PACKET, but
if it's faster I'm willing to use it. Again, it may be a hack.

I'd appreciate any advice and comments about which road to take.

2. Encrypting again an already encrypted file increase security ?

3. Sending Arp reply packets using packet-sockets on linux

4. encryption and decryption in Unix

5. Socket using send/recv

6. HELP!: Solaris 2.3/OW 3.3: Mailtool doesn't work!

7. recv / send in mutiple client socket programming (using multi-threads)

8. DIP configuration help needed

9. Sending multicast packet on a raw socket

10. sample code that sends raw Ethernet packets?

11. Sending raw ethernet packets

12. How to send raw Ethernet packets?

13. Sending Raw Ethernet Packets