Skip to content

Commit a1c2066

Browse files
committed
hostname: add command implemenation
1 parent a19ba37 commit a1c2066

File tree

7 files changed

+789
-3
lines changed

7 files changed

+789
-3
lines changed

Cargo.lock

Lines changed: 326 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,17 @@ authors = [
99
license = "MIT"
1010

1111
[dependencies]
12+
clap = { version = "4.5", features = ["derive"] }
13+
libc = "0.2"
14+
nix = { version = "0.30", features = ["hostname", "net"] }
15+
thiserror = "2.0"
16+
17+
[[bin]]
18+
name = "hostname"
19+
path = "bin/hostname.rs"
20+
21+
[lints.rust]
22+
unsafe_op_in_unsafe_fn = { level = "deny" }
23+
24+
[lints.clippy]
25+
undocumented_unsafe_blocks = "warn"

bin/hostname.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
fn main() {
2+
net_tools_rs::hostname_main();
3+
}

src/error.rs

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
use std::io;
2+
use thiserror::Error;
3+
4+
#[derive(Error, Debug)]
5+
pub enum NetToolsError {
6+
#[error("IO error: {0}")]
7+
Io(#[from] io::Error),
8+
9+
#[error("System error: {0}")]
10+
Nix(#[from] nix::errno::Errno),
11+
12+
#[error("Invalid argument: {0}")]
13+
InvalidArgument(String),
14+
15+
#[error("Permission denied: {0}")]
16+
PermissionDenied(String),
17+
18+
#[error("Not found: {0}")]
19+
NotFound(String),
20+
21+
#[error("Name too long: {0}")]
22+
NameTooLong(String),
23+
24+
#[error("Protocol family not supported")]
25+
ProtocolNotSupported,
26+
27+
#[error("{0}")]
28+
Other(String),
29+
}
30+
31+
pub type Result<T> = std::result::Result<T, NetToolsError>;

0 commit comments

Comments
 (0)