summary refs log tree commit diff
path: root/library/std/src/net
AgeCommit message (Collapse)AuthorLines
2021-04-16Add documentation to help people find `Ipv4Addr::UNSPECIFIED`Josh Triplett-0/+3
People looking for `INADDR_ANY` don't always find `Ipv4Addr::UNSPECIFIED`; add some documentation and an alias to help.
2021-04-05Rollup merge of #83831 - AngelicosPhosphoros:issue-77583-inline-for-ip, ↵Dylan DPC-0/+3
r=m-ou-se Add `#[inline]` to IpAddr methods Add some inlines to trivial methods of IpAddr Closes https://github.com/rust-lang/rust/issues/77583
2021-04-04Add `#[inline]` to IpAddr methodsAngelicosPhosphoros-0/+3
Add some inlines to trivial methods of IpAddr Closes https://github.com/rust-lang/rust/issues/77583
2021-04-04Rollup merge of #82487 - CDirkx:const-socketaddr, r=m-ou-seYuki Okushi-10/+20
Constify methods of `std::net::SocketAddr`, `SocketAddrV4` and `SocketAddrV6` The following methods are made unstable const under the `const_socketaddr` feature (https://github.com/rust-lang/rust/issues/82485): ```rust // std::net impl SocketAddr { pub const fn ip(&self) -> IpAddr; pub const fn port(&self) -> u16; pub const fn is_ipv4(&self) -> bool; pub const fn is_ipv6(&self) -> bool; } impl SocketAddrV4 { pub const fn ip(&self) -> IpAddr; pub const fn port(&self) -> u16; } impl SocketAddrV6 { pub const fn ip(&self) -> IpAddr; pub const fn port(&self) -> u16; pub const fn flowinfo(&self) -> u32; pub const fn scope_id(&self) -> u32; } ``` Note: `SocketAddrV4::ip` and `SocketAddrV6::ip` use pointer casting and depend on the unstable feature `const_raw_ptr_deref`
2021-03-30Disallow octal format in Ipv4 stringCheng XU-1/+23
In its original specification, leading zero in Ipv4 string is interpreted as octal literals. So a IP address 0127.0.0.1 actually means 87.0.0.1. This confusion can lead to many security vulnerabilities. Therefore, in [IETF RFC 6943], it suggests to disallow octal/hexadecimal format in Ipv4 string all together. Existing implementation already disallows hexadecimal numbers. This commit makes Parser reject octal numbers. Fixes #83648. [IETF RFC 6943]: https://tools.ietf.org/html/rfc6943#section-3.1.1
2021-03-26Document that the SocketAddr memory representation is not stableLinus Färnstrand-2/+8
2021-03-24Rollup merge of #83353 - m-ou-se:io-error-avoid-alloc, r=nagisaDylan DPC-2/+2
Add internal io::Error::new_const to avoid allocations. This makes it possible to have a io::Error containing a message with zero allocations, and uses that everywhere to avoid the *three* allocations involved in `io::Error::new(kind, "message")`. The function signature isn't perfect, because it needs a reference to the `&str`. So for now, this is just a `pub(crate)` function. Later, we'll be able to use `fn new_const<MSG: &'static str>(kind: ErrorKind)` to make that a bit better. (Then we'll also be able to use some ZST trickery if that would result in more efficient code.) See https://github.com/rust-lang/rust/issues/83352
2021-03-21Use io::Error::new_const everywhere to avoid allocations.Mara Bos-2/+2
2021-03-05(std::net::parser): Fix capitalization of IP versionspierwill-16/+16
Also add some missing punctuation in doc and code comments.
2021-02-24Constify methods of `std::net::SocketAddr`, `SocketAddrV4` and `SocketAddrV6`Christiaan Dirkx-10/+20
The following methods are made unstable const under the `const_socketaddr` feature: `SocketAddr` - `ip` - `port` - `is_ipv4` - `is_ipv6` `SocketAddrV4` - `ip` - `port` `SocketAddrV6` - `ip` - `port` - `flowinfo` - `scope_id`
2021-02-03add #[inline] to all the public IpAddr functionsBen Kimock-0/+69
2021-01-31Rollup merge of #81549 - est31:wording_fix, r=jonas-schievinkJonas Schievink-7/+7
Misc ip documentation fixes
2021-01-30Misc ip documentation fixesest31-7/+7
2021-01-20Dont prefix 0x when `dbg!(ipv6)`Lzu Tao-2/+5
2021-01-20Use slice::split_first instead of manuall slicingLzu Tao-2/+2
2020-12-19Auto merge of #79342 - CDirkx:ipaddr-const, r=oli-obkbors-22/+27
Stabilize all stable methods of `Ipv4Addr`, `Ipv6Addr` and `IpAddr` as const This PR stabilizes all currently stable methods of `Ipv4Addr`, `Ipv6Addr` and `IpAddr` as const. Tracking issue: #76205 `Ipv4Addr` (`const_ipv4`): - `octets` - `is_loopback` - `is_private` - `is_link_local` - `is_multicast` - `is_broadcast` - `is_docmentation` - `to_ipv6_compatible` - `to_ipv6_mapped` `Ipv6Addr` (`const_ipv6`): - `segments` - `is_unspecified` - `is_loopback` - `is_multicast` - `to_ipv4` `IpAddr` (`const_ip`): - `is_unspecified` - `is_loopback` - `is_multicast` ## Motivation The ip methods seem like prime candidates to be made const: their behavior is defined by an external spec, and based solely on the byte contents of an address. These methods have been made unstable const in the beginning of September, after the necessary const integer arithmetic was stabilized. There is currently a PR open (#78802) to change the internal representation of `IpAddr{4,6}` from `libc` types to a byte array. This does not have any impact on the constness of the methods. ## Implementation Most of the stabilizations are straightforward, with the exception of `Ipv6Addr::segments`, which uses the unstable feature `const_fn_transmute`. The code could be rewritten to equivalent stable code, but this leads to worse code generation (#75085). This is why `segments` gets marked with `#[rustc_allow_const_fn_unstable(const_fn_transmute)]`, like the already const-stable `Ipv6Addr::new`, the justification being that a const-stable alternative implementation exists https://github.com/rust-lang/rust/pull/76206#issuecomment-685044184. ## Future posibilities This PR const-stabilizes all currently stable ip methods, however there are also a number of unstable methods under the `ip` feature (#27709). These methods are already unstable const. There is a PR open (#76098) to stabilize those methods, which could include const-stabilization. However, stabilizing those methods as const is dependent on `Ipv4Addr::octets` and `Ipv6Addr::segments` (covered by this PR).
2020-11-27Stabilize all stable methods of `Ipv4Addr`, `Ipv6Addr` and `IpAddr` as constChristiaan Dirkx-22/+27
`Ipv4Addr` - `octets` - `is_loopback` - `is_private` - `is_link_local` - `is_multicast` - `is_broadcast` - `is_docmentation` - `to_ipv6_compatible` - `to_ipv6_mapped` `Ipv6Addr` - `segments` - `is_unspecified` - `is_loopback` - `is_multicast` - `to_ipv4` `IpAddr` - `is_unspecified` - `is_loopback` - `is_multicast`
2020-11-26Move const ip in ui test to unit testDaiki Ihara-0/+6
2020-11-23Auto merge of #78439 - lzutao:rm-clouldabi, r=Mark-Simulacrumbors-2/+2
Drop support for all cloudabi targets `cloudabi` is a tier-3 target, and [it is no longer being maintained upstream][no]. This PR drops supports for cloudabi targets. Those targets are: * aarch64-unknown-cloudabi * armv7-unknown-cloudabi * i686-unknown-cloudabi * x86_64-unknown-cloudabi Since this drops supports for a target, I'd like somebody to tag `relnotes` label to this PR. Some other issues: * The tidy exception for `cloudabi` crate is still remained because * `parking_lot v0.9.0` and `parking_lot v0.10.2` depends on `cloudabi v0.0.3`. * `parking_lot v0.11.0` depends on `cloudabi v0.1.0`. [no]: https://github.com/NuxiNL/cloudabi#note-this-project-is-unmaintained
2020-11-23Auto merge of #76226 - CDirkx:const-ipaddr, r=dtolnaybors-2/+4
Stabilize `IpAddr::is_ipv4` and `is_ipv6` as const Insta-stabilize the methods `is_ipv4` and `is_ipv6` of `std::net::IpAddr` as const, in the same way as [PR#76198](https://github.com/rust-lang/rust/pull/76198). Possible because of the recent stabilization of const control flow. Part of #76225 and #76205.
2020-11-23Bump version to 1.50.0Christiaan Dirkx-2/+2
2020-11-23Stabilize `IpAddr::is_ipv4` and `is_ipv6` as constChristiaan Dirkx-2/+4
Insta-stabilize the methods `is_ipv4` and `is_ipv6` of `IpAddr`. Possible because of the recent stabilization of const control flow. Also adds a test for these methods in a const context.
2020-11-22Drop support for cloudabi targetsLzu Tao-2/+2
2020-11-19Bump bootstrap compiler versionJake Goulding-2/+1
2020-10-25Rollup merge of #78208 - liketechnik:issue-69399, r=oli-obkYuki Okushi-1/+2
replace `#[allow_internal_unstable]` with `#[rustc_allow_const_fn_unstable]` for `const fn`s `#[allow_internal_unstable]` is currently used to side-step feature gate and stability checks. While it was originally only meant to be used only on macros, its use was expanded to `const fn`s. This pr adds stricter checks for the usage of `#[allow_internal_unstable]` (only on macros) and introduces the `#[rustc_allow_const_fn_unstable]` attribute for usage on `const fn`s. This pr does not change any of the functionality associated with the use of `#[allow_internal_unstable]` on macros or the usage of `#[rustc_allow_const_fn_unstable]` (instead of `#[allow_internal_unstable]`) on `const fn`s (see https://github.com/rust-lang/rust/issues/69399#issuecomment-712911540). Note: The check for `#[rustc_allow_const_fn_unstable]` currently only validates that the attribute is used on a function, because I don't know how I would check if the function is a `const fn` at the place of the check. I therefore openend this as a 'draft pull request'. Closes rust-lang/rust#69399 r? @oli-obk
2020-10-23Rollup merge of #77918 - wcampbell0x2a:cleanup-network-tests, r=m-ou-seYuki Okushi-10/+4
Cleanup network tests Some cleanup for network related tests
2020-10-21switch allow_internal_unstable const fns to rustc_allow_const_fn_unstableFlorian Warzecha-1/+2
2020-10-20Rollup merge of #77923 - wcampbell0x2a:cleanup-net-module, r=scottmcmYuki Okushi-8/+2
[net] apply clippy lints Applied helpful clippy lints to the network std library module.
2020-10-19Revert "[net] clippy: needless_update"wcampbell-0/+1
This reverts commit 058699d0a2fca02127761f014d0ecfce1c5541ec.
2020-10-18Remove redundant 'static from library cratesest31-1/+1
2020-10-13fmtwcampbell-1/+1
Signed-off-by: wcampbell <wcampbell1995@gmail.com>
2020-10-13use matches! in library/std/src/net/ip.rs wcampbell-4/+1
Apply suggestion from review Co-authored-by: LingMan <LingMan@users.noreply.github.com>
2020-10-13[net] clippy: identity_opwcampbell-4/+4
warning: the operation is ineffective. Consider reducing it to `self.segments()[0]` --> library/std/src/net/ip.rs:1265:9 | 1265 | (self.segments()[0] & 0xffff) == 0xfe80 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | = note: `#[warn(clippy::identity_op)]` on by default = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#identity_op warning: the operation is ineffective. Consider reducing it to `self.segments()[1]` --> library/std/src/net/ip.rs:1266:16 | 1266 | && (self.segments()[1] & 0xffff) == 0 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#identity_op warning: the operation is ineffective. Consider reducing it to `self.segments()[2]` --> library/std/src/net/ip.rs:1267:16 | 1267 | && (self.segments()[2] & 0xffff) == 0 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#identity_op warning: the operation is ineffective. Consider reducing it to `self.segments()[3]` --> library/std/src/net/ip.rs:1268:16 | 1268 | && (self.segments()[3] & 0xffff) == 0 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#identity_op Signed-off-by: wcampbell <wcampbell1995@gmail.com>
2020-10-13[net] clippy: match_like_matches_macrowcampbell-4/+1
warning: match expression looks like `matches!` macro --> library/std/src/net/ip.rs:459:9 | 459 | / match self.octets() { 460 | | [169, 254, ..] => true, 461 | | _ => false, 462 | | } | |_________^ help: try this: `matches!(self.octets(), [169, 254, ..])` | = note: `#[warn(clippy::match_like_matches_macro)]` on by default = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#match_like_matches_macro Signed-off-by: wcampbell <wcampbell1995@gmail.com>
2020-10-13[net] clippy: needless_updatewcampbell-1/+0
warning: struct update has no effect, all the fields in the struct have already been specified --> library/std/src/net/addr.rs:367:19 | 367 | ..unsafe { mem::zeroed() } | ^^^^^^^^^^^^^^^^^^^^^^^^ | = note: `#[warn(clippy::needless_update)]` on by default = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#needless_update
2020-10-13Use is_ok() instead of empty Ok(_)wcampbell-10/+4
Signed-off-by: wcampbell <wcampbell1995@gmail.com>
2020-10-06Parse SocketAddrV6::scope_idTamir Duberstein-4/+15
2020-10-06Avoid unused returnTamir Duberstein-9/+12
2020-10-06Rollup merge of #77528 - tamird:avoid-cast-net-parser, r=dtolnayYuki Okushi-36/+48
Avoid unchecked casts in net parser Once this and #77426 are in, I'll send another PR adding scope id parsing. r? @dtolnay
2020-10-04Inline "eof" methodsTamir Duberstein-13/+2
2020-10-04Avoid unchecked casts in net parserTamir Duberstein-23/+46
2020-10-04Include scope id in SocketAddrV6::DisplayTamir Duberstein-3/+19
2020-09-25Rollup merge of #76304 - CDirkx:const-ip, r=ecstatic-morseJonas Schievink-5/+29
Make delegation methods of `std::net::IpAddr` unstably const Make the following methods of `std::net::IpAddr` unstable const under the `const_ip` feature: - `is_unspecified` - `is_loopback` - `is_global` - `is_multicast` Also adds a test for these methods in a const context. Possible because these methods delegate to the inner `Ipv4Addr` or `Ipv6Addr`, which were made const ([PR#76205](https://github.com/rust-lang/rust/pull/76142) and [PR#76206](https://github.com/rust-lang/rust/pull/76206)), and the recent stabilization of const control flow. Part of #76205 r? @ecstatic-morse
2020-09-23Make delegation methods of `std::net::IpAddr` unstable constChristiaan Dirkx-5/+29
Make the following methods of `std::net::IpAddr` unstable const under the `const_ip` feature: - `is_unspecified` - `is_loopback` - `is_global` - `is_multicast` Also adds a test for these methods in a const context. Possible because these methods delegate to the inner `Ipv4Addr` or `Ipv6Addr`, which were made const, and the recent stabilization of const control flow. Part of #76205
2020-09-22Update library/std/src/net/addr.rsImbolc-1/+1
Co-authored-by: Ivan Tham <pickfire@riseup.net>
2020-09-22Update library/std/src/net/addr.rsImbolc-1/+1
Co-authored-by: Ivan Tham <pickfire@riseup.net>
2020-09-22Update addr.rsImbolc-1/+1
I little clarification
2020-09-03Make `Ipv4Addr` and `Ipv6Addr` const tests unit tests under `library`Christiaan Dirkx-0/+109
These tests are about the standard library, not the compiler itself, thus should live in `library`, see #76268.
2020-09-03Auto merge of #76235 - jyn514:std-intra-links, r=poliorceticsbors-46/+0
Convert many files to intra-doc links Helps with https://github.com/rust-lang/rust/issues/75080 r? @poliorcetics I recommend reviewing one commit at a time, but the diff is small enough you can do it all at once if you like :)
2020-09-03Rollup merge of #76142 - CDirkx:const-ip, r=ecstatic-morseDylan DPC-18/+38
Make all methods of `std::net::Ipv4Addr` const Make the following methods of `std::net::Ipv4Addr` unstable const under the `const_ipv4` feature: - `octets` - `is_loopback` - `is_private` - `is_link_local` - `is_global` (unstable) - `is_shared` (unstable) - `is_ietf_protocol_assignment` (unstable) - `is_benchmarking` (unstable) - `is_reserved` (unstable) - `is_multicast` - `is_broadcast` - `is_documentation` - `to_ipv6_compatible` - `to_ipv6_mapped` This would make all methods of `Ipv6Addr` const. Of these methods, `is_global`, `is_broadcast`, `to_ipv6_compatible`, and `to_ipv6_mapped` require a change in implementation. Part of #76205