#![allow(dead_code)]
#![allow(non_camel_case_types)]
use std::io::{Read, Write};
use super::{
Deserialize, DeserializeEnum, DeserializeStruct, Serialize, SerializeEnum, SerializeStruct,
};
use crate::xdr::deserialize;
use num_derive::{FromPrimitive, ToPrimitive};
#[allow(non_camel_case_types)]
#[derive(Copy, Clone, Debug, Default)]
#[repr(C)]
pub struct mapping {
pub prog: u32,
pub vers: u32,
pub prot: u32,
pub port: u32,
}
DeserializeStruct!(mapping, prog, vers, prot, port);
SerializeStruct!(mapping, prog, vers, prot, port);
#[derive(Default, Debug)]
pub struct pmaplist {
pub map: mapping,
pub next: Box<Option<pmaplist>>,
}
impl Serialize for pmaplist {
fn serialize<W: Write>(&self, dest: &mut W) -> std::io::Result<()> {
self.map.serialize(dest)?;
self.next.serialize(dest)
}
}
impl Deserialize for pmaplist {
fn deserialize<R: Read>(&mut self, src: &mut R) -> std::io::Result<()> {
let mapping = deserialize::<mapping>(src)?;
self.map = mapping;
let has_next = deserialize::<bool>(src)?;
match has_next {
true => {
let pmaplist = deserialize::<pmaplist>(src)?;
self.next = Box::from(Some(pmaplist))
}
false => self.next = Box::from(None),
}
Ok(())
}
}
pub const IPPROTO_TCP: u32 = 6;
pub const IPPROTO_UDP: u32 = 17;
pub const PROGRAM: u32 = 100000;
pub const VERSION: u32 = 2;
#[allow(non_camel_case_types)]
#[allow(clippy::upper_case_acronyms)]
#[derive(Copy, Clone, Debug, FromPrimitive, ToPrimitive)]
pub enum PortmapProgram {
PMAPPROC_NULL = 0,
PMAPPROC_SET = 1,
PMAPPROC_UNSET = 2,
PMAPPROC_GETPORT = 3,
PMAPPROC_DUMP = 4,
PMAPPROC_CALLIT = 5,
INVALID,
}
impl SerializeEnum for PortmapProgram {}
impl DeserializeEnum for PortmapProgram {}