Commit 63394f9c authored by Paul Sajna's avatar Paul Sajna

working gethostbyaddr

parent e5b91e11
......@@ -8964,11 +8964,11 @@ m4_define([lt_dict_filter],
# serial 4219 ltversion.m4
# This file is part of GNU Libtool
m4_define([LT_PACKAGE_VERSION], [2.4.6.40-6ca5])
m4_define([LT_PACKAGE_VERSION], [2.4.6.40-6ca5-dirty])
m4_define([LT_PACKAGE_REVISION], [2.4.6.40])
AC_DEFUN([LTVERSION_VERSION],
[macro_version='2.4.6.40-6ca5'
[macro_version='2.4.6.40-6ca5-dirty'
macro_revision='2.4.6.40'
_LT_DECL(, macro_version, 0, [Which release of libtool.m4 was used?])
_LT_DECL(, macro_revision, 0)
......
......@@ -4245,7 +4245,7 @@ esac
macro_version='2.4.6.40-6ca5'
macro_version='2.4.6.40-6ca5-dirty'
macro_revision='2.4.6.40'
......
[[package]]
name = "byteorder"
version = "1.1.0"
version = "1.2.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "compiler_builtins"
version = "0.1.0"
source = "git+https://github.com/rust-lang-nursery/compiler-builtins#200c94eebf3705fa9590451f5a9e8c3fb94d7323"
source = "git+https://github.com/rust-lang-nursery/compiler-builtins#0633d73c55b210d326e0109453d86c7515ea295d"
[[package]]
name = "libc"
......@@ -17,7 +17,7 @@ source = "git+https://github.com/redox-os/liblibc#d18565cf6fbfedaa12b7d0046f50e7
name = "newlib_redox"
version = "0.1.0"
dependencies = [
"byteorder 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)",
"byteorder 1.2.1 (registry+https://github.com/rust-lang/crates.io-index)",
"compiler_builtins 0.1.0 (git+https://github.com/rust-lang-nursery/compiler-builtins)",
"libc 0.2.30 (git+https://github.com/redox-os/liblibc)",
"redox_syscall 0.1.32 (registry+https://github.com/rust-lang/crates.io-index)",
......@@ -38,7 +38,7 @@ dependencies = [
]
[metadata]
"checksum byteorder 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "ff81738b726f5d099632ceaffe7fb65b90212e8dce59d518729e7e8634032d3d"
"checksum byteorder 1.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "652805b7e73fada9d85e9a6682a4abd490cb52d96aeecc12e33a0de34dfd0d23"
"checksum compiler_builtins 0.1.0 (git+https://github.com/rust-lang-nursery/compiler-builtins)" = "<none>"
"checksum libc 0.2.30 (git+https://github.com/redox-os/liblibc)" = "<none>"
"checksum redox_syscall 0.1.32 (registry+https://github.com/rust-lang/crates.io-index)" = "ab105df655884ede59d45b7070c8a65002d921461ee813a024558ca16030eea0"
......
......@@ -44,7 +44,7 @@ struct addrinfo {
};
struct hostent *gethostbyname(const char *name);
struct hostent *gethostbyaddr(const void v, socklen_t length, int format);
struct hostent *gethostbyaddr(const void *v, socklen_t length, int format);
struct hostent *gethostent();
struct protoent *getprotobyname(const char *name);
struct protoent *getprotobynumber(int number);
......
......@@ -24,15 +24,6 @@ impl Iterator for LookupHost {
}
}
struct LookupAddr(IntoIter<[u8;11]>);
impl Iterator for LookupAddr {
type Item = [u8;11];
fn next(&mut self) -> Option<Self::Item> {
self.0.next()
}
}
#[repr(C)]
pub struct hostent {
h_name: *const libc::c_char,
......@@ -236,7 +227,7 @@ fn lookup_host(host: &str) -> Result<LookupHost> {
}
}
unsafe fn lookup_addr(addr: in_addr) -> Result<LookupAddr> {
unsafe fn lookup_addr(addr: in_addr) -> Result<Vec<Vec<u8>>> {
// XXX better error handling
let ip_string = String::from_utf8(::file_read_all("/etc/net/ip")?).or(Err(
Error::new(syscall::EIO),
......@@ -263,8 +254,6 @@ unsafe fn lookup_addr(addr: in_addr) -> Result<LookupAddr> {
for ch in b".IN-ADDR.ARPA"{
name.push(*ch);
}
let _ = syscall::write(2, name.as_slice());
let _ = syscall::write(2, "\n".as_bytes());
if ip.len() == 4 && dns.len() == 4 {
let mut timespec = syscall::TimeSpec::default();
......@@ -312,27 +301,19 @@ unsafe fn lookup_addr(addr: in_addr) -> Result<LookupAddr> {
drop(sendrecvfd);
drop(fd);
//never gets to here
let _ = syscall::write(2, "hello world\n".as_bytes());
match Dns::parse(&buf[..count]) {
Ok(response) => {
let _ = syscall::write(2, format!("{:?}", response).as_bytes());
let _ = syscall::write(2, "\n".as_bytes());
let mut names = vec![];
for answer in response.answers.iter() {
let _ = syscall::write(2, format!("{:?}", answer).as_bytes());
let _ = syscall::write(2, "\n".as_bytes());
let _ = syscall::write(2, answer.data.as_slice());
let _ = syscall::write(2, "\n".as_bytes());
if answer.a_type == 0x0001 && answer.a_class == 0x0001
if answer.a_type == 0x000C && answer.a_class == 0x0001
{
names.push(answer.data.clone());
let _ = syscall::write(2, answer.data.as_slice());
let _ = syscall::write(2, "\n".as_bytes());
}
}
Ok(LookupAddr(names.into_iter()))
Ok(names)
}
Err(_err) => Err(Error::new(EINVAL)),
}
......@@ -361,11 +342,22 @@ libc_fn!(unsafe endservent() {
libc_fn!(unsafe gethostbyaddr(v: *const libc::c_void, length: socklen_t, format: libc::c_int) -> Result <*const hostent> {
let mut addr = mem::uninitialized();
::socket::inet_aton(['8' as i8, '.' as i8, '8' as i8, '.' as i8, '4' as i8, '.' as i8, '4' as i8, '\0' as i8].as_ptr(), &mut addr);
let mut addr: in_addr = *(v as *mut in_addr);
match lookup_addr(addr) {
Ok(s) => Ok(&HOST_ENTRY),
Err(err) => Err(err),
Ok(s) => {
HOST_ADDR_LIST = [addr.s_addr.as_mut_ptr() as *const c_char, null()];
let host_name = s[0].to_vec();
HOST_ENTRY = hostent {
h_name: host_name.as_ptr() as *const c_char,
h_aliases: [null();2].as_mut_ptr(),
h_addrtype: ::socket::AF_INET,
h_length: 4,
h_addr_list: HOST_ADDR_LIST.as_ptr()
};
HOST_NAME = Some(host_name);
return Ok(&HOST_ENTRY)
}
Err(err) => Err(err)
}
});
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment