4 releases
new 0.1.3 | Mar 3, 2025 |
---|---|
0.1.2 | Mar 2, 2025 |
0.1.1 | Feb 28, 2025 |
0.1.0 | Feb 28, 2025 |
#1421 in Network programming
166 downloads per month
29KB
618 lines
nscd-lookup – look up IP addresses using nscd
Explicitly querying nscd
might come in handy
if your program runs in a container or jail without direct internet access, but you still need to
look up a domain name for some reason.
use std::net::{IpAddr, Ipv4Addr, Ipv6Addr};
use nscd_lookup::sync::lookup;
let localhost: Vec<IpAddr> = lookup("localhost", &mut Vec::new(), None)
.expect("should be able to look up addresses")
.expect("address list should not be empty")
.collect();
assert!(localhost.contains(&IpAddr::V4(Ipv4Addr::LOCALHOST)));
assert!(localhost.contains(&IpAddr::V6(Ipv6Addr::LOCALHOST)));
Or with the feature "tokio"
:
use std::net::{IpAddr, Ipv4Addr, Ipv6Addr};
use nscd_lookup::tokio::lookup;
let localhost: Vec<IpAddr> = lookup("localhost", &mut Vec::new(), None)
.await
.expect("should be able to look up addresses")
.expect("address list should not be empty")
.collect();
assert!(localhost.contains(&IpAddr::V4(Ipv4Addr::LOCALHOST)));
assert!(localhost.contains(&IpAddr::V6(Ipv6Addr::LOCALHOST)));
The feature "reqwest"
enables a resolver that can be used in reqwest clients.
Dependencies
~2–14MB
~203K SLoC