about summary refs log tree commit diff
path: root/library/std/src/net/ip.rs
AgeCommit message (Collapse)AuthorLines
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-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-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-03-30Disallow octal format in Ipv4 stringCheng XU-0/+2
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-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/+2
2021-01-20Use slice::split_first instead of manuall slicingLzu Tao-2/+2
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-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-19Bump bootstrap compiler versionJake Goulding-2/+1
2020-10-21switch allow_internal_unstable const fns to rustc_allow_const_fn_unstableFlorian Warzecha-1/+2
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-09-23Make delegation methods of `std::net::IpAddr` unstable constChristiaan Dirkx-5/+10
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-03Auto merge of #76235 - jyn514:std-intra-links, r=poliorceticsbors-42/+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
2020-09-02add a note for Ipv4Addr::to_ipv6_compatible南浦月-0/+3
2020-09-01Remove explicit links to `true` and `false` in ip.rsJoshua Nelson-42/+0
2020-09-01Make all remaining methods of `std::net::Ipv4Addr` constChristiaan Dirkx-9/+20
Makes the following methods of `std::net::Ipv4Addr` unstable const under the `const_ipv4` feature: - `is_global` - `is_reserved` - `is_broadcast` - `to_ipv6_compatible` - `to_ipv6_mapped` This results in all methods of `Ipv4Addr` being const. Also adds tests for these methods in a const context.
2020-09-01Change implementation of `Ipv6Addr::is_unspecified` and `is_loopback` from ↵CDirkx-2/+2
`matches!` to `u128` comparison Done because `matches!` doesn't optimize well with array comparisons
2020-09-01Make methods unstable const under `const_ipv4`CDirkx-9/+9
2020-09-01Make all methods of `std::net::Ipv6Addr` constCDirkx-16/+30
Make the following methods of `std::net::Ipv6Addr` unstable const under the `const_ipv6` feature: - `segments` - `is_unspecified` - `is_loopback` - `is_global` (unstable) - `is_unique_local` - `is_unicast_link_local_strict` - `is_documentation` - `multicast_scope` - `is_multicast` - `to_ipv4_mapped` - `to_ipv4` Changed the implementation of `is_unspecified` and `is_loopback` to use a `match` instead of `==`. Part of #76205
2020-08-31Make more Ipv4Addr methods constCDirkx-9/+18
Constify the following methods of `std::net::Ipv4Addr`: - `octets` - `is_loopback` - `is_private` - `is_link_local` - `is_shared` - `is_ietf_protocol_assignment` - `is_benchmarking` - `is_multicast` - `is_documentation` Also insta-stabilizes these methods as const. Possible because of the stabilization of const integer arithmetic and control flow.
2020-08-31std: move "mod tests/benches" to separate filesLzu Tao-859/+4
Also doing fmt inplace as requested.
2020-08-19Minor changes to Ipv4AddrLzu Tao-5/+10
* Impl IntoInner rather than AsInner for Ipv4Addr * Add some comments * Add test to show endiannes of Ipv4Addr display
2020-08-16Fix a link, improve method resolutionAlexis Bourget-24/+25
2020-08-15Move to intra doc links in std::netAlexis Bourget-75/+61
2020-08-14Rollup merge of #74409 - ↵Tyler Mandry-1/+8
LukasKalbertodt:improve-debug-impl-of-socketaddr-ipaddr, r=Amanieu Change Debug impl of SocketAddr and IpAddr to match their Display output This has already been done for `SocketAddrV4`, `SocketAddrV6`, `IpAddrV4` and `IpAddrV6`. I don't see a point to keep the rather bad to read derived impl, especially so when pretty printing: V4( 127.0.0.1 ) From the `Display`, one can easily and unambiguously see if it's V4 or V6. Two examples: ``` 127.0.0.1:443 [2001:db8:85a3::8a2e:370:7334]:443 ``` Luckily the docs explicitly state that `Debug` output is not stable and that it may be changed at any time. Using `Display` as `Debug` is very convenient for configuration structs (e.g. for webservers) that often just have a `derive(Debug)` and are printed that way to the one starting the server.
2020-08-12Auto merge of #75019 - nanpuyue:to_ipv4_mapped, r=LukasKalbertodtbors-0/+40
Add Ipv6Addr::to_ipv4_mapped * add Ipv6Addr::to_ipv4_mapped * ~~deprecate Ipv4Addr::to_ipv6_compatible & Ipv6Addr::to_ipv4~~ reference: #75150 According to [IETF RFC 4291](https://tools.ietf.org/html/rfc4291#page-10), the "IPv4-Compatible IPv6 address" is deprecated. > 2.5.5.1. IPv4-Compatible IPv6 Address > > The "IPv4-Compatible IPv6 address" was defined to assist in the IPv6 > transition. The format of the "IPv4-Compatible IPv6 address" is as > follows: > > | 80 bits | 16 | 32 bits | > +--------------------------------------+--------------------------+ > |0000..............................0000|0000| IPv4 address | > +--------------------------------------+----+---------------------+ > > Note: The IPv4 address used in the "IPv4-Compatible IPv6 address" > must be a globally-unique IPv4 unicast address. > > The "IPv4-Compatible IPv6 address" is now deprecated because the > current IPv6 transition mechanisms no longer use these addresses. > New or updated implementations are not required to support this > address type. And the current implementation of `Ipv4Addr::to_ipv6_compatible`is incorrect: it does not check whether the IPv4 address is a globally-unique IPv4 unicast address. Please let me know if there are any issues with this pull request.
2020-08-11prefer pattern matching over indexingLzu Tao-13/+10
2020-08-11add Ipv6Addr::to_ipv4_mapped南浦月-0/+40
2020-08-10Transmute between big endian `s6_addr` and `[u16; 8]`.Lzu Tao-27/+27
The old code already made the assumption to reinterpret `Ipv6Addr` as `[u16; 8]`. Glibc, Linux, FreeBSD, Win32 all makes this assumption. The main motivation of using union it to better optimize code. ref: * https://docs.microsoft.com/en-us/windows/win32/api/in6addr/ns-in6addr-in6_addr * https://github.com/freebsd/freebsd/blob/1d6e4247415d264485ee94b59fdbc12e0c566fd0/contrib/ntp/lib/isc/include/isc/ipv6.h#L63 * https://github.com/zephyrproject-rtos/zephyr/blob/8b531aa996bba254c03129658490af59597acd78/include/net/net_ip.h#L137 * https://sourceware.org/git/?p=glibc.git;a=blob;f=inet/netinet/in.h;h=f6355c7efe5192b88337b136ef687fe9a5ed648c;hb=HEAD#l216 Co-authored-by: Josh Stone <cuviper@gmail.com> Co-authored-by: Peter Atashian <retep998@gmail.com>
2020-08-07Rollup merge of #75179 - lzutao:unsed-ipv4-frominner, r=alexcrichtonYuki Okushi-5/+0
Remove unused FromInner impl for Ipv4Addr The removed is a unused unstable implementation.
2020-08-07Rollup merge of #75175 - lzutao:doctest-ipv4-fromu32, r=cuviperYuki Okushi-4/+4
Make doctests of Ipv4Addr::from(u32) easier to read There are many zeroes in `0x0d0c0b0au32` which makes it hard to read.
2020-08-05Remove unused FromInner impl for Ipv4AddrLzu Tao-5/+0
2020-08-05Make doctests of Ipv4Addr::from(u32) easier to readLzu Tao-4/+4
2020-08-05Use u32::from_ne_bytes to fix a FIXMELzu Tao-9/+3
Co-authored-by: Weiyi Wang <wwylele@gmail.com> Co-authored-by: Adam Reichold <adam.reichold@t-online.de> Co-authored-by: Josh Stone <cuviper@gmail.com> Co-authored-by: Scott McMurray <scottmcm@users.noreply.github.com> Co-authored-by: tmiasko <tomasz.miasko@gmail.com>
2020-07-28Add note to clearly mark the RFC as rejectedAlexis Bourget-0/+6
2020-07-28Remove links to rejected errata 4406 for RFC 4291Alexis Bourget-6/+0
2020-07-28Change Debug impl of SocketAddr and IpAddr to match their Display outputLukas Kalbertodt-1/+8
This has already been done for `SocketAddrV4`, `SocketAddrV6`, `IpAddrV4` and `IpAddrV6`. I don't see a point to keep the rather bad to read derived impl, especially when pretty printing: V4( 127.0.0.1 ) From the `Display`, one can easily and unambiguously see if it's V4 or V6. Using `Display` as `Debug` is very convenient for configuration structs (e.g. for webservers) that often just have a `derive(Debug)` and are printed that way to the user.
2020-07-27mv std libs to library/mark-0/+2731