Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

std: net: Add function to return the system hostname #135141

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

orowith2os
Copy link

@orowith2os orowith2os commented Jan 6, 2025

Resolves rust-lang/libs-team#330
Tracking issue: #135142

Now you can retrieve the system hostname, without relying on anything other than std!

This is my first pull request to the Rust standard library (or anything inside rust-lang/rust, period, quite possible rust-lang itself), so there are bound to be issues. I'll try my best to resolve them.

@rustbot
Copy link
Collaborator

rustbot commented Jan 6, 2025

Thanks for the pull request, and welcome! The Rust team is excited to review your changes, and you should hear from @joboet (or someone else) some time within the next two weeks.

Please see the contribution instructions for more information. Namely, in order to ensure the minimum review times lag, PR authors and assigned reviewers should ensure that the review label (S-waiting-on-review and S-waiting-on-author) stays updated, invoking these commands when appropriate:

  • @rustbot author: the review is finished, PR author should check the comments and take action accordingly
  • @rustbot review: the author is ready for a review, this PR will be queued again in the reviewer's queue

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-libs Relevant to the library team, which will review and decide on the PR/issue. labels Jan 6, 2025
@rust-log-analyzer

This comment has been minimized.

@rustbot rustbot added has-merge-commits PR has merge commits, merge with caution. S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Jan 6, 2025
@rustbot

This comment has been minimized.

@rust-log-analyzer

This comment has been minimized.

@rustbot

This comment has been minimized.

@rust-log-analyzer

This comment has been minimized.

@orowith2os orowith2os force-pushed the std-net-gethostname branch from 64aec6c to 2748acd Compare January 6, 2025 01:02
@rustbot rustbot removed has-merge-commits PR has merge commits, merge with caution. S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Jan 6, 2025
@orowith2os
Copy link
Author

forgive all the updates, I was having troubles updating my branch properly. Figured it out.

@rust-log-analyzer

This comment has been minimized.

@orowith2os orowith2os force-pushed the std-net-gethostname branch from 2748acd to a6af22f Compare January 6, 2025 01:11
@rust-log-analyzer

This comment has been minimized.

@orowith2os orowith2os force-pushed the std-net-gethostname branch from a6af22f to 518f66c Compare January 6, 2025 01:39
@rust-log-analyzer

This comment has been minimized.

@orowith2os orowith2os force-pushed the std-net-gethostname branch 2 times, most recently from b942cde to 2cfa066 Compare January 6, 2025 01:54
@rust-log-analyzer

This comment has been minimized.

@orowith2os orowith2os force-pushed the std-net-gethostname branch from 2cfa066 to 9761a27 Compare January 6, 2025 02:17
@rust-log-analyzer

This comment has been minimized.

@orowith2os orowith2os force-pushed the std-net-gethostname branch 2 times, most recently from ff9bb72 to 141870c Compare January 6, 2025 02:32
@rust-log-analyzer

This comment has been minimized.

Copy link
Member

@ChrisDenton ChrisDenton left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The code looks fine. Note though that Windows 7 doesn't have GetHostNameW so it'd need. a fallback, However, it's also tier 3 so can be left to a follow up by the target maintainer.

// always enough.
let mut buffer = [0; 256];
// SAFETY: these parameters specify a valid, writable region of memory.
let ret = unsafe { c::GetHostNameW(buffer.as_mut_ptr(), buffer.len() as i32) };
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess my one nitpick is that maybe the max buffer len could be a constant instead of using as i32, which is often a code smell but in this case it's narrowly scoped enough that I don't feel strongly about it.

@valaphee
Copy link

valaphee commented Jan 27, 2025

Didn't know that there is a dedicated GetHostName function in WSA, would have expected GetComputerNameExW. Implemented since Windows 2000, and doesn't require WS2 init.

joboet added a commit to joboet/rust that referenced this pull request Feb 2, 2025
As per rust-lang#117276, this PR moves `sys_common::net` and the `sys::pal::net` into the newly created `sys::net` module. In order to support rust-lang#135141, I've moved all the current network code into a separate `connection` module, future functions like `hostname` can live in separate modules.

I'll probably do a follow-up PR and clean up some of the actual code, this is mostly just a reorganization.
joboet added a commit to joboet/rust that referenced this pull request Feb 2, 2025
As per rust-lang#117276, this PR moves `sys_common::net` and the `sys::pal::net` into the newly created `sys::net` module. In order to support rust-lang#135141, I've moved all the current network code into a separate `connection` module, future functions like `hostname` can live in separate modules.

I'll probably do a follow-up PR and clean up some of the actual code, this is mostly just a reorganization.
jieyouxu added a commit to jieyouxu/rust that referenced this pull request Feb 5, 2025
std: move network code into `sys`

As per rust-lang#117276, this PR moves `sys_common::net` and the `sys::pal::net` into the newly created `sys::net` module. In order to support rust-lang#135141, I've moved all the current network code into a separate `connection` module, future functions like `hostname` can live in separate modules.

I'll probably do a follow-up PR and clean up some of the actual code, this is mostly just a reorganization.
jieyouxu added a commit to jieyouxu/rust that referenced this pull request Feb 5, 2025
std: move network code into `sys`

As per rust-lang#117276, this PR moves `sys_common::net` and the `sys::pal::net` into the newly created `sys::net` module. In order to support rust-lang#135141, I've moved all the current network code into a separate `connection` module, future functions like `hostname` can live in separate modules.

I'll probably do a follow-up PR and clean up some of the actual code, this is mostly just a reorganization.
jieyouxu added a commit to jieyouxu/rust that referenced this pull request Feb 5, 2025
std: move network code into `sys`

As per rust-lang#117276, this PR moves `sys_common::net` and the `sys::pal::net` into the newly created `sys::net` module. In order to support rust-lang#135141, I've moved all the current network code into a separate `connection` module, future functions like `hostname` can live in separate modules.

I'll probably do a follow-up PR and clean up some of the actual code, this is mostly just a reorganization.
rust-timer added a commit to rust-lang-ci/rust that referenced this pull request Feb 6, 2025
Rollup merge of rust-lang#136449 - joboet:move_pal_net, r=ChrisDenton

std: move network code into `sys`

As per rust-lang#117276, this PR moves `sys_common::net` and the `sys::pal::net` into the newly created `sys::net` module. In order to support rust-lang#135141, I've moved all the current network code into a separate `connection` module, future functions like `hostname` can live in separate modules.

I'll probably do a follow-up PR and clean up some of the actual code, this is mostly just a reorganization.
@bors
Copy link
Contributor

bors commented Feb 6, 2025

☔ The latest upstream changes (presumably #136572) made this pull request unmergeable. Please resolve the merge conflicts.

@ChrisDenton
Copy link
Member

This needs to be rebased but then I think it'll be good to be merged.

github-actions bot pushed a commit to tautschnig/verify-rust-std that referenced this pull request Feb 20, 2025
As per rust-lang#117276, this PR moves `sys_common::net` and the `sys::pal::net` into the newly created `sys::net` module. In order to support rust-lang#135141, I've moved all the current network code into a separate `connection` module, future functions like `hostname` can live in separate modules.

I'll probably do a follow-up PR and clean up some of the actual code, this is mostly just a reorganization.
github-actions bot pushed a commit to tautschnig/verify-rust-std that referenced this pull request Feb 20, 2025
As per rust-lang#117276, this PR moves `sys_common::net` and the `sys::pal::net` into the newly created `sys::net` module. In order to support rust-lang#135141, I've moved all the current network code into a separate `connection` module, future functions like `hostname` can live in separate modules.

I'll probably do a follow-up PR and clean up some of the actual code, this is mostly just a reorganization.
github-actions bot pushed a commit to carolynzech/rust that referenced this pull request Feb 20, 2025
As per rust-lang#117276, this PR moves `sys_common::net` and the `sys::pal::net` into the newly created `sys::net` module. In order to support rust-lang#135141, I've moved all the current network code into a separate `connection` module, future functions like `hostname` can live in separate modules.

I'll probably do a follow-up PR and clean up some of the actual code, this is mostly just a reorganization.
github-actions bot pushed a commit to model-checking/verify-rust-std that referenced this pull request Feb 20, 2025
As per rust-lang#117276, this PR moves `sys_common::net` and the `sys::pal::net` into the newly created `sys::net` module. In order to support rust-lang#135141, I've moved all the current network code into a separate `connection` module, future functions like `hostname` can live in separate modules.

I'll probably do a follow-up PR and clean up some of the actual code, this is mostly just a reorganization.
github-actions bot pushed a commit to thanhnguyen-aws/verify-rust-std that referenced this pull request Feb 21, 2025
As per rust-lang#117276, this PR moves `sys_common::net` and the `sys::pal::net` into the newly created `sys::net` module. In order to support rust-lang#135141, I've moved all the current network code into a separate `connection` module, future functions like `hostname` can live in separate modules.

I'll probably do a follow-up PR and clean up some of the actual code, this is mostly just a reorganization.
github-actions bot pushed a commit to thanhnguyen-aws/verify-rust-std that referenced this pull request Feb 21, 2025
As per rust-lang#117276, this PR moves `sys_common::net` and the `sys::pal::net` into the newly created `sys::net` module. In order to support rust-lang#135141, I've moved all the current network code into a separate `connection` module, future functions like `hostname` can live in separate modules.

I'll probably do a follow-up PR and clean up some of the actual code, this is mostly just a reorganization.
github-actions bot pushed a commit to model-checking/verify-rust-std that referenced this pull request Feb 22, 2025
As per rust-lang#117276, this PR moves `sys_common::net` and the `sys::pal::net` into the newly created `sys::net` module. In order to support rust-lang#135141, I've moved all the current network code into a separate `connection` module, future functions like `hostname` can live in separate modules.

I'll probably do a follow-up PR and clean up some of the actual code, this is mostly just a reorganization.
github-actions bot pushed a commit to carolynzech/rust that referenced this pull request Feb 22, 2025
As per rust-lang#117276, this PR moves `sys_common::net` and the `sys::pal::net` into the newly created `sys::net` module. In order to support rust-lang#135141, I've moved all the current network code into a separate `connection` module, future functions like `hostname` can live in separate modules.

I'll probably do a follow-up PR and clean up some of the actual code, this is mostly just a reorganization.
github-actions bot pushed a commit to tautschnig/verify-rust-std that referenced this pull request Feb 22, 2025
As per rust-lang#117276, this PR moves `sys_common::net` and the `sys::pal::net` into the newly created `sys::net` module. In order to support rust-lang#135141, I've moved all the current network code into a separate `connection` module, future functions like `hostname` can live in separate modules.

I'll probably do a follow-up PR and clean up some of the actual code, this is mostly just a reorganization.
github-actions bot pushed a commit to thanhnguyen-aws/verify-rust-std that referenced this pull request Feb 22, 2025
As per rust-lang#117276, this PR moves `sys_common::net` and the `sys::pal::net` into the newly created `sys::net` module. In order to support rust-lang#135141, I've moved all the current network code into a separate `connection` module, future functions like `hostname` can live in separate modules.

I'll probably do a follow-up PR and clean up some of the actual code, this is mostly just a reorganization.
github-actions bot pushed a commit to thanhnguyen-aws/verify-rust-std that referenced this pull request Mar 3, 2025
As per rust-lang#117276, this PR moves `sys_common::net` and the `sys::pal::net` into the newly created `sys::net` module. In order to support rust-lang#135141, I've moved all the current network code into a separate `connection` module, future functions like `hostname` can live in separate modules.

I'll probably do a follow-up PR and clean up some of the actual code, this is mostly just a reorganization.
github-actions bot pushed a commit to carolynzech/rust that referenced this pull request Mar 4, 2025
As per rust-lang#117276, this PR moves `sys_common::net` and the `sys::pal::net` into the newly created `sys::net` module. In order to support rust-lang#135141, I've moved all the current network code into a separate `connection` module, future functions like `hostname` can live in separate modules.

I'll probably do a follow-up PR and clean up some of the actual code, this is mostly just a reorganization.
github-actions bot pushed a commit to carolynzech/rust that referenced this pull request Mar 4, 2025
As per rust-lang#117276, this PR moves `sys_common::net` and the `sys::pal::net` into the newly created `sys::net` module. In order to support rust-lang#135141, I've moved all the current network code into a separate `connection` module, future functions like `hostname` can live in separate modules.

I'll probably do a follow-up PR and clean up some of the actual code, this is mostly just a reorganization.
github-actions bot pushed a commit to thanhnguyen-aws/verify-rust-std that referenced this pull request Mar 4, 2025
As per rust-lang#117276, this PR moves `sys_common::net` and the `sys::pal::net` into the newly created `sys::net` module. In order to support rust-lang#135141, I've moved all the current network code into a separate `connection` module, future functions like `hostname` can live in separate modules.

I'll probably do a follow-up PR and clean up some of the actual code, this is mostly just a reorganization.
github-actions bot pushed a commit to tautschnig/verify-rust-std that referenced this pull request Mar 6, 2025
As per rust-lang#117276, this PR moves `sys_common::net` and the `sys::pal::net` into the newly created `sys::net` module. In order to support rust-lang#135141, I've moved all the current network code into a separate `connection` module, future functions like `hostname` can live in separate modules.

I'll probably do a follow-up PR and clean up some of the actual code, this is mostly just a reorganization.
github-actions bot pushed a commit to thanhnguyen-aws/verify-rust-std that referenced this pull request Mar 6, 2025
As per rust-lang#117276, this PR moves `sys_common::net` and the `sys::pal::net` into the newly created `sys::net` module. In order to support rust-lang#135141, I've moved all the current network code into a separate `connection` module, future functions like `hostname` can live in separate modules.

I'll probably do a follow-up PR and clean up some of the actual code, this is mostly just a reorganization.
github-actions bot pushed a commit to tautschnig/verify-rust-std that referenced this pull request Mar 11, 2025
As per rust-lang#117276, this PR moves `sys_common::net` and the `sys::pal::net` into the newly created `sys::net` module. In order to support rust-lang#135141, I've moved all the current network code into a separate `connection` module, future functions like `hostname` can live in separate modules.

I'll probably do a follow-up PR and clean up some of the actual code, this is mostly just a reorganization.
github-actions bot pushed a commit to tautschnig/verify-rust-std that referenced this pull request Mar 11, 2025
std: move network code into `sys`

As per rust-lang#117276, this PR moves `sys_common::net` and the `sys::pal::net` into the newly created `sys::net` module. In order to support rust-lang#135141, I've moved all the current network code into a separate `connection` module, future functions like `hostname` can live in separate modules.

I'll probably do a follow-up PR and clean up some of the actual code, this is mostly just a reorganization.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-meta Area: Issues & PRs about the rust-lang/rust repository itself A-run-make Area: port run-make Makefiles to rmake.rs O-unix Operating system: Unix-like O-windows Operating system: Windows S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-libs Relevant to the library team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add net::hostname to retrieve the devices host name