falco_event/types/net/
endpoint.rs1use crate::fields::{FromBytes, FromBytesError, ToBytes};
2use crate::types::Port;
3use std::io::Write;
4use std::net::{Ipv4Addr, Ipv6Addr};
5
6pub type EndpointV4 = (Ipv4Addr, Port);
7
8impl ToBytes for EndpointV4 {
9 #[inline]
10 fn binary_size(&self) -> usize {
11 self.0.binary_size() + self.1.binary_size()
12 }
13
14 #[inline]
16 fn write<W: Write>(&self, mut writer: W) -> std::io::Result<()> {
17 self.0.write(&mut writer)?;
18 self.1.write(writer)
19 }
20
21 #[inline]
22 fn default_repr() -> impl ToBytes {
23 (Ipv4Addr::from(0), Port(0))
24 }
25}
26
27impl FromBytes<'_> for EndpointV4 {
28 #[inline]
29 fn from_bytes(buf: &mut &'_ [u8]) -> Result<Self, FromBytesError> {
30 Ok((FromBytes::from_bytes(buf)?, FromBytes::from_bytes(buf)?))
31 }
32}
33
34pub type EndpointV6 = (Ipv6Addr, Port);
35
36impl ToBytes for EndpointV6 {
37 #[inline]
38 fn binary_size(&self) -> usize {
39 self.0.binary_size() + self.1.binary_size()
40 }
41
42 #[inline]
44 fn write<W: Write>(&self, mut writer: W) -> std::io::Result<()> {
45 self.0.write(&mut writer)?;
46 self.1.write(writer)
47 }
48
49 #[inline]
50 fn default_repr() -> impl ToBytes {
51 (Ipv6Addr::from(0), Port(0))
52 }
53}
54
55impl FromBytes<'_> for EndpointV6 {
56 #[inline]
57 fn from_bytes(buf: &mut &'_ [u8]) -> Result<Self, FromBytesError> {
58 Ok((FromBytes::from_bytes(buf)?, FromBytes::from_bytes(buf)?))
59 }
60}