pub struct NetworkUdpSocket { /* private fields */ }Expand description
A UDP socket that relays datagrams through the network provider.
Under the hood, the Rust side talks to a local relay socket. Each outbound
datagram is prefixed with a 6-byte address header ([4-byte IPv4][2-byte port BE])
so the relay (Go sidecar) knows where to forward the packet on the tsnet
network. Inbound datagrams arrive with the same header prepended by the relay.
This struct hides the framing — callers use send_to / recv_from with
normal SocketAddr values.
Implementations§
Source§impl NetworkUdpSocket
impl NetworkUdpSocket
Sourcepub async fn send_to(
&self,
data: &[u8],
addr: SocketAddr,
) -> Result<usize, NetworkError>
pub async fn send_to( &self, data: &[u8], addr: SocketAddr, ) -> Result<usize, NetworkError>
Send a datagram to the specified address via the relay.
The relay will forward the datagram to the target on the tsnet network.
Sourcepub async fn recv_from(
&self,
buf: &mut [u8],
) -> Result<(usize, SocketAddr), NetworkError>
pub async fn recv_from( &self, buf: &mut [u8], ) -> Result<(usize, SocketAddr), NetworkError>
Receive a datagram from the relay, returning the payload and sender address.
The relay prepends a 6-byte address header to each inbound datagram.
Sourcepub fn local_addr(&self) -> Result<SocketAddr, NetworkError>
pub fn local_addr(&self) -> Result<SocketAddr, NetworkError>
Return the local address of the underlying relay socket.
Sourcepub fn tsnet_port(&self) -> u16
pub fn tsnet_port(&self) -> u16
Return the tsnet-bound port (the logical port on the Tailscale network).