rscamper 0.2.2

Rust interface to scamper network measurement tool
Documentation
// rscamper - Rust FFI bindings for scamper_ping.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, size_t, timeval};
use super::scamper_addr::ScamperAddrT;
use super::scamper_list::{ScamperListT, ScamperCycleT};

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

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

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

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

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

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

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

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

pub const SCAMPER_PING_STOP_NONE:       u8 = 0;
pub const SCAMPER_PING_STOP_COMPLETED:  u8 = 1;
pub const SCAMPER_PING_STOP_ERROR:      u8 = 2;
pub const SCAMPER_PING_STOP_HALTED:     u8 = 3;
pub const SCAMPER_PING_STOP_INPROGRESS: u8 = 4;

pub const SCAMPER_PING_REPLY_FLAG_REPLY_TTL:  u32 = 0x01;
pub const SCAMPER_PING_REPLY_FLAG_REPLY_IPID: u32 = 0x02;
pub const SCAMPER_PING_REPLY_FLAG_PROBE_IPID: u32 = 0x04;

unsafe extern "C" {
    pub fn scamper_ping_tojson(ping: *const ScamperPingT, l: *mut size_t) -> *mut c_char;
    pub fn scamper_ping_totext(ping: *const ScamperPingT, l: *mut size_t) -> *mut c_char;
    pub fn scamper_ping_free(ping: *mut ScamperPingT);

    pub fn scamper_ping_list_get(ping: *const ScamperPingT) -> *mut ScamperListT;
    pub fn scamper_ping_cycle_get(ping: *const ScamperPingT) -> *mut ScamperCycleT;
    pub fn scamper_ping_userid_get(ping: *const ScamperPingT) -> u32;
    pub fn scamper_ping_dst_get(ping: *const ScamperPingT) -> *mut ScamperAddrT;
    pub fn scamper_ping_src_get(ping: *const ScamperPingT) -> *mut ScamperAddrT;
    pub fn scamper_ping_rtr_get(ping: *const ScamperPingT) -> *mut ScamperAddrT;
    pub fn scamper_ping_start_get(ping: *const ScamperPingT) -> *const timeval;
    pub fn scamper_ping_stop_reason_get(ping: *const ScamperPingT) -> u8;
    pub fn scamper_ping_stop_data_get(ping: *const ScamperPingT) -> u8;
    pub fn scamper_ping_stop_tostr(
        ping: *const ScamperPingT,
        buf: *mut c_char,
        len: size_t,
    ) -> *mut c_char;
    pub fn scamper_ping_data_get(ping: *const ScamperPingT) -> *const u8;
    pub fn scamper_ping_datalen_get(ping: *const ScamperPingT) -> u16;
    pub fn scamper_ping_attempts_get(ping: *const ScamperPingT) -> u16;
    pub fn scamper_ping_pktsize_get(ping: *const ScamperPingT) -> u16;
    pub fn scamper_ping_method_get(ping: *const ScamperPingT) -> u8;
    pub fn scamper_ping_method_tostr(
        ping: *const ScamperPingT,
        buf: *mut c_char,
        len: size_t,
    ) -> *mut c_char;
    pub fn scamper_ping_errmsg_get(ping: *const ScamperPingT) -> *const c_char;
    pub fn scamper_ping_method_is_icmp(ping: *const ScamperPingT) -> c_int;
    pub fn scamper_ping_method_is_icmp_time(ping: *const ScamperPingT) -> c_int;
    pub fn scamper_ping_method_is_tcp(ping: *const ScamperPingT) -> c_int;
    pub fn scamper_ping_method_is_tcp_ack_sport(ping: *const ScamperPingT) -> c_int;
    pub fn scamper_ping_method_is_udp(ping: *const ScamperPingT) -> c_int;
    pub fn scamper_ping_method_is_vary_sport(ping: *const ScamperPingT) -> c_int;
    pub fn scamper_ping_method_is_vary_dport(ping: *const ScamperPingT) -> c_int;
    pub fn scamper_ping_wait_probe_get(ping: *const ScamperPingT) -> *const timeval;
    pub fn scamper_ping_wait_timeout_get(ping: *const ScamperPingT) -> *const timeval;
    pub fn scamper_ping_ttl_get(ping: *const ScamperPingT) -> u8;
    pub fn scamper_ping_tos_get(ping: *const ScamperPingT) -> u8;
    pub fn scamper_ping_sport_get(ping: *const ScamperPingT) -> u16;
    pub fn scamper_ping_dport_get(ping: *const ScamperPingT) -> u16;
    pub fn scamper_ping_icmpsum_get(ping: *const ScamperPingT) -> u16;
    pub fn scamper_ping_tcpseq_get(ping: *const ScamperPingT) -> u32;
    pub fn scamper_ping_tcpack_get(ping: *const ScamperPingT) -> u32;
    pub fn scamper_ping_tsps_get(ping: *const ScamperPingT) -> *mut ScamperPingV4tsT;
    pub fn scamper_ping_flags_get(ping: *const ScamperPingT) -> u32;
    pub fn scamper_ping_stop_count_get(ping: *const ScamperPingT) -> u16;
    pub fn scamper_ping_pmtu_get(ping: *const ScamperPingT) -> u16;
    pub fn scamper_ping_sent_get(ping: *const ScamperPingT) -> u16;
    pub fn scamper_ping_probe_get(
        ping: *const ScamperPingT,
        i: u16,
    ) -> *mut ScamperPingProbeT;

    pub fn scamper_ping_probe_free(probe: *mut ScamperPingProbeT);
    pub fn scamper_ping_probe_use(probe: *mut ScamperPingProbeT) -> *mut ScamperPingProbeT;
    pub fn scamper_ping_probe_id_get(probe: *const ScamperPingProbeT) -> u16;
    pub fn scamper_ping_probe_ipid_get(probe: *const ScamperPingProbeT) -> u16;
    pub fn scamper_ping_probe_flags_get(probe: *const ScamperPingProbeT) -> u32;
    pub fn scamper_ping_probe_tx_get(probe: *const ScamperPingProbeT) -> *const timeval;
    pub fn scamper_ping_probe_reply_get(
        probe: *const ScamperPingProbeT,
        i: u16,
    ) -> *mut ScamperPingReplyT;

    pub fn scamper_ping_reply_free(reply: *mut ScamperPingReplyT);
    pub fn scamper_ping_reply_use(reply: *mut ScamperPingReplyT) -> *mut ScamperPingReplyT;
    pub fn scamper_ping_reply_is_from_target(
        ping: *const ScamperPingT,
        reply: *const ScamperPingReplyT,
    ) -> c_int;
    pub fn scamper_ping_reply_addr_get(reply: *const ScamperPingReplyT) -> *mut ScamperAddrT;
    pub fn scamper_ping_reply_proto_get(reply: *const ScamperPingReplyT) -> u8;
    pub fn scamper_ping_reply_ttl_get(reply: *const ScamperPingReplyT) -> u8;
    pub fn scamper_ping_reply_size_get(reply: *const ScamperPingReplyT) -> u16;
    pub fn scamper_ping_reply_ipid_get(reply: *const ScamperPingReplyT) -> u16;
    pub fn scamper_ping_reply_ipid32_get(reply: *const ScamperPingReplyT) -> u32;
    pub fn scamper_ping_reply_flags_get(reply: *const ScamperPingReplyT) -> u32;
    pub fn scamper_ping_reply_flag_is_reply_ipid(reply: *const ScamperPingReplyT) -> c_int;
    pub fn scamper_ping_reply_icmp_type_get(reply: *const ScamperPingReplyT) -> u8;
    pub fn scamper_ping_reply_icmp_code_get(reply: *const ScamperPingReplyT) -> u8;
    pub fn scamper_ping_reply_icmp_nhmtu_get(reply: *const ScamperPingReplyT) -> u16;
    pub fn scamper_ping_reply_tcp_flags_get(reply: *const ScamperPingReplyT) -> u8;
    pub fn scamper_ping_reply_is_icmp(reply: *const ScamperPingReplyT) -> c_int;
    pub fn scamper_ping_reply_is_tcp(reply: *const ScamperPingReplyT) -> c_int;
    pub fn scamper_ping_reply_is_udp(reply: *const ScamperPingReplyT) -> c_int;
    pub fn scamper_ping_reply_is_icmp_echo_reply(reply: *const ScamperPingReplyT) -> c_int;
    pub fn scamper_ping_reply_is_icmp_unreach(reply: *const ScamperPingReplyT) -> c_int;
    pub fn scamper_ping_reply_is_icmp_unreach_port(reply: *const ScamperPingReplyT) -> c_int;
    pub fn scamper_ping_reply_is_icmp_ttl_exp(reply: *const ScamperPingReplyT) -> c_int;
    pub fn scamper_ping_reply_is_icmp_tsreply(reply: *const ScamperPingReplyT) -> c_int;
    pub fn scamper_ping_reply_is_icmp_ptb(reply: *const ScamperPingReplyT) -> c_int;
    pub fn scamper_ping_reply_rtt_get(reply: *const ScamperPingReplyT) -> *const timeval;
    pub fn scamper_ping_reply_v4rr_get(
        reply: *const ScamperPingReplyT,
    ) -> *mut ScamperPingReplyV4rrT;
    pub fn scamper_ping_reply_v4ts_get(
        reply: *const ScamperPingReplyT,
    ) -> *mut ScamperPingReplyV4tsT;
    pub fn scamper_ping_reply_tsreply_get(
        reply: *const ScamperPingReplyT,
    ) -> *mut ScamperPingReplyTsreplyT;
    pub fn scamper_ping_reply_ifname_get(reply: *const ScamperPingReplyT) -> *const c_char;

    pub fn scamper_ping_reply_tsreply_free(tsr: *mut ScamperPingReplyTsreplyT);
    pub fn scamper_ping_reply_tsreply_tso_get(tsr: *const ScamperPingReplyTsreplyT) -> u32;
    pub fn scamper_ping_reply_tsreply_tsr_get(tsr: *const ScamperPingReplyTsreplyT) -> u32;
    pub fn scamper_ping_reply_tsreply_tst_get(tsr: *const ScamperPingReplyTsreplyT) -> u32;

    pub fn scamper_ping_reply_v4rr_free(rr: *mut ScamperPingReplyV4rrT);
    pub fn scamper_ping_reply_v4rr_ipc_get(rr: *const ScamperPingReplyV4rrT) -> u8;
    pub fn scamper_ping_reply_v4rr_ip_get(
        rr: *const ScamperPingReplyV4rrT,
        i: u8,
    ) -> *mut ScamperAddrT;

    pub fn scamper_ping_reply_v4ts_free(ts: *mut ScamperPingReplyV4tsT);
    pub fn scamper_ping_reply_v4ts_tsc_get(ts: *const ScamperPingReplyV4tsT) -> u8;
    pub fn scamper_ping_reply_v4ts_ts_get(ts: *const ScamperPingReplyV4tsT, i: u8) -> u32;
    pub fn scamper_ping_reply_v4ts_hasip(ts: *const ScamperPingReplyV4tsT) -> c_int;
    pub fn scamper_ping_reply_v4ts_ip_get(
        ts: *const ScamperPingReplyV4tsT,
        i: u8,
    ) -> *mut ScamperAddrT;

    pub fn scamper_ping_v4ts_free(ts: *mut ScamperPingV4tsT);
    pub fn scamper_ping_v4ts_ipc_get(ts: *const ScamperPingV4tsT) -> u8;
    pub fn scamper_ping_v4ts_ip_get(ts: *const ScamperPingV4tsT, i: u8) -> *mut ScamperAddrT;

    pub fn scamper_ping_stats_alloc(ping: *const ScamperPingT) -> *mut ScamperPingStatsT;
    pub fn scamper_ping_stats_free(stats: *mut ScamperPingStatsT);
    pub fn scamper_ping_stats_nreplies_get(stats: *const ScamperPingStatsT) -> u32;
    pub fn scamper_ping_stats_ndups_get(stats: *const ScamperPingStatsT) -> u32;
    pub fn scamper_ping_stats_nloss_get(stats: *const ScamperPingStatsT) -> u32;
    pub fn scamper_ping_stats_nerrs_get(stats: *const ScamperPingStatsT) -> u32;
    pub fn scamper_ping_stats_min_rtt_get(stats: *const ScamperPingStatsT) -> *const timeval;
    pub fn scamper_ping_stats_max_rtt_get(stats: *const ScamperPingStatsT) -> *const timeval;
    pub fn scamper_ping_stats_avg_rtt_get(stats: *const ScamperPingStatsT) -> *const timeval;
    pub fn scamper_ping_stats_stddev_rtt_get(stats: *const ScamperPingStatsT) -> *const timeval;
}