Skip to content

Commit

Permalink
Rollup merge of rust-lang#40590 - z1mvader:master, r=steveklabnik
Browse files Browse the repository at this point in the history
documented order of conversion between u32 an ipv4addr

This fixes rust-lang#40118
  • Loading branch information
frewsxcv authored Mar 18, 2017
2 parents 7387fd5 + 50cede0 commit a3aaa0e
Showing 1 changed file with 2 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/libstd/net/ip.rs
Original file line number Diff line number Diff line change
Expand Up @@ -636,6 +636,7 @@ impl FromInner<c::in_addr> for Ipv4Addr {

#[stable(feature = "ip_u32", since = "1.1.0")]
impl From<Ipv4Addr> for u32 {
/// It performs the conversion in network order (big-endian).
fn from(ip: Ipv4Addr) -> u32 {
let ip = ip.octets();
((ip[0] as u32) << 24) + ((ip[1] as u32) << 16) + ((ip[2] as u32) << 8) + (ip[3] as u32)
Expand All @@ -644,6 +645,7 @@ impl From<Ipv4Addr> for u32 {

#[stable(feature = "ip_u32", since = "1.1.0")]
impl From<u32> for Ipv4Addr {
/// It performs the conversion in network order (big-endian).
fn from(ip: u32) -> Ipv4Addr {
Ipv4Addr::new((ip >> 24) as u8, (ip >> 16) as u8, (ip >> 8) as u8, ip as u8)
}
Expand Down

0 comments on commit a3aaa0e

Please sign in to comment.