| 2959 | |
| 2960 | #[pyfunction] |
| 2961 | fn inet_pton(af_inet: i32, ip_string: PyUtf8StrRef, vm: &VirtualMachine) -> PyResult<Vec<u8>> { |
| 2962 | static ERROR_MSG: &str = "illegal IP address string passed to inet_pton"; |
| 2963 | let ip_addr = match af_inet { |
| 2964 | c::AF_INET => ip_string |
| 2965 | .as_str() |
| 2966 | .parse::<Ipv4Addr>() |
| 2967 | .map_err(|_| vm.new_os_error(ERROR_MSG.to_owned()))? |
| 2968 | .octets() |
| 2969 | .to_vec(), |
| 2970 | c::AF_INET6 => ip_string |
| 2971 | .as_str() |
| 2972 | .parse::<Ipv6Addr>() |
| 2973 | .map_err(|_| vm.new_os_error(ERROR_MSG.to_owned()))? |
| 2974 | .octets() |
| 2975 | .to_vec(), |
| 2976 | _ => return Err(vm.new_os_error("Address family not supported by protocol".to_owned())), |
| 2977 | }; |
| 2978 | Ok(ip_addr) |
| 2979 | } |
| 2980 | |
| 2981 | #[pyfunction] |
| 2982 | fn inet_ntop(af_inet: i32, packed_ip: ArgBytesLike, vm: &VirtualMachine) -> PyResult<String> { |