Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ipv6 on windows, debugging large alloc #23

Merged
merged 8 commits into from
Jan 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/CI.yml
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ jobs:
- uses: messense/maturin-action@v1
with:
command: build
args: --release -o dist --universal2
args: --release -o dist
- uses: actions/setup-python@v4
with:
python-version: |
Expand Down
44 changes: 38 additions & 6 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 6 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ edition = "2021"
name = "netifaces"
crate-type = ["cdylib"]

[dependencies]
thiserror = "1.0.51"

[target.'cfg(windows)'.dependencies]
windows = { version = "0.42.0", features = [
"Data_Xml_Dom",
Expand All @@ -21,9 +24,9 @@ windows = { version = "0.42.0", features = [
"Win32_NetworkManagement_IpHelper",
"Win32_Networking"] }

[target.'cfg(unix)'.dependencies]
nix = { version = "0.25.0" }

[dependencies.pyo3]
version = "0.17.1"
features = ["extension-module", "abi3-py37"]

[target.'cfg(unix)'.dependencies]
nix = { version = "0.25.0" }
52 changes: 27 additions & 25 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[build-system]
requires = ["maturin>=0.14,<0.15"]
requires = ["maturin>=1.4.0"]
build-backend = "maturin"

[project]
Expand All @@ -8,23 +8,23 @@ description = "Portable network interface information"
version = "0.0.20"
requires-python = ">=3.7"
readme = "README.md"
license = {file = "LICENSE"}
license = { file = "LICENSE" }
dependencies = ['typing-extensions']
classifiers = [
"Programming Language :: Rust",
"Programming Language :: Python :: Implementation :: CPython",
"Programming Language :: Python :: Implementation :: PyPy",
"License :: OSI Approved :: MIT License",
"Operating System :: POSIX :: Linux",
"Operating System :: MacOS",
"Operating System :: Microsoft :: Windows",
"Topic :: System :: Networking"
"Programming Language :: Rust",
"Programming Language :: Python :: Implementation :: CPython",
"Programming Language :: Python :: Implementation :: PyPy",
"License :: OSI Approved :: MIT License",
"Operating System :: POSIX :: Linux",
"Operating System :: MacOS",
"Operating System :: Microsoft :: Windows",
"Topic :: System :: Networking"
]
authors = [
{name = "Samuel Yvon", email = "[email protected]"}
{ name = "Samuel Yvon", email = "[email protected]" }
]
maintainers = [
{name = "Samuel Yvon", email = "[email protected]"}
{ name = "Samuel Yvon", email = "[email protected]" }
]

[project.urls]
Expand All @@ -33,22 +33,24 @@ Issues = "https://github.com/SamuelYvon/netifaces-2/issues"

[project.optional-dependencies]
dev = [
"mypy >= 0.991",
"black >= 23.1.0",
"ruff >= 0.0.240",
"pytest >= 7.1.1"
"mypy >= 0.991",
"black >= 23.1.0",
"ruff >= 0.0.240",
"pytest >= 7.1.1"
]

[tool.black]
target-version = ["py311", "py310", "py39", "py38", "py37"]

[tool.maturin]
python-source = "python"
module-name = "netifaces"
bindings = "pyo3"

[tool.mypy]
python_version = "3.7"
exclude = ['venv/.*/*\.py$']
strict=true
strict = true

[[tool.mypy.overrides]]
module = 'netifaces.netifaces'
Expand All @@ -58,14 +60,14 @@ ignore_missing_imports = true
src = ["netifaces"]
target-version = "py37"
select = [
"B", # flake8-bugbear
"C4", # flake8-comprehensions
"E", # pycodestyle
"F", # pyflakes
"W", # pycodestyle
"RUF", # ruff
"I", # isort
"PT", # flake8-pytest-style
"B", # flake8-bugbear
"C4", # flake8-comprehensions
"E", # pycodestyle
"F", # pyflakes
"W", # pycodestyle
"RUF", # ruff
"I", # isort
"PT", # flake8-pytest-style
]

[tool.coverage.report]
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
7 changes: 7 additions & 0 deletions src/common.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
use thiserror::Error;

#[derive(Debug, Error)]
pub enum NetifacesError {
#[error("Failed to use a system function (module {0}, error code {1})")]
SystemErrorCode(String, u32),
}
5 changes: 3 additions & 2 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ mod linux;
#[cfg(not(target_family = "windows"))]
use linux::{linux_ifaddresses as ifaddresses, linux_interfaces as interfaces};

mod common;
#[cfg(target_family = "windows")]
mod win;

Expand All @@ -40,11 +41,11 @@ pub fn ip_to_string(ip: u32) -> String {

/// Given the bytes that makes up a mac address, return the String
/// representation as it would be expected in the colloquial form.
pub fn mac_to_string(mac: &[u8; 6]) -> String {
pub fn mac_to_string(mac: &Vec<u8>) -> String {
let mut s = String::new();

for i in 0..mac.len() {
write!(&mut s, "{:X?}", mac[i]).unwrap();
write!(&mut s, "{:02X?}", mac[i]).unwrap();
if i + 1 < mac.len() {
s.push(':');
}
Expand Down
4 changes: 2 additions & 2 deletions src/linux.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ pub fn linux_interfaces() -> Result<Vec<String>, Box<dyn std::error::Error>> {
s.insert(addr.interface_name);
}

Ok(Vec::from_iter(s.into_iter()))
Ok(Vec::from_iter(s))
}

fn add_to_types_mat(
Expand All @@ -26,7 +26,7 @@ fn add_to_types_mat(
types_mat: &mut HashMap<i32, Vec<AddrPairs>>,
any: &mut bool,
) {
let e = types_mat.entry(af_class.into()).or_insert_with(Vec::new);
let e = types_mat.entry(af_class.into()).or_default();

if !*any {
*any = true;
Expand Down
Loading