Skip to content

Commit 694c029

Browse files
committed
0.2.0 (#2)
- Refactor `IfNet` and add `Ifv4Net`, `Ifv6Net`, `IfAddr`, `Ifv4Addr` and `Ifv6Addr` - Add `interface_addrs`, `interface_ipv4_addrs`, `interface_ipv6_addrs`, `interface_addrs_by_filter`, `interface_ipv4_addrs_by_filter`, and `interface_ipv6_addrs_by_filter` - Add `interface_multicast_addrs`, `interface_multicast_ipv4_addrs`, `interface_multicast_ipv6_addrs`, `interface_multicast_addrs_by_filter`, `interface_multcast_ipv4_addrs_by_filter` and `interface_multcast_ipv6_addrs_by_filter` - Add `gateway_addrs`, `gateway_ipv4_addrs`, `gateway_ipv6_addrs`, `gateway_addrs_by_filter`, `gateway_ipv4_addrs_by_filter` and `gateway_ipv6_addrs_by_filter` - Add `local_addrs`, `local_ipv4_addrs`, `local_ipv6_addrs`, `local_addrs_by_filter`, `local_ipv4_addrs_by_filter` and `local_ipv6_addrs_by_filter` - Add `private_addrs`, `private_ipv4_addrs`, `private_ipv6_addrs`, `private_addrs_by_filter`, `private_ipv4_addrs_by_filter`, `private_ipv6_addrs_by_filter` - Add `public_addrs`, `public_ipv4_addrs`, `public_ipv6_addrs`, `public_addrs_by_filter`, `public_ipv4_addrs_by_filter`, and `public_ipv6_addrs_by_filter` - Add `ifindex_to_name` and `ifname_to_index`
1 parent b8e273a commit 694c029

39 files changed

+3895
-694
lines changed

.codecov.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@ ignore:
55
- src/tests
66
- src/tests.rs
77
- tests
8+
- src/bsd_like # Ignore becasue cargo-tarpaulin does not support BSD-like OSes
9+
- src/bsd_like.rs # Ignore becasue cargo-tarpaulin does not support BSD-like OSes
10+
- examples/
811

912
coverage:
1013
status:

.github/workflows/coverage.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ jobs:
4646
- name: Run Coverage and Generate Report
4747
run: |
4848
mkdir -p coverage
49-
cargo tarpaulin --tests --avoid-cfg-tarpaulin --skip-clean --exclude-files "target/*" --out xml --output-dir coverage/${{ matrix.os }} -j 1
49+
cargo tarpaulin --run-types Doctests --run-types Tests --run-types Lib --out xml --output-dir coverage/${{ matrix.os }} -j 1
5050
continue-on-error: true
5151
- name: Upload Coverage Report as Artifact
5252
uses: actions/upload-artifact@v4

CHANGELOG.md

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,12 @@
1-
# UNRELEASED
2-
3-
# 0.1.2 (January 6th, 2022)
4-
5-
FEATURES
6-
7-
1+
# RELEASED
2+
3+
## 0.2.0 (January 19th, 2025)
4+
5+
- Refactor `IfNet` and add `Ifv4Net`, `Ifv6Net`, `IfAddr`, `Ifv4Addr` and `Ifv6Addr`
6+
- Add `interface_addrs`, `interface_ipv4_addrs`, `interface_ipv6_addrs`, `interface_addrs_by_filter`, `interface_ipv4_addrs_by_filter`, and `interface_ipv6_addrs_by_filter`
7+
- Add `interface_multicast_addrs`, `interface_multicast_ipv4_addrs`, `interface_multicast_ipv6_addrs`, `interface_multicast_addrs_by_filter`, `interface_multcast_ipv4_addrs_by_filter` and `interface_multcast_ipv6_addrs_by_filter`
8+
- Add `gateway_addrs`, `gateway_ipv4_addrs`, `gateway_ipv6_addrs`, `gateway_addrs_by_filter`, `gateway_ipv4_addrs_by_filter` and `gateway_ipv6_addrs_by_filter`
9+
- Add `local_addrs`, `local_ipv4_addrs`, `local_ipv6_addrs`, `local_addrs_by_filter`, `local_ipv4_addrs_by_filter` and `local_ipv6_addrs_by_filter`
10+
- Add `private_addrs`, `private_ipv4_addrs`, `private_ipv6_addrs`, `private_addrs_by_filter`, `private_ipv4_addrs_by_filter`, `private_ipv6_addrs_by_filter`
11+
- Add `public_addrs`, `public_ipv4_addrs`, `public_ipv6_addrs`, `public_addrs_by_filter`, `public_ipv4_addrs_by_filter`, and `public_ipv6_addrs_by_filter`
12+
- Add `ifindex_to_name` and `ifname_to_index`

Cargo.toml

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,25 @@ edition = "2021"
55
repository = "https://github.com/al8n/getifs"
66
homepage = "https://github.com/al8n/getifs"
77
documentation = "https://docs.rs/getifs"
8-
description = "Get network interfaces information (including MTU) in a fast way (say bye to `libc::getifaddrs`)."
8+
description = "Cross-platform network tools, a bunch of network tools for fetching interfaces, multicast addresses, local ip addresses, private ip addresses, public ip addresses and etc."
99
license = "MIT OR Apache-2.0"
1010
rust-version = "1.57.0"
1111
keywords = ["ifaddrs", "interface", "network-interface", "mtu", "getifaddrs"]
1212
categories = ["network-programming"]
1313

1414
[[bench]]
15-
path = "benches/bench.rs"
16-
name = "bench"
15+
path = "benches/interfaces.rs"
16+
name = "interfaces"
17+
harness = false
18+
19+
[[bench]]
20+
path = "benches/local_ip_address.rs"
21+
name = "local_ip_address"
22+
harness = false
23+
24+
[[bench]]
25+
path = "benches/gateway.rs"
26+
name = "gateway"
1727
harness = false
1828

1929
[features]
@@ -25,9 +35,13 @@ bitflags = "2"
2535
either = "1"
2636
hardware-address = "0.1"
2737
iprobe = "0.1"
38+
ipnet = "2"
39+
iprfc = "0.2"
40+
paste = "1"
2841
smol_str = "0.3"
2942
smallvec-wrapper = "0.2"
30-
ipnet = "2"
43+
triomphe = "0.1"
44+
3145

3246
# serde = { version = "1", features = ["derive"], optional = true }
3347

@@ -44,6 +58,7 @@ widestring = "1"
4458
[dev-dependencies]
4559
criterion = "0.5"
4660
network-interface = "2"
61+
local-ip-address = "0.6"
4762
which = "7"
4863
scopeguard = "1"
4964

README.md

Lines changed: 25 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
<div align="center">
2-
<h1>Get Interfaces</h1>
2+
<h1>GetIfs</h1>
33
</div>
44
<div align="center">
55

6-
Get network interfaces information (including MTU) in a fast way (say bye to `libc::getifaddrs`).
6+
Cross-platform network tools, a bunch of network tools for fetching interfaces, multicast addresses, local ip addresses, private ip addresses, public ip addresses and etc.
77

88
[<img alt="github" src="https://img.shields.io/badge/github-al8n/getifs-8da0cb?style=for-the-badge&logo=Github" height="22">][Github-url]
99
<img alt="LoC" src="https://img.shields.io/endpoint?url=https%3A%2F%2Fgist.githubusercontent.com%2Fal8n%2F327b2a8aef9003246e45c6e47fe63937%2Fraw%2Fgetifs" height="22">
@@ -17,26 +17,47 @@ Get network interfaces information (including MTU) in a fast way (say bye to `li
1717

1818
</div>
1919

20+
## Introduction
21+
22+
Cross-platform network tools, a bunch of network tools for fetching interfaces, multicast addresses, local ip addresses, private ip addresses, public ip addresses and etc.
23+
2024
## Installation
2125

2226
```toml
2327
[dependencies]
24-
getifs = "0.1"
28+
getifs = "0.2"
2529
```
2630

31+
## Examples
32+
33+
- Fetching all interfaces: [examples/interfaces.rs](./examples/interfaces.rs)
34+
- Fetching all interface addresses (excluding multicast addrs): [examples/addrs.rs](./examples/addrs.rs)
35+
- Fetching all interface multicast addresses: [exampels/multicast_addrs.rs](./examples/multicast_addrs.rs)
36+
- Fetching gateway addresses: [examples/gateway.rs](./examples/gateway.rs)
37+
- Fetching local ip addresses: [examples/local_ip_addrs.rs](./examples/local_ip_addrs.rs)
38+
- Fetching ip addresses by RFC: [examples/filter_by_rfc.rs](./examples/filter_by_rfc.rs)
39+
2740
## Details
2841

2942
OS | Approach
3043
--- | ---
3144
Linux | `socket(AF_NETLINK, SOCK_RAW \| SOCK_CLOEXEC, NETLINK_ROUTE)`
32-
BSD-based | Uses of `sysctl` to retrieve network interfaces
45+
BSD-like | `sysctl`
3346
Windows | `GetAdaptersAddresses`
3447

3548
## Why a new network interfaces crate?
3649

3750
Because all of current network interfaces crates do not support fetching `MTU`, and almost all of them are using `libc::getifaddrs`. This crate
3851
tries to avoid unneeded allocation and use more underlying method to achieve the same functionalities.
3952

53+
## Roadmap
54+
55+
- [ ] Support fetching routing tables (0.3.0)
56+
57+
## Pedigree
58+
59+
- The code in this crate is inspired by Golang's `interface.go` and [HashiCorp's go-sockaddr](https://github.com/hashicorp/go-sockaddr).
60+
4061
#### License
4162

4263
`getifs` is under the terms of both the MIT license and the
@@ -51,4 +72,3 @@ Copyright (c) 2025 Al Liu.
5172
[doc-url]: https://docs.rs/getifs
5273
[crates-url]: https://crates.io/crates/getifs
5374
[codecov-url]: https://app.codecov.io/gh/al8n/getifs/
54-
[zh-cn-url]: https://github.com/al8n/getifs/tree/main/README-zh_CN.md

benches/gateway.rs

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
use criterion::*;
2+
3+
fn bench_getifs_gateway_ipv4(c: &mut Criterion) {
4+
c.bench_function("getifs::gateway_ipv4_addrs", |b| {
5+
b.iter(|| {
6+
getifs::gateway_ipv4_addrs().unwrap();
7+
})
8+
});
9+
}
10+
11+
fn bench_getifs_gateway_ipv6(c: &mut Criterion) {
12+
c.bench_function("getifs::gateway_ipv6_addrs", |b| {
13+
b.iter(|| {
14+
getifs::gateway_ipv6_addrs().unwrap();
15+
})
16+
});
17+
}
18+
19+
criterion_group!(
20+
benches,
21+
bench_getifs_gateway_ipv4,
22+
bench_getifs_gateway_ipv6,
23+
);
24+
25+
criterion_main!(benches);
File renamed without changes.

benches/local_ip_address.rs

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
use criterion::*;
2+
3+
fn bench_getifs_local_ipv4(c: &mut Criterion) {
4+
c.bench_function("getifs::local_ipv4_addrs", |b| {
5+
b.iter(|| {
6+
getifs::local_ipv4_addrs().unwrap();
7+
})
8+
});
9+
}
10+
11+
fn bench_getifs_local_ipv6(c: &mut Criterion) {
12+
c.bench_function("getifs::local_ipv6_addrs", |b| {
13+
b.iter(|| {
14+
getifs::local_ipv6_addrs().unwrap();
15+
})
16+
});
17+
}
18+
19+
fn bench_local_ip_address_local_ipv4(c: &mut Criterion) {
20+
c.bench_function("local_ip_address::local_ip", |b| {
21+
b.iter(|| {
22+
local_ip_address::local_ip().unwrap();
23+
})
24+
});
25+
}
26+
27+
fn bench_local_ip_address_local_ipv6(c: &mut Criterion) {
28+
c.bench_function("local_ip_address::local_ipv6", |b| {
29+
b.iter(|| {
30+
local_ip_address::local_ipv6().unwrap();
31+
})
32+
});
33+
}
34+
35+
criterion_group!(
36+
benches,
37+
bench_getifs_local_ipv4,
38+
bench_getifs_local_ipv6,
39+
bench_local_ip_address_local_ipv4,
40+
bench_local_ip_address_local_ipv6,
41+
);
42+
43+
criterion_main!(benches);

ci/miri_sb.sh

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

ci/miri_tb.sh

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

examples/addrs.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
use getifs::interface_addrs;
2+
3+
fn main() {
4+
let addrs = interface_addrs().unwrap();
5+
for addr in addrs {
6+
println!("IP addr: {}", addr);
7+
}
8+
}

examples/filter_by_rfc.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
use getifs::{interface_addrs_by_filter, rfc};
2+
3+
fn main() {
4+
let addrs = interface_addrs_by_filter(|addr| rfc::RFC3330.contains(addr)).unwrap();
5+
for addr in addrs {
6+
println!("RFC3330 IP addr: {}", addr);
7+
}
8+
}

examples/foo.rs

Lines changed: 0 additions & 1 deletion
This file was deleted.

examples/gateway.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
use getifs::gateway_addrs;
2+
3+
fn main() {
4+
let gateways = gateway_addrs().unwrap();
5+
for gw in gateways {
6+
println!("Gateway: {}", gw);
7+
}
8+
}

examples/interfaces.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
use getifs::interfaces;
2+
3+
fn main() {
4+
let ift = interfaces().unwrap();
5+
for ifi in ift {
6+
println!("{:?}", ifi);
7+
}
8+
}

examples/local_ip_addrs.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
use getifs::local_addrs;
2+
3+
fn main() {
4+
let addrs = local_addrs().unwrap();
5+
for addr in addrs {
6+
println!("Local IP addr: {}", addr);
7+
}
8+
}

examples/multicast_addrs.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
use getifs::interface_multicast_addrs;
2+
3+
fn main() {
4+
let ift = interface_multicast_addrs().unwrap();
5+
for ifa in ift {
6+
println!("{}", ifa);
7+
}
8+
}

0 commit comments

Comments
 (0)