MCPcopy Index your code
hub / github.com/RustPython/RustPython / inet_pton

Function inet_pton

crates/stdlib/src/socket.rs:2961–2979  ·  view source on GitHub ↗
(af_inet: i32, ip_string: PyUtf8StrRef, vm: &VirtualMachine)

Source from the content-addressed store, hash-verified

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> {

Callers 2

testIPv4toStringMethod · 0.90
testIPv6toStringMethod · 0.90

Calls 5

to_vecMethod · 0.80
new_os_errorMethod · 0.80
ErrClass · 0.50
as_strMethod · 0.45
to_ownedMethod · 0.45

Tested by 2

testIPv4toStringMethod · 0.72
testIPv6toStringMethod · 0.72