libpnet

Linux ∪ OS X Build Status: Linux ∪ OS X Build Status

Windows Build Status: Windows Build Status

Discussion and support: #libpnet on freenode / #rust on irc.mozilla.org.

libpnet provides a cross-platform API for low level networking using Rust.

There are four key components:

Why?

There are lots of reasons to use low level networking, and many more to do it using Rust. A few are outlined here:

Developing Transport Protocols

There are usually two ways to go about developing a new transport layer protocol:

The former is great for trying out new ideas and rapid prototyping, however not so great as a real-world implementation. While you can usually get reasonable performance out of these implementations, they're generally significantly slower than an implementation in C, and not suitable for any "heavy lifting".

The next option is to write it in C - this will give you great performance, but comes with a number of other issues:

Using libpnet and Rust, you get the best of both worlds. The higher level abstractions, memory and thread safety, alongside the performance of C.

Network Utilities

Many networking utilities such as ping and traceroute rely on being able to manipulate network and transport headers, which isn't possible with standard networking stacks such as those provided by std::io::net.

Data Link Layer

It can be useful to work directly at the data link layer, to see packets as they are "on the wire". There are lots of uses for this, including network diagnostics, packet capture and traffic shaping.

Documentation

API documentation for the lastest build can be found here: http://octarineparrot.com/assets/libpnet/doc/pnet/.

Usage

To use libpnet in your project, add the following to your Cargo.toml:

[dependencies.pnet] git = "https://github.com/libpnet/libpnet.git"

When developing, use the provided Makefile, which does weird things to make the tests work properly. Note that root/administrator access is usually required for libpnet.

You must use the nightly channel of Rust to use libpnet.