Expand description
§networkframework-rs
Safe Rust bindings for Apple’s Network.framework, backed by a Swift bridge plus an opt-in raw FFI surface.
§What’s new in v0.9
SwiftPMbridge modeled after thescreencapturekit-rslayout.- Safe modules for the requested logical areas:
Connection,Listener,Browser,Parameters,Endpoint,Path,Framer,Group,Protocol,ContentContext,Resolver,Quic,PrivacyContext,ProxyConfig, andAdvertiseDescriptor. raw-ffifeature for direct access to the low-level bridge symbols.COVERAGE.md, per-area smoke tests, and runnable examples for every area.
§Crate layout
- Safe API: enabled by default.
- Raw bridge API:
--features raw-ffi - Coverage report:
COVERAGE.md
§Quick start
use networkframework::{TcpClient, TcpListener};
let listener = TcpListener::bind(0)?;
let port = listener.local_port();
let server = std::thread::spawn(move || -> Result<(), networkframework::NetworkError> {
let connection = listener.accept()?;
let request = connection.receive(1024)?;
assert_eq!(request, b"ping");
connection.send(b"pong")?;
Ok(())
});
let client = TcpClient::connect("127.0.0.1", port)?;
client.send(b"ping")?;
let reply = client.receive(1024)?;
assert_eq!(reply, b"pong");
server.join().expect("server thread")?;§Availability notes
Some Apple APIs are runtime-gated by the operating system:
- Application-service browsing / advertising / parameters: macOS 13+
- Relay and Oblivious HTTP proxy configuration: macOS 14+
- Ultra-constrained path / parameter flags and link quality: newer SDK/runtime combinations
The safe wrappers return NetworkError::InvalidArgument when a requested API is unavailable at runtime.
§Examples
cargo run --example 01_get_example
cargo run --example 04_bonjour
cargo run --example 06_bonjour_advertise
cargo run --example framer_length_prefix
cargo run --example content_context_overview
cargo run --example resolver_overview
cargo run --example privacy_context_overview
cargo run --example quic_options§Validation
cargo clippy --all-targets -- -D warnings
cargo test
for ex in examples/*.rs; do cargo run --example "$(basename "$ex" .rs)"; done§API documentation
Re-exports§
pub use advertise_descriptor::advertise_with_descriptor;pub use advertise_descriptor::AdvertiseDescriptor;pub use advertise_descriptor::Advertiser;pub use browser::advertise_bonjour_service;pub use browser::start_browser;pub use browser::start_browser_results_with_descriptor;pub use browser::start_browser_with_descriptor;pub use browser::BonjourAdvertiser;pub use browser::BrowseDescriptor;pub use browser::BrowseResult;pub use browser::BrowseResultChange;pub use browser::BrowseResultsBrowser;pub use browser::Browser;pub use browser::BrowserEvent;pub use browser::BrowserState;pub use browser::DiscoveredService;pub use client::ContentContext;pub use client::ReceivedContent;pub use client::TcpClient;pub use connection::Connection;pub use connection_group::ConnectionGroup;pub use connection_group::ConnectionGroupDescriptor;pub use connection_group::ConnectionGroupMessage;pub use connection_group::ConnectionGroupState;pub use connection_report::DataTransferPathReport;pub use connection_report::DataTransferReport;pub use connection_report::DataTransferReportState;pub use connection_report::EstablishmentProtocol;pub use connection_report::EstablishmentReport;pub use connection_report::ResolutionProtocol;pub use connection_report::ResolutionReport;pub use connection_report::ResolutionSource;pub use connection_report::ResolutionStep;pub use endpoint::Endpoint;pub use endpoint::EndpointType;pub use error::ErrorDomain;pub use error::FrameworkError;pub use error::NetworkError;pub use ethernet_channel::EthernetChannel;pub use ethernet_channel::EthernetChannelState;pub use ethernet_channel::EthernetFrame;pub use framer::Framer;pub use framer::FramerContext;pub use framer::FramerDefinition;pub use framer::FramerMessage;pub use framer::FramerMessageView;pub use framer::FramerOptions;pub use framer::FramerStart;pub use group::Group;pub use group::GroupDescriptor;pub use group::GroupMessage;pub use group::GroupState;pub use interface::list_interfaces;pub use interface::InterfaceType;pub use interface::NetworkInterface;pub use listener::TcpListener;pub use parameters::ConnectionParameters;pub use parameters::ParametersAttribution;pub use path::LinkQuality;pub use path::Path;pub use path::PathStatus;pub use path::PathUnsatisfiedReason;pub use path_monitor::start_path_monitor;pub use path_monitor::start_path_monitor_for_ethernet_channel;pub use path_monitor::start_path_monitor_with_type;pub use path_monitor::PathMonitor;pub use path_monitor::PathUpdate;pub use privacy::PrivacyContext;pub use privacy::ProxyConfig;pub use privacy::RelayHop;pub use privacy::ResolverConfig;pub use privacy::UrlSessionConfiguration;pub use protocol::IpEcnFlag;pub use protocol::IpLocalAddressPreference;pub use protocol::IpVersion;pub use protocol::ProtocolDefinition;pub use protocol::ProtocolMetadata;pub use protocol::ProtocolOptions;pub use protocol::TcpMultipathVersion;pub use quic::QuicConnection;pub use quic::QuicOptions;pub use txt_record::TxtRecord;pub use txt_record::TxtRecordEntry;pub use txt_record::TxtRecordFindResult;pub use txt_record::TxtRecordLookup;pub use udp::UdpClient;pub use websocket::Opcode;pub use websocket::WebSocket;pub use websocket::WsCloseCode;pub use websocket::WsMessage;pub use websocket::WsRequest;pub use websocket::WsResponse;pub use websocket::WsResponseStatus;pub use websocket::WsVersion;
Modules§
- advertise_
descriptor - Advertise-descriptor helpers.
- async_
api async - Async stream wrappers for Network.framework callback-based APIs.
- browser
Browser— Bonjour and application-service discovery vianw_browser.- client
TcpClient— synchronous outbound TCP connection via Network.framework.- connection
- Connection-oriented helpers and aliases.
- connection_
group - Connection groups built on
nw_connection_group_*. - connection_
report - Connection establishment and data-transfer reports.
- content_
context - Content-context aliases.
- endpoint
- Endpoint helpers backed by
nw_endpoint_t. - error
- Errors raised by
networkframework. - ethernet_
channel - Ethernet channel wrappers.
- framer
- Custom protocol framers built on
nw_framer_*. - group
- Connection-group aliases.
- interface
- Network interface enumeration helpers.
- listener
TcpListener— synchronous TCP listener via Network.framework.- parameters
- Configurable
nw_parameterswrappers for advanced connections. - path
- Path snapshots backed by
nw_path_t. - path_
monitor PathMonitor— observe network reachability and interface changes vianw_path_monitor.- prelude
- Common imports.
- privacy
- Privacy contexts, proxy configuration, and encrypted resolver settings.
- privacy_
context - Privacy-context aliases.
- protocol
- Protocol definitions and options.
- proxy_
config - Proxy-configuration aliases.
- quic
- QUIC helpers backed by Network.framework.
- raw_ffi
raw-ffi - Raw FFI ABI surface for advanced callers.
- resolver
- Resolver aliases.
- txt_
record - TXT-record helper APIs.
- udp
UdpClient— connected-mode UDP via Network.framework.- websocket
WebSocket— RFC 6455 WebSocket client over Network.framework.
Structs§
- Protocol
Stack - Mutable wrapper around
nw_protocol_stack_t. - Quic
Metadata - QUIC protocol metadata attached to a connection or content context.
- Security
Protocol Metadata - Opaque
sec_protocol_metadata_textracted from QUIC metadata. - Security
Protocol Options - Opaque
sec_protocol_options_textracted from QUIC options.
Enums§
- Expired
DnsBehavior - Policy controlling whether expired DNS answers may be used.
- Interface
Radio Type - Radio technology reported for an interface path sample.
- Multipath
Service - Multipath policy applied to new connections.
- Quic
Stream Type - QUIC stream direction or datagram mode.
- Service
Class - Connection service class applied to new paths.