Crate udplite[][src]

Exposes the UDP-Lite socket type with an API similar to std::net::UdpSocket.

UDP-Lite is a layer 3 networking protocol very similar to UDP, that allows receiving partially corrupted packets.

In addition to not being reliable (ie. datagrams can disappear), UDP-Lite is only useful if the layer 2 protocol supports disabling checksums, and is not all that usable on the wider internet. (My ISPs router doesn't recognize the protocol, so its NAT drops all packets.) The protocol is also only implemented on Linux and FreeBSD. (It looks like Android hasn't disabled it, but I'm not certain).

This crate is tested on both Linux (except Android) and FreeBSD.

Examples

use udplite::UdpLiteSocket;
use std::net::*;

let a = UdpLiteSocket::bind((Ipv4Addr::LOCALHOST, 0))
    .expect("create UDP-Lite socket bound to 127.0.0.1:0");
let b = UdpLiteSocket::bind((Ipv4Addr::LOCALHOST, 0))
    .expect("create another socket bound to 127.0.0.1:0");

// reduce sent and required checksum coverage (whole datagram by default)
a.set_send_checksum_coverage(Some(5)).expect("set partial checksum coverage");
b.set_recv_checksum_coverage_filter(Some(5)).expect("set required checksum coverage");

let b_addr = b.local_addr().expect("get addr of socket b");
a.send_to(b"Hello UDP-Lite", b_addr).expect("send datagram");

let mut buf = [0u8; 20];
let received_bytes = b.recv(&mut buf).expect("receive datagram");
assert_eq!(received_bytes, "Hello UDP-Lite".len());
assert_eq!(&buf[..5], b"Hello");

Current implementation details

To significantly reduce the amount of unsafe code necessary in this crate, most methods are provided through Deref to UdpSocket. This creates one wart/gotcha/unsoundness though: UdpSockets .try_clone() is available, returning an UdpSocket that is actually UDP-Lite. The method is shadowed by UdpLiteSockets own .try_clone()(struct.UdpLiteSocket.html#method.try_clone)

Minimum Rust version

udplite will require Rust 1.36.0 (for std::io::IoSlice).

Possible future features (open an issue if you want one)

  • Optional tokio integration.
  • Vectored I/O (stds UdpSocket doesn't have this yet either).
  • Exposing more POSIX socket options and flags for send() and recv().
  • Sending and receiving multiple datagrams at a time.
  • Getting TTL and/or timestamp of received datagrams.

Structs

UdpLiteSocket