Giter Site home page Giter Site logo

hostname's People

Contributors

fengcen avatar jd91mzm2 avatar mbrubeck avatar mokeyish avatar stoeckmann avatar svartalf avatar wackbyte avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

hostname's Issues

Add to get host-ip as well?

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?

Want to know more about this project

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?

Hostname on esp32

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

Avoidable, potential unsafety

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.

Breaking 0.2 changes plan

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.

  • Determine minimal supported Rust version — (set to 1.19.0)
  • Gather list of the supported OSes
  • Add CI builds (how to test Redox and various *nix'es?) — Linux, macOS and Windows are enabled already
  • Deprecate the get_hostname function
  • Add get() -> io::Result<OsString> function
  • Add set<T>(hostname: T) -> io::Result<()> where T: Into<OsStr> function (determine what exactly T should be)
  • Replace winutil dependency with the winapi crate
  • Use gethostname from the libc crate instead of bundled version
  • Add keywords, categories and badges seasoning to the Cargo manifest
  • Add more documentation and examples
  • Review API guidelines and make the public API great
  • Address the #6 issue

Hostname on esp32

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

Handing over crates.io name

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. 😄

wasix support

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...

Fetching FQDN?

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).

SetComputerNameExW missing NUL terminator

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.

Broken build on Windows because of loose versions in dependency tree

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."

Without `winapi`

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 are failing

   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.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.