netsem
Standardized, pure-functional IP address validation and port checking utilities.
netsem (Network Semantics) provides synchronous tools for parsing, classifying, and validating network primitives (IPs, Ports, Sockets). It is designed to be a lightweight foundation for network applications, offering a clear separation between semantic validation (syntax, logic) and OS-level interactions (binding, connecting).
Features
- Pure Validation: Parse and validate IPs and Ports without touching the OS.
- IP Classification: Categorize IPs into
Loopback,Private,Global,Multicast, orUnspecified. - Port Classification: Identify
System,User, orDynamicports. - OS Checks (Optional): Perform actual
bindorconnectchecks using thecheckfeature (powered bysocket2). - Sync-First: Zero async dependencies. Ready to be wrapped in
spawn_blockingif needed. - Error Handling: Uses
thiserrorfor structured, inspectable errors.
Usage Examples
Check the examples directory for runnable code:
- Basic Usage:
examples/simple.rs- Parse a socket address and optionally check if it can be bound. - IP Classification:
examples/ip_classification.rs- Categorize different IP addresses (Loopback, Private, Global, etc.). - Port Ranges:
examples/port_ranges.rs- Classify ports into System, User, and Dynamic ranges. - OS Checks:
examples/os_check.rs- Perform actual bind and connect tests (requirescheckfeature).
Installation
[]
= { = "0.0.2", = ["full"] }
Feature Flags
| Feature | Description |
|---|---|
check |
Enables OS-level checks (check_bind, check_connect) using socket2. |
tracing |
Enables integration with the tracing crate (currently reserved/unused). |
serde |
Enables serde support (currently reserved/unused). |
full |
Enables all features above. |
License
Released under the MIT License © 2026 Canmi