Crates.io | pnet_bandwhich_fork |
lib.rs | pnet_bandwhich_fork |
version | 0.23.1 |
source | src |
created_at | 2020-01-07 17:45:30.459254 |
updated_at | 2020-01-08 16:35:30.901527 |
description | Cross-platform, low level networking using the Rust programming language. |
homepage | https://github.com/libpnet/libpnet |
repository | https://github.com/libpnet/libpnet |
max_upload_size | |
id | 196249 |
size | 108,567 |
Discussion and support: #libpnet on freenode / #rust-networking on irc.mozilla.org / #rust on irc.mozilla.org.
libpnet
provides a cross-platform API for low level networking using Rust.
There are four key components:
packet
module, allowing safe construction and manipulation of packets;pnet_macros
crate, providing infrastructure for the packet module;transport
module, which allows implementation of transport protocols;datalink
module, which allows sending and receiving data link packets directly.There are lots of reasons to use low level networking, and many more to do it using Rust. A few are outlined here:
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.
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
.
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.
API documentation for the latest build can be found here: https://docs.rs/pnet/
To use libpnet
in your project, add the following to your Cargo.toml:
[dependencies.pnet]
version = "0.23.0"
libpnet
should work on any Rust channel (stable, beta, or nightly), starting
with Rust 1.15. When using a nightly version of Rust, you may wish to use pass
--no-default-features --features nightly
to Cargo, to enable faster build
times.
When running the test suite, there are a number of networking tests which will
likely fail - the easiest way to workaround this is to run cargo test
as a
root or administrative user. This can often be avoided, however it is more
involved.
There are three requirements for building on Windows:
Packet.lib
from the WinPcap Developers pack
in a directory named lib
, in the root of this repository. Alternatively, you can use any of the
locations listed in the %LIB%
/$Env:LIB
environment variables. For the 64 bit toolchain it is
in WpdPack/Lib/x64/Packet.lib
, for the 32 bit toolchain, it is in WpdPack/Lib/Packet.lib
.