-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlib.rs
More file actions
80 lines (66 loc) · 2.12 KB
/
lib.rs
File metadata and controls
80 lines (66 loc) · 2.12 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
#[macro_use]
extern crate lazy_static;
extern crate libc;
#[macro_use]
extern crate libnss;
use std::net::IpAddr;
use libnss::host::{AddressFamily, Host, HostHooks};
use libnss::interop::Response;
use zbus::{blocking::Connection};
struct DoHHost;
libnss_host_hooks!(doh, DoHHost);
impl HostHooks for DoHHost {
fn get_all_entries() -> Response<Vec<Host>> {
Response::Success(vec![])
}
fn get_host_by_name(name: &str, family: AddressFamily) -> Response<Host> {
let result = Connection::system()
.and_then(|connection: Connection| {
let record_type: u32 = if family == AddressFamily::IPv6 {
28
} else {
1
};
connection.call_method(
Some("com.glaciaos.NameResolver"),
"/com/glaciaos/NameResolver",
Some("com.glaciaos.NameResolver"),
"ResolveName",
&(std::process::id(), name, record_type),
)
})
.and_then(|message| {
message.body().deserialize::<Host>()
});
match result {
Ok(host) => Response::Success(host),
Err(_err) => Response::NotFound
}
}
fn get_host_by_addr(_addr: IpAddr) -> Response<Host> {
Response::NotFound
}
}
// #[cfg(test)]
// mod tests {
// use libnss::host::{AddressFamily, HostHooks};
//
// use crate::DoHHost;
//
// #[test]
// fn it_works() {
// let google_domain6 = DoHHost::get_host_by_name("google.com", AddressFamily::IPv6);
//
// match google_domain6 {
// libnss::interop::Response::Success(_) => assert_eq!(1, 1, "Resulted in a IP"),
// _ => assert_eq!(1, 2, "Not resulted in a IP")
// };
//
// let google_domain = DoHHost::get_host_by_name("google.com", AddressFamily::IPv4);
//
// match google_domain {
// libnss::interop::Response::Success(_) => assert_eq!(1, 1, "Resulted in a IP"),
// _ => assert_eq!(1, 1, "Not resulted in a IP")
// };
// }
// }