Skip to content

Conversation

nadzyah
Copy link
Member

@nadzyah nadzyah commented Oct 11, 2025

This PR adds a partial Rust implementation of the hostname command from net-tools as the first utility. The following options have been implemented:

  • Basic get/set hostname functionality
  • --short - display short hostname (just the part before the first dot)
  • --domain - display DNS domain name (everything after the first dot)
  • --ip-address - resolve and display IP addresses for the hostname
  • --all-ip-addresses - display all IP addresses from all network interfaces
  • --yp, --nis - get/set NIS/YP domain name
  • --file - read hostname from a file
  • --verbose - verbose output (additional option)

The options of the original hostname command like --fqdn, --alias, --all-fqdns, and --boot have not been implemented yet because currently I haven't found a way to implement them without using a lot of unsafe blocks

There are two unsafe blocks in the code, both for NIS domain operations, which are getdomainname and setdomainname. The nix crate does not wrap these system calls. They are necessary for NIS/YP functionality and there's no safe Rust alternative. I tried to find safe wrappers, but nix doesn't provide them (unlike gethostname which does have a safe wrapper)
Each unsafe block has a SAFETY comment, and I've added undocumented_unsafe_blocks = "warn" to the Cargo.toml file

Also, since this command uses the original net-tools implementation as a reference, which is licensed under the copyleft licenseGPL-2+, I've changed the license of the project correspondingly and added the copyright notice for the original net-tools authors

@nadzyah nadzyah requested review from bdrung and lvoytek October 11, 2025 10:25
@nadzyah nadzyah changed the title hostname: add command implemenation Add hostname command implemenation Oct 11, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant