Create initial skeleton
This commit is contained in:
commit
ea3483263d
|
@ -0,0 +1,3 @@
|
|||
/build
|
||||
/target
|
||||
/Cargo.lock
|
|
@ -0,0 +1,20 @@
|
|||
cmake_minimum_required(VERSION 3.23)
|
||||
|
||||
project(nss_malcontent
|
||||
DESCRIPTION ""
|
||||
VERSION 0.1.0
|
||||
LANGUAGES C)
|
||||
|
||||
include(FetchContent)
|
||||
FetchContent_Declare(
|
||||
Corrosion
|
||||
GIT_REPOSITORY https://github.com/corrosion-rs/corrosion.git
|
||||
GIT_TAG v0.2.1
|
||||
)
|
||||
|
||||
set(Rust_TOOLCHAIN nightly)
|
||||
FetchContent_MakeAvailable(Corrosion)
|
||||
corrosion_import_crate(MANIFEST_PATH Cargo.toml)
|
||||
|
||||
get_target_property(corrosion_install_libraries malcontent-nss INTERFACE_LINK_LIBRARIES)
|
||||
install(IMPORTED_RUNTIME_ARTIFACTS ${corrosion_install_libraries})
|
|
@ -0,0 +1,18 @@
|
|||
[package]
|
||||
name = "malcontent-nss"
|
||||
version = "0.1.0"
|
||||
edition = "2021"
|
||||
authors = ["Matteo Settenvini <matteo.settenvini@montecristosoftware.eu"]
|
||||
|
||||
[lib]
|
||||
crate-type = ["cdylib"]
|
||||
|
||||
[build-dependencies.bindgen]
|
||||
version = "0.60"
|
||||
|
||||
[dependencies.libc]
|
||||
version = "0.2"
|
||||
|
||||
[dependencies.nix]
|
||||
version = "0.24"
|
||||
features = []
|
|
@ -0,0 +1,20 @@
|
|||
extern crate bindgen;
|
||||
|
||||
use {std::env, std::path::PathBuf};
|
||||
|
||||
fn main() {
|
||||
println!("cargo:rerun-if-changed=wrapper.h");
|
||||
let bindings = bindgen::Builder::default()
|
||||
.header("wrapper.h")
|
||||
.parse_callbacks(Box::new(bindgen::CargoCallbacks))
|
||||
.newtype_enum("nss_status")
|
||||
.allowlist_type("nss_status")
|
||||
.allowlist_type("gaih_addrtuple")
|
||||
.generate()
|
||||
.expect("Unable to generate bindings");
|
||||
|
||||
let out_path = PathBuf::from(env::var("OUT_DIR").unwrap());
|
||||
bindings
|
||||
.write_to_file(out_path.join("bindings.rs"))
|
||||
.expect("Couldn't write bindings!");
|
||||
}
|
|
@ -0,0 +1,5 @@
|
|||
#![allow(non_upper_case_globals)]
|
||||
#![allow(non_camel_case_types)]
|
||||
#![allow(non_snake_case)]
|
||||
|
||||
mod nss_api;
|
|
@ -0,0 +1,123 @@
|
|||
include!(concat!(env!("OUT_DIR"), "/bindings.rs"));
|
||||
|
||||
use {
|
||||
core::ffi::{c_char, c_int, c_void},
|
||||
libc::{hostent, size_t, socklen_t, AF_INET},
|
||||
std::ptr,
|
||||
};
|
||||
|
||||
// -------------- by host ---------------
|
||||
|
||||
#[no_mangle]
|
||||
pub extern "C" fn _nss_malcontent_gethostbyname4_r(
|
||||
name: *const c_char,
|
||||
pat: *mut *mut gaih_addrtuple,
|
||||
buffer: *mut c_char,
|
||||
buflen: size_t,
|
||||
errnop: *mut c_int,
|
||||
h_errnop: *mut c_int,
|
||||
ttlp: *mut i32,
|
||||
) -> nss_status {
|
||||
todo!()
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
pub extern "C" fn _nss_malcontent_gethostbyname3_r(
|
||||
name: *const c_char,
|
||||
af: c_int,
|
||||
host: *mut hostent,
|
||||
buffer: *mut c_char,
|
||||
buflen: size_t,
|
||||
errnop: *mut c_int,
|
||||
h_errnop: *mut c_int,
|
||||
ttlp: *mut i32,
|
||||
canonp: *mut *mut char,
|
||||
) -> nss_status {
|
||||
todo!()
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
pub extern "C" fn _nss_malcontent_gethostbyname2_r(
|
||||
name: *const c_char,
|
||||
af: c_int,
|
||||
host: *mut hostent,
|
||||
buffer: *mut c_char,
|
||||
buflen: size_t,
|
||||
errnop: *mut c_int,
|
||||
h_errnop: *mut c_int,
|
||||
) -> nss_status {
|
||||
_nss_malcontent_gethostbyname3_r(
|
||||
name,
|
||||
af,
|
||||
host,
|
||||
buffer,
|
||||
buflen,
|
||||
errnop,
|
||||
h_errnop,
|
||||
ptr::null_mut(),
|
||||
ptr::null_mut(),
|
||||
)
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
pub extern "C" fn _nss_malcontent_gethostbyname_r(
|
||||
name: *const c_char,
|
||||
host: *mut hostent,
|
||||
buffer: *mut c_char,
|
||||
buflen: size_t,
|
||||
errnop: *mut c_int,
|
||||
h_errnop: *mut c_int,
|
||||
) -> nss_status {
|
||||
_nss_malcontent_gethostbyname3_r(
|
||||
name,
|
||||
AF_INET,
|
||||
host,
|
||||
buffer,
|
||||
buflen,
|
||||
errnop,
|
||||
h_errnop,
|
||||
ptr::null_mut(),
|
||||
ptr::null_mut(),
|
||||
)
|
||||
}
|
||||
|
||||
// ----------------- by addr -----------------
|
||||
|
||||
#[no_mangle]
|
||||
pub extern "C" fn _nss_malcontent_gethostbyaddr2_r(
|
||||
addr: *const c_void,
|
||||
len: socklen_t,
|
||||
af: c_int,
|
||||
host: *mut hostent,
|
||||
buffer: *mut c_char,
|
||||
buflen: size_t,
|
||||
errnop: *mut c_int,
|
||||
h_errnop: *mut c_int,
|
||||
ttlp: *mut i32,
|
||||
) -> nss_status {
|
||||
todo!()
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
pub extern "C" fn _nss_malcontent_gethostbyaddr_r(
|
||||
addr: *const c_void,
|
||||
len: socklen_t,
|
||||
af: c_int,
|
||||
host: *mut hostent,
|
||||
buffer: *mut c_char,
|
||||
buflen: size_t,
|
||||
errnop: *mut c_int,
|
||||
h_errnop: *mut c_int,
|
||||
) -> nss_status {
|
||||
_nss_malcontent_gethostbyaddr2_r(
|
||||
addr,
|
||||
len,
|
||||
af,
|
||||
host,
|
||||
buffer,
|
||||
buflen,
|
||||
errnop,
|
||||
h_errnop,
|
||||
ptr::null_mut(),
|
||||
)
|
||||
}
|
Loading…
Reference in New Issue