{"id":13578107,"url":"https://github.com/J-Schoepplenberg/zero-packet","last_synced_at":"2025-04-05T16:31:53.815Z","repository":{"id":247495722,"uuid":"823863790","full_name":"J-Schoepplenberg/zero-packet","owner":"J-Schoepplenberg","description":"A zero-copy Rust library that builds and parses network packets in-place.","archived":false,"fork":false,"pushed_at":"2025-03-25T19:16:57.000Z","size":159,"stargazers_count":110,"open_issues_count":3,"forks_count":4,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-04-04T22:18:33.941Z","etag":null,"topics":["networking","no-allocation","packet-processing","packets","zero-copy"],"latest_commit_sha":null,"homepage":"https://crates.io/crates/zero-packet","language":"Rust","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/J-Schoepplenberg.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2024-07-03T22:12:41.000Z","updated_at":"2025-03-31T05:12:13.000Z","dependencies_parsed_at":"2024-07-18T18:54:58.281Z","dependency_job_id":null,"html_url":"https://github.com/J-Schoepplenberg/zero-packet","commit_stats":null,"previous_names":["j-schoepplenberg/zero-packet"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/J-Schoepplenberg%2Fzero-packet","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/J-Schoepplenberg%2Fzero-packet/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/J-Schoepplenberg%2Fzero-packet/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/J-Schoepplenberg%2Fzero-packet/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/J-Schoepplenberg","download_url":"https://codeload.github.com/J-Schoepplenberg/zero-packet/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247366330,"owners_count":20927493,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["networking","no-allocation","packet-processing","packets","zero-copy"],"created_at":"2024-08-01T15:01:27.520Z","updated_at":"2025-04-05T16:31:53.558Z","avatar_url":"https://github.com/J-Schoepplenberg.png","language":"Rust","funding_links":[],"categories":["Rust"],"sub_categories":[],"readme":"# zero-packet\n\n[![crates.io](https://img.shields.io/crates/v/zero-packet.svg)](https://crates.io/crates/zero-packet)\n[![MIT](https://img.shields.io/badge/License-MIT-orange.svg)](https://github.com/J-Schoepplenberg/zero-packet/blob/main/LICENSE)\n[![docs.rs](https://docs.rs/zero-packet/badge.svg)](https://docs.rs/zero-packet/latest/zero_packet/index.html)\n\nSuper simple library to efficiently build and parse network packets in-place with zero overhead.\n\nNo async, no allocations, no dependencies, no std, no unsafe. It simply cannot be easier.\n\nUse `zero-packet` if you are working with raw sockets, low-level networking, or something similar.\n\n## Supported\n\nYou can build and parse a wide variety of packets of arbitrary complexity.\n\n- Ethernet II\n    - Optional\n        - VLAN tagging\n        - Double tagging\n- ARP\n- IPv4\n- IPv6\n    - Extension headers\n        - Hop-by-Hop Options\n        - Routing\n        - Fragment\n        - Authentication Header\n        - Destination Options (1st and 2nd)\n- IP-in-IP\n    - Encapsulation\n        - IPv4 in IPv4\n        - IPv4 in IPv6\n        - IPv6 in IPv4\n        - IPv6 in IPv6\n- ICMPv4\n- ICMPv6\n- TCP\n- UDP\n\n## Usage\n\n### Getting started\n\nInstall via your command line:\n\n```bash\ncargo add zero-packet\n```\n\nOr add the following to your `Cargo.toml`:\n\n```toml\n[dependencies]\nzero-packet = \"0.1.0\"\n```\n\n### PacketBuilder\n\nIf you want to create network packets manually and efficiently, look no further.\n\n```Rust\n// Raw packet that we will mutate in-place.\n// Ethernet header (14 bytes) + IPv4 header (20 bytes) + UDP header (8 bytes) = 42 bytes.\nlet mut buffer = [0u8; 64]\n\n// Some random payload (11 bytes).\nlet payload = b\"Hello, UDP!\";\n\n// PacketBuilder is a zero-copy packet builder.\n// Using the typestate pattern, a state machine is implemented at compile-time.\n// The state machine ensures that the package is built structurally correct.\nlet mut packet_builder = PacketBuilder::new(\u0026mut buffer);\n\n// Sets Ethernet, IPv4 and UDP header fields.\n// Optional: add payload to the packet.\n// Encapsulates everything in the given byte slice.\nlet packet: \u0026[u8] = packet_builder\n    .ethernet(src_mac, dest_mac, ethertype)?\n    .ipv4(version, ihl, dscp, ecn, total_length, id, flags, fragment_offset, ttl, protocol, src_ip, dest_ip)?\n    .udp(src_ip, src_port, dest_ip, dest_port, length, Some(payload))?\n    .build();\n```\n\n### PacketParser\n\nParsing any received byte slice for which we don't know ahead of time what type of packet it is.\n\n```Rust\n// Some byte slice that we have received.\n// We don't know yet what it contains.\nlet packet = [..];\n\n// PacketParser is a zero-copy packet parser.\n// The `parse` method recognizes which protocol headers are present.\nlet parsed = PacketParser::parse(\u0026packet)?;\n\n// Now it is as easy as this.\nif let Some(ethernet) = parsed.ethernet {\n    let ethertype = ethernet.ethertype();\n    // ...\n}\n\n// Or this.\nif let Some(ipv4) = parsed.ipv4 {\n    let src_ip = ipv4.src_ip();\n    // ...\n}\n\n// Alternatively, just manually read headers directly.\n// By adjusting the index of the slice you can find different headers.\nif let Some(tcp) = TcpReader::new(\u0026packet)? {\n    let src_port = tcp.src_port();\n    // ...\n}\n\n```","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FJ-Schoepplenberg%2Fzero-packet","html_url":"https://awesome.ecosyste.ms/projects/github.com%2FJ-Schoepplenberg%2Fzero-packet","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FJ-Schoepplenberg%2Fzero-packet/lists"}