1
0
mirror of https://github.com/jht5945/rust_util.git synced 2025-12-29 00:20:04 +08:00

refactor: ipv4_to_u32

This commit is contained in:
2020-09-19 20:07:49 +08:00
parent 89f45cc354
commit 20b452656e

View File

@@ -190,7 +190,8 @@ fn ipv4_mask(mask: u8) -> u32 {
} }
fn ipv4_to_u32(ipv4: &[u8; 4]) -> u32 { fn ipv4_to_u32(ipv4: &[u8; 4]) -> u32 {
((ipv4[0] as u32) << (8 * 3)) + ((ipv4[1] as u32) << (8 * 2)) + ((ipv4[2] as u32) << 8) + (ipv4[3] as u32) u32::from_be_bytes(*ipv4)
// ((ipv4[0] as u32) << (8 * 3)) + ((ipv4[1] as u32) << (8 * 2)) + ((ipv4[2] as u32) << 8) + (ipv4[3] as u32)
} }
fn parse_ipv4_addr(addr: &str) -> Option<[u8; 4]> { fn parse_ipv4_addr(addr: &str) -> Option<[u8; 4]> {