Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

C code to generate and send a packet [closed]

I would like to know about the inbuilt library functions in C to build a complete packet(along with frame) and to send it over a network... Can any one upload the C code which does the above stuff... :)

like image 613
M.S Balagopal Avatar asked Aug 12 '10 13:08

M.S Balagopal


1 Answers

Here is a very simple code example for two programs that talk over a UDP socket: One code listing creates and sends a packet and one receives it.

http://www.abc.se/~m6695/udp.html

Note that these Network functions aren't part of the C Language itself which has no networking support, but they are standard (POSIX, I think) and available in similar forms on most modern C implementations.

Note that with the standard functions, you only specify the packet payload, address, port, and some flags, you don't get to control the exact contents of the ethernet frame, IP headers, etc, those are created for you by the Operating System. If you need that level of control over the low level packet, I believe you can use libpcap/winpcap for that purpose, or some operating systems may have 'raw' sockets which let you do this.

like image 116
bdk Avatar answered Oct 17 '22 15:10

bdk