diff --git a/vm/src/stdlib/socket.rs b/vm/src/stdlib/socket.rs index c8d2b381d..7eea1d507 100644 --- a/vm/src/stdlib/socket.rs +++ b/vm/src/stdlib/socket.rs @@ -579,6 +579,23 @@ fn socket_gethostbyaddr( )) } +#[cfg(not(target_os = "redox"))] +fn socket_gethostbyname(name: PyStringRef, vm: &VirtualMachine) -> PyResult { + match socket_gethostbyaddr(name, vm) { + Ok((_, _, hosts)) => { + let lst = vm.extract_elements::(&hosts)?; + Ok(lst.get(0).unwrap().to_string()) + } + Err(_) => { + let error_type = vm.class("_socket", "gaierror"); + Err(vm.new_exception_msg( + error_type, + "nodename nor servname provided, or not known".to_owned(), + )) + } + } +} + fn get_addr(vm: &VirtualMachine, addr: T) -> PyResult where T: ToSocketAddrs, @@ -707,6 +724,7 @@ pub fn make_module(vm: &VirtualMachine) -> PyObjectRef { extend_module!(vm, module, { "getaddrinfo" => ctx.new_function(socket_getaddrinfo), "gethostbyaddr" => ctx.new_function(socket_gethostbyaddr), + "gethostbyname" => ctx.new_function(socket_gethostbyname), }); extend_module_platform_specific(vm, &module);