views:

129

answers:

4

Hi all, 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... :)

+1  A: 

This guide has a great overview of using sockets for network programming, i'm sure you can find some code examples in there.

James
+1 bgnet guide's are my favorites.
karlphillip
its one of the main sources i got started with =D
James
i think OP wants to craft the headers as well as the data.
tholomew
A: 

http://packetfactory.openwall.net/projects/libnet

(If anyone knows why packetfactory.net has gone offline, do shed some light).

tholomew
A: 

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.

bdk
Thanks for the reply. I am looking for that low level packet creating C codes. How do i make use of libpcap?? am using ubuntu 10.
M.S Balagopal
A: 

I'm not sure what exactly you are looking for, but since you mentioned "frames", a pointer to raw(7) socket interface might be in order (this is for Linux, BTW).

Edit:

Well, why not look at the source then?

Nikolai N Fetissov
Hmm.. to make it simpler, let me say.. i just want to ping another machine in same network. But i want to create that icmp packet using C.
M.S Balagopal