Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I inject raw packets onto my network

In testing certain network device driver receive features, I need to send special packets on the wire. I know I need to open a raw socket and push the bytes out. Is there some well-known example (C, perl, whatever) code already available for playing at this level?

(added later) I would prefer non-platform-specific answers, they'll be the most useful for everyone.

like image 536
Shannon Nelson Avatar asked Feb 28 '23 17:02

Shannon Nelson


2 Answers

Look at the documentation for packet. Basically, you create a socket with SOCK_RAW or SOCK_DGRAM, then write to the socket using normal socket i/o. However, the data you send will be put directly on the line, rather than automatically getting the headers that are necessary for most network interop.

like image 141
JSBձոգչ Avatar answered Mar 05 '23 17:03

JSBձոգչ


http://www.codeproject.com/KB/IP/sendrawpacket.aspx

There's already an existing project that may be able to help you with this.

like image 41
Robert Greiner Avatar answered Mar 05 '23 15:03

Robert Greiner