From e688d9c4d16395e0d62529d97fa7af4b47a230de Mon Sep 17 00:00:00 2001 From: thedarkula <thedarkula2049@gmail.com> Date: Tue, 4 Sep 2018 02:59:59 +0100 Subject: [PATCH] Updated url, implemented missing functions in header/arpa_inet/mod.rs --- src/header/arpa_inet/mod.rs | 67 ++++++++++++++++++++++++++++--------- 1 file changed, 51 insertions(+), 16 deletions(-) diff --git a/src/header/arpa_inet/mod.rs b/src/header/arpa_inet/mod.rs index 4a5a0476..d724860b 100644 --- a/src/header/arpa_inet/mod.rs +++ b/src/header/arpa_inet/mod.rs @@ -1,10 +1,10 @@ -//! arpa/inet implementation for Redox, following http://pubs.opengroup.org/onlinepubs/7908799/xsh/arpainet.h.html +//! arpa/inet implementation for Redox, following http://pubs.opengroup.org/onlinepubs/7908799/xns/arpainet.h.html use core::str::FromStr; use core::{ptr, slice, str}; use header::errno::*; -use header::netinet_in::{in_addr, in_addr_t}; +use header::netinet_in::{in_addr, in_addr_t, INADDR_NONE}; use header::sys_socket::constants::*; use header::sys_socket::socklen_t; use platform; @@ -99,27 +99,62 @@ pub unsafe extern "C" fn inet_ntop( } } -//#[no_mangle] +#[no_mangle] pub extern "C" fn inet_addr(cp: *const c_char) -> in_addr_t { - unimplemented!(); + let mut val: in_addr = in_addr { + s_addr: 0, + }; + + if unsafe { inet_aton(cp, &mut val) } > 0 { + val.s_addr + } else { + INADDR_NONE + } + } -//#[no_mangle] -pub extern "C" fn inet_lnaof(_in: in_addr) -> in_addr_t { - unimplemented!(); +#[no_mangle] +pub extern "C" fn inet_lnaof(input: in_addr) -> in_addr_t { + if input.s_addr>>24 < 128 { + input.s_addr & 0xffffff + } else if input.s_addr>>24 < 192 { + input.s_addr & 0xffff + } else { + input.s_addr & 0xff + } } -//#[no_mangle] -pub extern "C" fn inet_makeaddr(net: in_addr_t, lna: in_addr_t) -> in_addr { - unimplemented!(); +#[no_mangle] +pub extern "C" fn inet_makeaddr(net: in_addr_t, host: in_addr_t) -> in_addr { + let mut output: in_addr = in_addr { + s_addr: 0, + }; + + if net < 256 { + output.s_addr = host | net<<24; + } else if net < 65536 { + output.s_addr = host | net<<16; + } else { + output.s_addr = host | net<<8; + } + + output } -//#[no_mangle] -pub extern "C" fn inet_netof(_in: in_addr) -> in_addr_t { - unimplemented!(); +#[no_mangle] +pub extern "C" fn inet_netof(input: in_addr) -> in_addr_t { + if input.s_addr>>24 < 128 { + input.s_addr & 0xffffff + } else if input.s_addr>>24 < 192 { + input.s_addr & 0xffff + } else { + input.s_addr & 0xff + } } -//#[no_mangle] -pub extern "C" fn inet_network(cp: *const c_char) -> in_addr_t { - unimplemented!(); + + +#[no_mangle] +pub extern "C" fn inet_network(cp: *mut c_char) -> in_addr_t { + ntohl(inet_addr(cp)) } -- GitLab