mirror of
https://github.com/zaphar/icmp-socket.git
synced 2025-07-21 19:29:47 -04:00
Merge pull request #4 from zaphar/allow_dgram_sockets
Add dgram sockets as an option
This commit is contained in:
commit
02b0714302
@ -70,10 +70,14 @@ pub struct IcmpSocket4 {
|
||||
}
|
||||
|
||||
impl IcmpSocket4 {
|
||||
/// Construct a new socket. The socket must be bound to an address using `bind_to`
|
||||
/// Construct a new raw socket. The socket must be bound to an address using `bind_to`
|
||||
/// before it can be used to send and receive packets.
|
||||
pub fn new() -> std::io::Result<Self> {
|
||||
let socket = Socket::new(Domain::IPV4, Type::RAW, Some(Protocol::ICMPV4))?;
|
||||
Self::new_from_socket(socket)
|
||||
}
|
||||
|
||||
fn new_from_socket(socket: Socket) -> std::io::Result<Self> {
|
||||
socket.set_recv_buffer_size(512)?;
|
||||
Ok(Self {
|
||||
bound_to: None,
|
||||
@ -85,6 +89,13 @@ impl IcmpSocket4 {
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
/// Construct a new dgram socket. The socket must be bound to an address using `bind_to`
|
||||
/// before it can be used to send and receive packets.
|
||||
pub fn new_dgram_socket() -> std::io::Result<Self> {
|
||||
let socket = Socket::new(Domain::IPV4, Type::DGRAM, Some(Protocol::ICMPV4))?;
|
||||
Self::new_from_socket(socket)
|
||||
}
|
||||
}
|
||||
|
||||
impl IcmpSocket for IcmpSocket4 {
|
||||
@ -136,10 +147,14 @@ pub struct IcmpSocket6 {
|
||||
}
|
||||
|
||||
impl IcmpSocket6 {
|
||||
/// Construct a new socket. The socket must be bound to an address using `bind_to`
|
||||
/// Construct a new raw socket. The socket must be bound to an address using `bind_to`
|
||||
/// before it can be used to send and receive packets.
|
||||
pub fn new() -> std::io::Result<Self> {
|
||||
let socket = Socket::new(Domain::IPV6, Type::RAW, Some(Protocol::ICMPV6))?;
|
||||
Self::new_from_socket(socket)
|
||||
}
|
||||
|
||||
fn new_from_socket(socket: Socket) -> std::io::Result<Self> {
|
||||
socket.set_recv_buffer_size(512)?;
|
||||
Ok(Self {
|
||||
bound_to: None,
|
||||
@ -151,6 +166,13 @@ impl IcmpSocket6 {
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
/// Construct a new dgram socket. The socket must be bound to an address using `bind_to`
|
||||
/// before it can be used to send and receive packets.
|
||||
pub fn new_dgram_socket() -> std::io::Result<Self> {
|
||||
let socket = Socket::new(Domain::IPV6, Type::DGRAM, Some(Protocol::ICMPV6))?;
|
||||
Self::new_from_socket(socket)
|
||||
}
|
||||
}
|
||||
|
||||
impl IcmpSocket for IcmpSocket6 {
|
||||
|
Loading…
x
Reference in New Issue
Block a user