Short ARS tutorial
Salvatore Sanfilippo
<antirez@invece.org>

OVERVIEW
~~~~~~~~

ARS is a packet assembly library that reflects the `layered' nature
of the TCP/IP protocol. It allows both low level and high level
packet assembly, providing an optional interface to build TCP/IP packets
based on a plaintext description.

The layers supported in this release are the following:
IPv4
IPv4 options (all the options documented AFAIK)
ICMP (all the type/code)
UDP
TCP
TCP options (all the options documented AFAIK)
DATA

Ipv6 is scheduled.

HELLO ARS
~~~~~~~~~

The following is a trivial example of low level packet costruction
using the ARS lib, it generates an ICMP echo-request packet similar
to the packets sent by the ping(8) program.

#include <stdio.h>
#include <netinet/in.h>
#include "ars.h"

int main(int argc, char **argv)
{
	struct ars_packet p;
	struct ars_iphdr *ip;
	struct ars_icmphdr *icmp;
	int s;
	void *data;

	ars_init(&p); /* Initialize the packet structure */

	s = ars_open_rawsocket(&p); /* Open a raw socket */
	if (s == -ARS_ERROR) {
		perror("Opening raw socket");
		exit(1);
	}

	/* IP layer */
	ip = ars_add_iphdr(&p, 0);
	ip->id = htons(1);
	ip->ttl = 0;
	ars_resolve(&p, &ip->saddr, "192.168.2.1");
	ars_resolve(&p, &ip->daddr, "192.168.2.2");

	/* ICMP layer */
	icmp = ars_add_icmphdr(&p, 0);
	icmp->type = ARS_ICMP_ECHO;
	icmp->code = 0;

	/* DATA */
	data = ars_add_data(&p, 10);
	memset(data, 'A', 10);

	/* Compile the packet */
	if (ars_compile(&p) != -ARS_OK) {
		printf("Error compiling\n");
		exit(0);
	}

	/* Send the packet */
	ars_send(s, &p, NULL, 0);

	return 0;
}

ars_init()
~~~~~~~~~~