Add hostname command implemenation #1
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This PR adds a partial Rust implementation of the
hostname
command from net-tools as the first utility. The following options have been implemented:--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 ofunsafe
blocksThere are two unsafe blocks in the code, both for NIS domain operations, which are
getdomainname
andsetdomainname
. Thenix
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, butnix
doesn't provide them (unlikegethostname
which does have a safe wrapper)Each unsafe block has a SAFETY comment, and I've added
undocumented_unsafe_blocks = "warn"
to theCargo.toml
fileAlso, 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