{"id":30086250,"url":"https://github.com/otsmr/pnet_layers","last_synced_at":"2026-01-20T17:29:23.935Z","repository":{"id":307852890,"uuid":"1030829228","full_name":"otsmr/pnet_layers","owner":"otsmr","description":"A scapy like wrapper around the pnet crate to easily parse, craft or manipulate network packets in Rust.","archived":false,"fork":false,"pushed_at":"2025-08-11T19:24:31.000Z","size":23,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"main","last_synced_at":"2025-08-23T07:44:55.796Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"https://crates.io/crates/pnet_layers","language":"Rust","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/otsmr.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"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,"zenodo":null}},"created_at":"2025-08-02T12:16:01.000Z","updated_at":"2025-08-11T20:39:57.000Z","dependencies_parsed_at":"2025-08-02T17:35:37.054Z","dependency_job_id":null,"html_url":"https://github.com/otsmr/pnet_layers","commit_stats":null,"previous_names":["otsmr/pnet_layers"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/otsmr/pnet_layers","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/otsmr%2Fpnet_layers","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/otsmr%2Fpnet_layers/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/otsmr%2Fpnet_layers/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/otsmr%2Fpnet_layers/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/otsmr","download_url":"https://codeload.github.com/otsmr/pnet_layers/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/otsmr%2Fpnet_layers/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":272958516,"owners_count":25022051,"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","status":"online","status_checked_at":"2025-08-31T02:00:09.071Z","response_time":79,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"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":[],"created_at":"2025-08-09T01:55:31.280Z","updated_at":"2026-01-20T17:29:23.923Z","avatar_url":"https://github.com/otsmr.png","language":"Rust","funding_links":[],"categories":[],"sub_categories":[],"readme":"# pnet_layers\n\n`pnet_layers` is a scapy like wrapper around the [pnet](https://crates.io/crates/pnet) crate to easily parse, craft or manipulate network packets.\n\nFor this `pnet_layers` defines two `traits` which can be implemented for `structs` that are deriving `#[packet]` defined by the `pnet` library. The first `trait` is the `LayerImmutable` implementing functions without cloning the underlining buffer. And the `LayerMutable` that allows to modify the packet or to craft new onces as shown below.  \n\n## Crafting a packet\n\nTo craft, for example, a UDP packet including all layers down to Ethernet the `EtherMut` can be used.\n\n```rs\n// Create a new Ethernet Packet\nlet mut ether = EtherMut::new();\n\n// Modify the packet. The `modify` function returns the pnet defined mutable packet to modify the different field.\nif let Some(mut eth) = ether.modify() {\n    eth.set_source(MacAddr::from_str(\"3c:ce:33:33:33:33\").unwrap());\n    eth.set_destination(MacAddr::broadcast());\n}\n\n// Using the `add` function new layers can be added.\nether.add(LayerMut::Vlan(VlanMut::new()));\nether.add(LayerMut::Ipv4(Ipv4Mut::new()));\nether.add(LayerMut::Udp(UdpMut::new()));\nether.add(LayerMut::Payload(PayloadMut::from_buf(vec![10; 10]).unwrap()));\n\nprintln!(\"{ether}\");\n// Ether (s: 3c:ce:33:33:33:33, d: ff:ff:ff:ff:ff:ff:ff) \u003e Vlan (id: 1) \u003e Ipv4 (s: 0.0.0.0, d: 0.0.0.0) \u003e Udp (s: 0, d: 0) \u003e [10, 10, 10, 10, 10, 10, 10, 10, 10, 10]\n\n// Using the .build() function all required params will be set including:\n// - EtherType\n// - Ipv4 size, checksum\n// - UDP size, checksum\n\n// Also some magic fields will be set. For example the IPv4 TTL value will be set to `MAGIC_IPV4_TTL`.\n// This makes is possible to identify the packet later, for example, in a Wireshark trace. \n// See all magic bytes in the `magics.rs` file\n\nif let Some(bytes) = ether.build() {\n    // bytes in format of Vec\u003cu8\u003e which can be send to the network\n    // let _ = tx.send_to(\u0026bytes, None);\n}\n```\n\n## Parsing and manipulating\n\nPacket can also be parsed from a `u8` array and then modified.\n\n```rs\n/// Parsing the packet from a buffer in this case an Ethernet packet.\nif let Some(mut ether) = EtherMut::from_buf(bytes) {\n\n    // Add an VLAN tag\n    ether.add(LayerMut::Vlan(VlanMut::new()));\n\n    // Searching for the PAYLOAD and modifying it\n    if let Some(LayerMut::Payload(vlan)) = ether.get_layer(\u0026Layers::Payload) {\n        vlan.set_payload(vec![11; 10]);\n    }\n\n    // Building the manipulated packet. This will also recalculate all the different checksums.\n    // The magic values are only changed if the value was `0`. So when the TTL value is already set, this will not be changed to the magic value.\n    if let Some(bytes) = ether.build() {\n        // let _ = tx.send_to(\u0026bytes, None);\n    }\n}\n```\n\n## Creating a new layer\n\nCurrently only a few layers are defined in [src/layers](src/layers/). If you want to add a new layer, please crate a new file in the `layers` folder with the protocol name. And implement the two traits. Most functions can be implemented by macros defined in `macros.rs`. \n\n# License\nThis project is licensed under the [Apache-2.0](./LICENSE) license","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fotsmr%2Fpnet_layers","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fotsmr%2Fpnet_layers","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fotsmr%2Fpnet_layers/lists"}