pub trait UdpSas: Sized {
fn bind_sas<A: ToSocketAddrs>(addr: A) -> Result<Self>;
fn send_sas(
&self,
buf: &[u8],
target: &SocketAddr,
local: &IpAddr
) -> Result<usize>;
fn recv_sas(&self, buf: &mut [u8]) -> Result<(usize, SocketAddr, IpAddr)>;
}
Expand description
An extension trait to support source address selection in std::net::UdpSocket
See module level documentation for more details.
Required Methods
fn bind_sas<A: ToSocketAddrs>(addr: A) -> Result<Self>
fn bind_sas<A: ToSocketAddrs>(addr: A) -> Result<Self>
Creates a UDP socket from the given address.
The address type can be any implementor of ToSocketAddrs
trait. See
its documentation for concrete examples.
The new socket is configured with the IP_PKTINFO
or IPV6_RECVPKTINFO
option enabled.
Examples
use std::net::UdpSocket;
use udp_sas::UdpSas;
let socket = UdpSocket::bind_sas("127.0.0.1:34254").expect("couldn't bind to address");
Sends a datagram to the given target
address and use the local
address as its
source.
On success, returns the number of bytes written.