38 lines
898 B
Rust
38 lines
898 B
Rust
use serde::{Deserialize, Serialize};
|
|
use std::fmt::{Display, Formatter};
|
|
use std::net::{Ipv4Addr, Ipv6Addr};
|
|
|
|
pub mod codec;
|
|
pub mod request;
|
|
pub mod response;
|
|
|
|
// version 3: initial version
|
|
// version 4: IPv6 support
|
|
// version 5: Add severity level to info response
|
|
pub const CURRENT_VERSION: u8 = 5;
|
|
|
|
#[derive(Copy, Clone, Debug, PartialEq, Eq, Hash, Serialize, Deserialize)]
|
|
pub struct IpPair {
|
|
pub ipv4: Ipv4Addr,
|
|
pub ipv6: Ipv6Addr,
|
|
}
|
|
|
|
impl IpPair {
|
|
pub fn new(ipv4: Ipv4Addr, ipv6: Ipv6Addr) -> Self {
|
|
IpPair { ipv4, ipv6 }
|
|
}
|
|
}
|
|
|
|
impl Display for IpPair {
|
|
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
|
|
write!(f, "IPv4: {}, IPv6: {}", self.ipv4, self.ipv6)
|
|
}
|
|
}
|
|
|
|
fn make_bincode_serializer() -> impl bincode::Options {
|
|
use bincode::Options;
|
|
bincode::DefaultOptions::new()
|
|
.with_big_endian()
|
|
.with_varint_encoding()
|
|
}
|