diff --git a/src/message.rs b/src/message.rs index c792005..16f13db 100644 --- a/src/message.rs +++ b/src/message.rs @@ -8,7 +8,7 @@ use netlink_packet_utils::{ DecodeError, }; -use crate::{inet, unix, SockDiagBuffer, SOCK_DIAG_BY_FAMILY}; +use crate::{inet, unix, SockDiagBuffer, SOCK_DESTROY, SOCK_DIAG_BY_FAMILY}; #[derive(Debug, PartialEq, Eq, Clone)] pub enum SockDiagMessage { @@ -93,3 +93,44 @@ 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) + } +}