Introduction

libtins is a high-level, multiplatform C++ network packet sniffing and crafting library.

Its main purpose is to provide the C++ developer an easy, efficient, platform and endianness-independent way to create tools which need to send, receive and manipulate network packets.

It uses a BSD-2 license and it's hosted at github.

It's easy to use!

The library is very simple to use. As a short example, this is how it could be used to print the source and destination addresses and ports of every TCP packet captured in the eth0 interface:

#include <iostream> #include <tins/tins.h> using namespace Tins ; using namespace std ; bool callback ( const PDU & pdu ) { // Find the IP layer const IP & ip = pdu . rfind_pdu < IP > (); // Find the TCP layer const TCP & tcp = pdu . rfind_pdu < TCP > (); cout << ip . src_addr () << ':' << tcp . sport () << " -> " << ip . dst_addr () << ':' << tcp . dport () << endl ; return true ; } int main () { Sniffer ( "eth0" ). sniff_loop ( callback ); }

High level != inefficient

libtins was designed keeping efficiency in mind at all times. In fact, it is one of the fastest packet sniffing and interpretation libraries available. The benchmark section contains some actual measurements of how fast it works.

It's been thoroughly tested

Almost as much time was invested testing the library than developing it. At the moment of writing, there are 624 unit tests, which check that everything in libtins does what's expected.

Portability

Making your applications portable is very important. That is why a lot of work has been done so that libtins works on Windows, OSX and both little and big endian GNU/Linux and FreeBSD operating systems. This means you can develop some sniffing application, cross-compile it and execute it directly on your ARM or MIPS routers, or any other device that has sniffing capabilities, provided it has enough RAM. (libtins is ~10MB)

Features

libtins supports several protocols and features: