| Crates.io | tcp-save-syn |
| lib.rs | tcp-save-syn |
| version | 0.1.0 |
| created_at | 2026-01-15 14:41:05.22812+00 |
| updated_at | 2026-01-15 14:41:05.22812+00 |
| description | Capture raw SYN from TCP connections on Linux |
| homepage | |
| repository | https://github.com/client-side-dev/tcp-save-syn-rs |
| max_upload_size | |
| id | 2045719 |
| size | 21,204 |
Retrieve the raw SYN packet bytes from accepted TCP connections on Linux via TCP_SAVE_SYN/TCP_SAVED_SYN.
When TCP_SAVE_SYN is enabled on a listening socket, the Linux kernel saves the raw SYN packet (including IP headers) for each accepted connection. This packet can be retrieved with TCP_SAVED_SYN and used for TCP fingerprinting or analysis.
This crate provides a simple interface to these socket options. On non-Linux platforms, all functions are no-ops that succeed silently, so your code compiles and runs everywhere.
use std::net::TcpListener;
use tcp_save_syn::{enable_save_syn, get_saved_syn};
let listener = TcpListener::bind("0.0.0.0:8080")?;
enable_save_syn(&listener)?;
let (stream, _addr) = listener.accept()?;
if let Some(syn_bytes) = get_saved_syn(&stream) {
// syn_bytes contains the raw IP + TCP headers from the SYN packet
println!("SYN packet: {} bytes", syn_bytes.len());
// Parse with etherparse, pnet, or your preferred packet parser
}
Works with any socket type implementing AsRawFd, including tokio::net::TcpListener/TcpStream.
| Platform | Behavior |
|---|---|
| Linux | Full functionality via setsockopt/getsockopt |
| macOS, Windows, others | No-op (enable_save_syn succeeds, get_saved_syn returns None) |
The returned bytes start with the IP header:
4, IHL field gives header length6, fixed 40-byte headerTCP header follows immediately after. The packet may be truncated if TCP Fast Open includes data in the SYN, but headers are always present.
Apache-2.0