pub struct SocketConfig<V: IcmpVersion> {
pub bind_to: Option<V::SocketAddr>,
}
Expand description
Config for creating sockets.
Most use cases can use SocketConfig::default()
.
To avoid compatibility concerns when more fields are added, use the ..
struct update syntax
so that any new fields will be conveniently defaulted in existing invocations:
use std::net;
use async_icmp::{Icmpv4, socket::SocketConfig};
let config: SocketConfig<Icmpv4> = SocketConfig {
bind_to: Some(net::SocketAddrV4::new(net::Ipv4Addr::LOCALHOST, 1234)),
..SocketConfig::default()
};
Fields§
§bind_to: Option<V::SocketAddr>
The sockaddr to bind the socket to. If specified with Some
, the socket is always bound to
the address.
If not specified, the behavior depends on the platform. On all supported platforms, a
socket’s initial state is bound to the suitable undefined
address (0.0.0.0:0
or :::0
).
On Linux, explicitly binding that address causes the kernel to select a local port, which is useful for ICMP Echo messages since Linux forces the echo id to be the local port.
On macOS, binding that address makes no difference: an ICMP socket always has zero local port, so the bind is not performed.
Trait Implementations§
Source§impl<V: Clone + IcmpVersion> Clone for SocketConfig<V>where
V::SocketAddr: Clone,
impl<V: Clone + IcmpVersion> Clone for SocketConfig<V>where
V::SocketAddr: Clone,
Source§fn clone(&self) -> SocketConfig<V>
fn clone(&self) -> SocketConfig<V>
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read more