diff --git a/netlink-packet-sock-diag/src/message.rs b/netlink-packet-sock-diag/src/message.rs index 519814da..4471379d 100644 --- a/netlink-packet-sock-diag/src/message.rs +++ b/netlink-packet-sock-diag/src/message.rs @@ -10,6 +10,7 @@ use crate::{ NetlinkPayload, NetlinkSerializable, SockDiagBuffer, + SOCK_DESTROY, SOCK_DIAG_BY_FAMILY, }; @@ -93,3 +94,41 @@ impl From for NetlinkPayload { NetlinkPayload::InnerMessage(message) } } + +#[derive(Debug, PartialEq, Eq, Clone)] +pub struct SockDiagDestroy(SockDiagMessage); + +impl SockDiagDestroy { + pub fn new(message: SockDiagMessage) -> SockDiagDestroy { + SockDiagDestroy(message) + } +} + +impl NetlinkSerializable for SockDiagDestroy { + fn message_type(&self) -> u16 { + SOCK_DESTROY + } + + fn buffer_len(&self) -> usize { + NetlinkSerializable::buffer_len(&self.0) + } + + fn serialize(&self, buffer: &mut [u8]) { + self.0.serialize(buffer) + } +} + +impl NetlinkDeserializable for SockDiagDestroy { + type Error = DecodeError; + fn deserialize(header: &NetlinkHeader, payload: &[u8]) -> Result { + Ok(SockDiagDestroy::new(SockDiagMessage::deserialize( + header, payload, + )?)) + } +} + +impl From for NetlinkPayload { + fn from(message: SockDiagDestroy) -> Self { + NetlinkPayload::InnerMessage(message) + } +}