1#![cfg_attr(not(test), no_std)]
2
3#[cfg(target_arch = "aarch64")]
4use aarch64::inet_aton_impl;
5#[cfg(any(target_arch = "x86", target_arch = "x86_64"))]
6use x86::inet_aton_impl;
7
8#[must_use]
9pub fn inet_aton(str: &[u8]) -> Option<u32> {
11 unsafe { inet_aton_impl(str) }
12}
13
14mod aarch64;
15mod pattern;
16mod x86;
17
18#[cfg(test)]
19mod tests {
20
21 use std::{net::Ipv4Addr, str::FromStr};
22
23 use super::inet_aton;
24 use proptest::prelude::*;
25
26 prop_compose! {
27 fn ipv4_strategy()(v in prop::array::uniform4(any::<u8>())) -> String {
28 v.map(|x| x.to_string()).join(".")
29 }
30 }
31
32 proptest! {
33 #[test]
34 fn test_ip(ip in ipv4_strategy()) {
35 let left = inet_aton(ip.as_bytes()).map(u32::swap_bytes);
36 let right = Ipv4Addr::from_str(&ip).ok().map(Into::into);
37 assert_eq!(left, right);
38 }
39 }
40}