Here is a very simple code example for two programs that talk on a UDP socket: one list of codes creates and sends a packet, and the other receives it.
http://www.abc.se/~m6695/udp.html
Note that these network functions are not part of the C language itself, which does not support network support, but they are standard (POSIX, I think) and are available in similar forms for most modern C implementations.
Please note that with standard functions you specify only the packet payload, address, port and some flags, you cannot control the exact contents of the Ethernet frame, IP headers, etc. that are created for you by the operating system. If you need this level of control over a low-level package, I believe that you can use libpcap / winpcap for this purpose, or some operating systems may have raw sockets that allow you to do this.
bdk
source share