Raw Sockets

Socket programming is a specialized area of network programming. While it offers the richest capability by its nature, it is little used due to the amount of intellectual overhead required to manage all the settings of the IP packet.

Visual Basic is one tool that makes socket programming easier with DLL library support, but yields an application that is limited to Windows and may require specific versions of windows.

C programming is another option, yielding a result that also ties to windows DLL libraries, but with an abstraction layer can in theory be written platform agnostic. Firstly the program which opens and closes a TCP socket.

The use of sockets allows complete control of ip address, port, packet size, et. al.

#include
#include

WSAStartup initializes the sockets processes.

UDP

A program can listen on UDP port 80, and use any data received on that port. UDP does not use a connection like TCP, once established, it never closes.

#include
#include

for printf main() {
WSADATA ws;
WSAStartup(0x0101,&ws);
SOCKET udp_socket;
struct sockaddr_in peer;
int peerlen;
char recvbuffer[20];
int retval;
peer.sin_family = AF_INET;
peer.sin_port = htons(80);
peer.sin_addr.s_addr = htonl(INADDR_ANY);
udp_socket = socket(AF_INET, SOCK_DGRAM, 0);

raw sockets allow you access to any parameter in an IP or TCP header.


Posted

in

by

Tags: