rscamper 0.2.2

Rust interface to scamper network measurement tool
Documentation
// rscamper - Rust FFI bindings for scamper_file.h
//
// Copyright (C) 2026 Dimitrios Giakatos
//
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, version 3.

use libc::{c_char, c_int, c_void, size_t};

#[repr(C)]
pub struct ScamperFileT {
    _opaque: [u8; 0],
}

#[repr(C)]
pub struct ScamperFileFilterT {
    _opaque: [u8; 0],
}

#[repr(C)]
pub struct ScamperFileReadbufT {
    _opaque: [u8; 0],
}

pub const SCAMPER_FILE_OBJ_LIST:          u16 = 1;
pub const SCAMPER_FILE_OBJ_CYCLE_START:   u16 = 2;
pub const SCAMPER_FILE_OBJ_CYCLE_DEF:     u16 = 3;
pub const SCAMPER_FILE_OBJ_CYCLE_STOP:    u16 = 4;
pub const SCAMPER_FILE_OBJ_ADDR:          u16 = 5;
pub const SCAMPER_FILE_OBJ_TRACE:         u16 = 6;
pub const SCAMPER_FILE_OBJ_PING:          u16 = 7;
pub const SCAMPER_FILE_OBJ_TRACELB:       u16 = 8;
pub const SCAMPER_FILE_OBJ_DEALIAS:       u16 = 9;
pub const SCAMPER_FILE_OBJ_NEIGHBOURDISC: u16 = 10;
pub const SCAMPER_FILE_OBJ_TBIT:          u16 = 11;
pub const SCAMPER_FILE_OBJ_STING:         u16 = 12;
pub const SCAMPER_FILE_OBJ_SNIFF:         u16 = 13;
pub const SCAMPER_FILE_OBJ_HOST:          u16 = 14;
pub const SCAMPER_FILE_OBJ_HTTP:          u16 = 15;
pub const SCAMPER_FILE_OBJ_UDPPROBE:      u16 = 16;
pub const SCAMPER_FILE_OBJ_OWAMP:         u16 = 17;

pub type ScamperFileReadfuncT =
    unsafe extern "C" fn(param: *mut c_void, data: *mut *mut u8, len: size_t) -> c_int;

unsafe extern "C" {
    pub fn scamper_file_open(
        filename: *const c_char,
        mode: c_char,
        ftype: *const c_char,
    ) -> *mut ScamperFileT;
    pub fn scamper_file_opennull(mode: c_char, ftype: *const c_char) -> *mut ScamperFileT;
    pub fn scamper_file_type_tostr(
        sf: *mut ScamperFileT,
        buf: *mut c_char,
        len: size_t,
    ) -> *mut c_char;
    pub fn scamper_file_close(sf: *mut ScamperFileT);
    pub fn scamper_file_getfilename(sf: *mut ScamperFileT) -> *mut c_char;
    pub fn scamper_file_read(
        sf: *mut ScamperFileT,
        filter: *const ScamperFileFilterT,
        obj_type: *mut u16,
        obj_data: *mut *mut c_void,
    ) -> c_int;
    pub fn scamper_file_setreadfunc(
        sf: *mut ScamperFileT,
        param: *mut c_void,
        readfunc: ScamperFileReadfuncT,
    );

    pub fn scamper_file_filter_alloc(
        types: *const u16,
        num: u16,
    ) -> *mut ScamperFileFilterT;
    pub fn scamper_file_filter_free(filter: *mut ScamperFileFilterT);

    pub fn scamper_file_readbuf_alloc() -> *mut ScamperFileReadbufT;
    pub fn scamper_file_readbuf_add(
        rb: *mut ScamperFileReadbufT,
        data: *const c_void,
        len: size_t,
    ) -> c_int;
    pub fn scamper_file_readbuf_free(rb: *mut ScamperFileReadbufT);
    pub fn scamper_file_readbuf_read(
        param: *mut c_void,
        data: *mut *mut u8,
        len: size_t,
    ) -> c_int;

    pub fn scamper_file_write_obj(
        sf: *mut ScamperFileT,
        o_type: u16,
        o_data: *mut c_void,
    ) -> c_int;
}