svartalf / hostname Goto Github PK
View Code? Open in Web Editor NEWCross-platform hostname functions in Rust
Home Page: https://crates.io/crates/hostname
License: MIT License
Cross-platform hostname functions in Rust
Home Page: https://crates.io/crates/hostname
License: MIT License
So in linux hostname command can also show the local ip via hostname -I
Looking at libc
code, you can clearly see the used gethostname
function, but I couldn't intuitively find the function for getting the local-ip only.
I'm aware that there is local-ip crate, but it's more of a hack using regex on ifconfig
and I doubt it's cross platform, it differs output with hostname -I
too. Is it appropriate to add the host-ip functionality here as well?
Hello, is this project still under maintenance? I would like to know the original idea of this project. Is it just to get and set the host name? Have you ever considered aligning the Linux hostname command function?
I'm working on a project in rust for esp32 and I get this error when I build the project.
Can anyone help me?
error[E0425]: cannot find value _SC_HOST_NAME_MAX
in crate libc
--> C:\Users\lpirc.cargo\registry\src\index.crates.io-6f17d22bba15001f\hostname-0.3.1\src\nix.rs:17:38
|
17 | unsafe { libc::sysconf(libc::_SC_HOST_NAME_MAX) as libc::size_t };
| ^^^^^^^^^^^^^^^^^ not found in libc
On Unix the function is potentially unsafe, depending on implementation choices made in the platform provided POSIX gethostname
function. In particular its documentation (man
page) reads:
If the null-terminated hostname is too large to fit, then the name is truncated, and no error is returned (but see NOTES below). POSIX.1-2001 says that if such truncation occurs, then it is unspecified whether the returned buffer includes a terminating null byte.
Although glibc
and Linux will both never return a successful non-nullterminated result, Apples documentation even directly specifies this possibility (edit: but doesn't seem to allow it in practice, see below). The configuration is, however, much more generic than those specific systems.
It would be safer to append a single NULL-byte manually in any case.
Since this crate is not abandoned anymore (yay!), it is time to make it a bit more modern and plan changes for the next 0.2
version.
1.19.0
)get_hostname
functionget() -> io::Result<OsString>
functionset<T>(hostname: T) -> io::Result<()> where T: Into<OsStr>
function (determine what exactly T
should be)winutil
dependency with the winapi
crategethostname
from the libc
crate instead of bundled versionhttps://docs.rs/crate/hostname/0.3.1 failed to build as of bc9b4bb due to error[E0658]: `#[doc(cfg)]` is experimental
.
Hi,
I'm trying to run it on cloudflare worker and I got the error:
error: Unsupported target OS! Create an issue: https://github.com/svartalf/hostname/issues/new
--> /home/xavier/.cargo/registry/src/github.com-1ecc6299db9ec823/hostname-0.3.1/src/lib.rs:81:9
|
81 | compile_error!("Unsupported target OS! Create an issue: https://github.com/svartalf/hostname/issues/new");
So here I am, creating an issue ;)
Hi,
I'm developing a xmpp client for esp32 using rust.
But I have problems with the dependencies, especially with this crate.
When I compile the project I get this error generated by the linker:
note: [ldproxy] Running ldproxy
Error: Linker C:/.embuild/espressif/tools/xtensa-esp32s3-elf/esp-2021r2-patch5-8.4.0/xtensa-esp32s3-elf/bin/xtensa-esp32s3-elf-gcc.exe failed: exit code: 1
STDERR OUTPUT:
c:/.embuild/espressif/tools/xtensa-esp32s3-elf/esp-2021r2-patch5-8.4.0/xtensa-esp32s3-elf/bin/../lib/gcc/xtensa-esp32s3-elf/8.4.0/../../../../xtensa-esp32s3-elf/bin/ld.exe: C:\S3WifiC\xtensa-esp32s3-espidf\debug\deps\libhostname-c83a955bc1dd5dc9.rlib(hostname-c83a955bc1dd5dc9.1wq21g0sr3imvl6y.rcgu.o):(.literal._ZN8hostname3nix3get17hbd00b343233444fcE+0x1c): undefined reference to `gethostname'
I'm trying to add esp-idf-sys::gethostname instead of libc::gethostname but I have been having a lot of difficulties due to lack of documentation
Would you be ok with handing over the hostname crate name?
This is a Github repo specifically made for this. You can, however, directly transfer ownership to @lunaryorn. He made some effort to stabilise the Windows implementation already. 😄
cargo wasix build
Compiling hostname v0.3.1
error: Unsupported target OS! Create an issue: https://github.com/svartalf/hostname/issues/new
--> /home/user/.cargo/registry/src/index.crates.io-6f17d22bba15001f/hostname-0.3.1/src/lib.rs:81:9
|
81 | compile_error!("Unsupported target OS! Create an issue: https://github.com/svartalf/hostname/issues/new");
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
error[E0433]: failed to resolve: use of undeclared crate or module `sys`
--> /home/user/.cargo/registry/src/index.crates.io-6f17d22bba15001f/hostname-0.3.1/src/lib.rs:105:5
|
105 | sys::get()
| ^^^ use of undeclared crate or module `sys`
For more information about this error, try `rustc --explain E0433`.
error: could not compile `hostname` (lib) due to 2 previous errors
warning: build failed, waiting for other jobs to finish...
Do you have plans for adding no_std support anytime soon? Thanks!
Thanks for this crate!
I was just wondering what you thought about adding a mechanism to fetch the fully qualified domain name (similar to hostname --fqdn
).
OsStr
is not a nul-terminated string. encode_wide()
doesn't add a terminator either. Therefore, SetComputerNameExW
may end up reading past the buffer.
pub fn set(hostname: &OsStr) -> io::Result<()> {
let buffer = hostname.encode_wide().collect::<Vec<_>>();
let result = unsafe {
sysinfoapi::SetComputerNameExW(
sysinfoapi::ComputerNamePhysicalDnsHostname,
buffer.as_ptr(),
)
};
It needs buffer.push(0)
before the winapi call.
Hi! Could the changes on master be released to crates.io? I'm interested in changes made by #18
The problem isn't directly in this crate, but will probably require a dependency version upgrade to be fixed.
This crate depends on winutil 0.1 that depends on versions of kernel32-sys and advapi32-sys that do not have version restrictions on the winapi crate. Now a new version of winapi has been published and that breaks the build chain. The fix is probably to upgrade the dependencies of winutil to depend on versions of kernel32-sys and advapi32-sys that fix the versions of winapi, but that will require this crate to upgrade its dependency on winutil.
I've notified the author of winutil to the problem and got the response "Thanks for the heads up, will take a look at fixing it when I get a minute. Might be a week or so."
I don't like having winapi
and all of its nested dependencies in the lock file.
Is it possible to ... not?
I am making a linux only program so it feels like it makes sense to me.
Doc-tests hostname
Running `/usr/bin/rustdoc --crate-type lib --test /home/brain/rpmbuild/BUILD/hostname-0.3.0/src/lib.rs --crate-name hostname -L dependency=/home/brain/rpmbuild/BUILD/hostname-0.3.0/target/release/deps -L dependency=/home/brain/rpmbuild/BUILD/hostname-0.3.0/target/release/deps --cfg 'feature="default"' --extern hostname=/home/brain/rpmbuild/BUILD/hostname-0.3.0/target/release/deps/libhostname-39f1b9d2526e0dbd.rlib --extern libc=/home/brain/rpmbuild/BUILD/hostname-0.3.0/target/release/deps/liblibc-a57c72450827c75f.rlib --extern match_cfg=/home/brain/rpmbuild/BUILD/hostname-0.3.0/target/release/deps/libmatch_cfg-f9e3034fabbadd5e.rlib --extern version_sync=/home/brain/rpmbuild/BUILD/hostname-0.3.0/target/release/deps/libversion_sync-0cf3986e57ef4972.rlib`
running 2 tests
test src/lib.rs - (line 7) ... FAILED
test src/lib.rs - get (line 68) ... ok
failures:
---- src/lib.rs - (line 7) stdout ----
error[E0425]: cannot find function `set` in crate `hostname`
--> src/lib.rs:11:11
|
6 | hostname::set("potato")?;
| ^^^ help: a function with a similar name exists: `get`
this is on Fedora Rawhide.
Details:
worked fine with 0.1. 5
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.