pf-rs 0.2.4

FreeBSD lib to access OpenBSD's implementation of the PF (Packet Filter) directly via /dev/pf
Documentation
use std::{process::Command, env};

macro_rules! msg 
{
    ($($tokens: tt)*) => {
        println!("cargo:warning={}", format!($($tokens)*))
    }
}

const DEFAULT_FREEBSD_VER: &'static str = "14.0";

fn get_freebsd_version() -> String
{   
    let use_ver = 
        option_env!("USE_FREEBSD_VER")
            .map_or(DEFAULT_FREEBSD_VER, |v| v)
            .to_string();

    let output = Command::new("freebsd-version").output().ok();
    if let Some(res) = output
    {
        if res.status.success() == false
        {
            return use_ver;
        }

        let stdout = String::from_utf8(res.stdout).unwrap();

        let ver = 
            match stdout.split_once("-")
            {
                Some((v, _)) =>
                {
                    v.to_string()
                },
                None => 
                {
                    msg!("can not determine freebsd version, building for: USE_FREEBSD_VER '{}'", use_ver);
                    use_ver
                }
            };


        return ver;
    }
    else
    {
        return use_ver;
    }    
}

fn ver_to_feature(ver: String) -> &'static str
{
    match ver.as_str()
    {
        "13.0" => return "FREEBSD_V13_0",
        "13.1" => return "FREEBSD_V13_1",
        "13.2" => return "FREEBSD_V13_2",
        "14.0" => return "FREEBSD_V14_0",
        _ => panic!("Freebsd version: '{}' is not supported", ver)
    }
}

fn main()
{
    let feature = ver_to_feature(get_freebsd_version());

    println!("cargo:rustc-cfg=feature=\"{}\"", feature);

    return;
}