about summary refs log tree commit diff
path: root/library/std/src/net
AgeCommit message (Collapse)AuthorLines
2021-06-19Remove `Ipv4Addr::is_ietf_protocol_assignment`Christiaan Dirkx-51/+6
2021-06-18Add `IpAddr::is_benchmarking`Christiaan Dirkx-3/+36
2021-06-18Add `Ipv6Addr::is_benchmarking`Christiaan Dirkx-29/+67
2021-06-15Document IPv4-mapped and IPv4-compatible addresses.Christiaan Dirkx-14/+72
2021-06-15Rename ErrorKind::Unknown to Uncategorized.Mara Bos-1/+1
2021-06-15Redefine `ErrorKind::Other` and stop using it in std.Mara Bos-1/+1
2021-06-09Remove `is_unicast_site_local`Christiaan Dirkx-52/+1
2021-06-09Rollup merge of #85791 - CDirkx:is_unicast, r=joshtriplettYuki Okushi-1/+29
Add `Ipv6Addr::is_unicast` Adds an unstable utility method `Ipv6Addr::is_unicast` under the feature flag `ip` (tracking issue: #27709). Added for completeness with the other unicast methods (see also https://github.com/rust-lang/rust/issues/85604#issuecomment-848220455) and opposite of `is_multicast`.
2021-06-09Rollup merge of #85676 - CDirkx:ip-style, r=JohnTitorYuki Okushi-26/+26
Fix documentation style inconsistencies for IP addresses Pulled out of #85655 as it is unrelated. Fixes some inconsistencies in the docs for IP addresses: - Currently some addresses are backticked, some are not, this PR backticks everything consistently. (looks better imo) - Lowercase hex-literals are used when writing addresses.
2021-05-31Use `is_unicast` instead of ``!is_multicast`Christiaan Dirkx-1/+1
2021-05-31Add `Ipv6Addr::is_unicast`Christiaan Dirkx-0/+28
2021-05-30Remove `is_unicast_link_local_strict`Christiaan Dirkx-101/+27
2021-05-25Fix documentation style inconsistenciesChristiaan Dirkx-26/+26
2021-05-25Move stability attribute for methods under the `ip` feature from the module ↵Christiaan Dirkx-8/+17
to the methods themselves
2021-05-02Add link to Issue #34202 in udp docswcampbell-1/+3
Signed-off-by: wcampbell <wcampbell1995@gmail.com>
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