Skip to content

Commit 43295af

Browse files
authored
Merge pull request #17 from ohadravid/chore/fix-ffi-and-libc
Fix ffi and libc related issues
2 parents 3ebf7a4 + 4f22fff commit 43295af

File tree

19 files changed

+193
-25811
lines changed

19 files changed

+193
-25811
lines changed

.github/workflows/ci.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ jobs:
2323
- uses: actions-rs/toolchain@v1
2424
with:
2525
profile: minimal
26-
toolchain: "1.69.0"
26+
toolchain: "1.82.0"
2727
default: true
2828

2929
- run: cargo test
@@ -37,5 +37,6 @@ jobs:
3737
- name: run cross build for iOS (on macOS)
3838
run: |
3939
cargo install cross
40+
rustup target add aarch64-apple-ios
4041
cross build --target aarch64-apple-ios
4142
if: matrix.os == 'macos-latest'

Cargo.toml

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
[package]
22
name = "netstat2"
3-
version = "0.9.1"
3+
version = "0.10.0"
44
authors = ["Ohad Ravid <ohad.rv@gmail.com>", "ivxvm <ivxvm@protonmail.com>"]
5-
edition = "2018"
5+
edition = "2021"
66
license = "MIT OR Apache-2.0"
77
readme = "README.md"
88
repository = "https://github.com/ohadravid/netstat2-rs"
@@ -15,8 +15,18 @@ Cross-platform library to retrieve network sockets information.
1515

1616
[dependencies]
1717
libc = "0.2"
18-
bitflags = "1.0"
19-
thiserror = "1"
18+
bitflags = "2"
19+
thiserror = "2"
20+
21+
[dev-dependencies]
22+
criterion = { version = "0.4" }
23+
24+
[[bench]]
25+
name = "get_sockets_info_benchmark"
26+
harness = false
27+
28+
[target.'cfg(any(target_os = "macos", target_os = "ios", target_os = "linux", target_os = "android"))'.build-dependencies]
29+
bindgen = "0.65"
2030

2131
[target.'cfg(any(target_os = "macos", target_os = "ios"))'.dependencies]
2232
num-derive = "0.3"

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ Provides unified interface and returns data structures which may have additional
1111
```toml
1212
# Cargo.toml
1313
[dependencies]
14-
netstat2 = "0.9"
14+
netstat2 = "0.10"
1515
```
1616

1717
This is a fork based on the [netstat](https://crates.io/crates/netstat) crate by [ivxvm](https://github.com/ivxvm).
Lines changed: 11 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,13 @@
1-
#![feature(test)]
1+
use criterion::{black_box, criterion_group, criterion_main, Criterion};
2+
use netstat2::*;
23

3-
extern crate test;
4-
5-
#[cfg(test)]
6-
mod tests {
7-
use netstat2::*;
8-
9-
#[bench]
10-
fn bench_new(b: &mut test::Bencher) {
11-
b.iter(|| {
12-
let af_flags = AddressFamilyFlags::IPV4 | AddressFamilyFlags::IPV6;
13-
let proto_flags = ProtocolFlags::TCP | ProtocolFlags::UDP;
14-
get_sockets_info(af_flags, proto_flags).unwrap();
15-
});
16-
}
4+
fn criterion_benchmark(c: &mut Criterion) {
5+
c.bench_function("get_sockets_info", |b| b.iter(|| {
6+
let af_flags = AddressFamilyFlags::IPV4 | AddressFamilyFlags::IPV6;
7+
let proto_flags = ProtocolFlags::TCP | ProtocolFlags::UDP;
8+
let _result = get_sockets_info(black_box(af_flags), proto_flags).unwrap();
9+
}));
1710
}
11+
12+
criterion_group!(benches, criterion_benchmark);
13+
criterion_main!(benches);

build.rs

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
use std::env;
2+
use std::path::Path;
3+
4+
#[cfg(any(target_os = "macos", target_os = "ios"))]
5+
fn main() {
6+
let bindings = bindgen::builder()
7+
.header_contents("libproc_rs.h", "#include <libproc.h>")
8+
.layout_tests(false)
9+
.clang_args(&["-x", "c++", "-I", "/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include/"])
10+
.generate()
11+
.expect("Failed to build libproc bindings");
12+
13+
let output_path = Path::new(&env::var("OUT_DIR")
14+
.expect("OUT_DIR env var was not defined"))
15+
.join("libproc_bindings.rs");
16+
17+
bindings
18+
.write_to_file(output_path)
19+
.expect("Failed to write libproc bindings");
20+
}
21+
22+
#[cfg(any(target_os = "linux", target_os = "android"))]
23+
fn main() {
24+
let bindings = bindgen::builder()
25+
.header_contents("linux_bindings.h", r#"
26+
#include <linux/sock_diag.h>
27+
#include <linux/inet_diag.h>
28+
#include <linux/rtnetlink.h>
29+
#include <linux/netlink.h>
30+
#include <linux/tcp.h>
31+
"#)
32+
.layout_tests(false)
33+
.generate()
34+
.expect("Failed to build linux bindings");
35+
36+
let output_path = Path::new(&env::var("OUT_DIR")
37+
.expect("OUT_DIR env var was not defined"))
38+
.join("linux_bindings.rs");
39+
40+
bindings
41+
.write_to_file(output_path)
42+
.expect("Failed to write linux bindings");
43+
}
44+
45+
#[cfg(target_os = "windows")]
46+
fn main() {}
47+
48+
#[cfg(not(any(target_os = "macos", target_os = "ios", target_os = "linux", target_os = "android", target_os = "windows")))]
49+
fn main() {}

cargo-linux.sh

Lines changed: 0 additions & 3 deletions
This file was deleted.

src/integrations/linux/ffi/enums.rs

Lines changed: 0 additions & 16 deletions
This file was deleted.

src/integrations/linux/ffi/mod.rs

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,4 @@
11
#[macro_use]
22
mod macros;
3-
mod enums;
4-
mod structs;
5-
mod types;
63

7-
pub use self::enums::*;
84
pub use self::macros::*;
9-
pub use self::structs::*;
10-
pub use self::types::*;

src/integrations/linux/ffi/structs.rs

Lines changed: 0 additions & 124 deletions
This file was deleted.

src/integrations/linux/ffi/types.rs

Lines changed: 0 additions & 17 deletions
This file was deleted.

0 commit comments

Comments
 (0)