
Line-by-line transliteration of a Rust DNS lookup library offering simple host/reverse lookups, safe getaddrinfo/getnameinfo wrappers, and source-provenance headers for traceability.
This is a Kotlin Multiplatform line-by-line transliteration port of keeperofdakeys/dns-lookup.
Original Project: This port is based on keeperofdakeys/dns-lookup. All design credit and project intent belong to the upstream authors; this repository is a faithful port to Kotlin Multiplatform with no behavioural changes intended.
This is an in-progress port. The goal is feature parity with the upstream Rust crate while providing a native Kotlin Multiplatform API. Every Kotlin file carries a // port-lint: source <path> header naming its upstream Rust counterpart so the AST-distance tool can track provenance.
The text below is reproduced and lightly edited from
https://github.com/keeperofdakeys/dns-lookup/. It is the upstream project's own description and remains under the upstream authors' authorship; links have been rewritten to absolute upstream URLs so they continue to resolve from this repository.
A small wrapper for libc to perform simple DNS lookups.
You can use the lookup_host function to get a list of IP Addresses for a
given hostname, and the lookup_name function to get the reverse dns entry for
the given IP Address.
PS: If you only need a single result, consider ToSocketAddrs in libstd.
The library also includes a safe wrapper for getaddrinfo and getnameinfo.
use dns_lookup::{lookup_host, lookup_addr};
{
let hostname = "localhost";
let ips: Vec<std::net::IpAddr> = lookup_host(hostname).unwrap().collect::<Vec<_>>();
assert!(ips.contains(&"127.0.0.1".parse().unwrap()));
}
{
let ip: std::net::IpAddr = "127.0.0.1".parse().unwrap();
let host = lookup_addr(&ip).unwrap();
// The string "localhost" on unix, and the hostname on Windows.
}{
extern crate dns_lookup;
use dns_lookup::{getaddrinfo, AddrInfoHints, SockType};
fn main() {
let hostname = "localhost";
let service = "ssh";
let hints = AddrInfoHints {
socktype: SockType::Stream.into(),
.. AddrInfoHints::default()
};
let sockets =
getaddrinfo(Some(hostname), Some(service), Some(hints))
.unwrap().collect::<std::io::Result<Vec<_>>>().unwrap();
for socket in sockets {
// Try connecting to socket
println!("{:?}", socket);
}
}
}
{
use dns_lookup::getnameinfo;
use std::net::{IpAddr, SocketAddr};
let ip: IpAddr = "127.0.0.1".parse().unwrap();
let port = 22;
let socket: SocketAddr = (ip, port).into();
let (name, service) = match getnameinfo(&socket, 0) {
Ok((n, s)) => (n, s),
Err(e) => panic!("Failed to lookup socket {:?}", e),
};
println!("{:?} {:?}", name, service);
let _ = (name, service);
}
{
use dns_lookup::gethostname;
let hostname = gethostname().unwrap();
}dependencies {
implementation("io.github.kotlinmania:dns-lookup-kotlin:0.1.4")
}./gradlew build
./gradlew testSee AGENTS.md for translator discipline, port-lint header convention, and Rust → Kotlin idiom mapping.
This Kotlin port is distributed under the same MIT license as the upstream keeperofdakeys/dns-lookup. See LICENSE (and any sibling LICENSE-* / NOTICE files mirrored from upstream) for the full text.
Original work copyrighted by the dns-lookup authors.
Kotlin port: Copyright (c) 2026 Sydney Renee and The Solace Project.
Thanks to the keeperofdakeys/dns-lookup maintainers and contributors for the original Rust implementation. This port reproduces their work in Kotlin Multiplatform; bug reports about upstream design or behavior should go to the upstream repository.
This is a Kotlin Multiplatform line-by-line transliteration port of keeperofdakeys/dns-lookup.
Original Project: This port is based on keeperofdakeys/dns-lookup. All design credit and project intent belong to the upstream authors; this repository is a faithful port to Kotlin Multiplatform with no behavioural changes intended.
This is an in-progress port. The goal is feature parity with the upstream Rust crate while providing a native Kotlin Multiplatform API. Every Kotlin file carries a // port-lint: source <path> header naming its upstream Rust counterpart so the AST-distance tool can track provenance.
The text below is reproduced and lightly edited from
https://github.com/keeperofdakeys/dns-lookup/. It is the upstream project's own description and remains under the upstream authors' authorship; links have been rewritten to absolute upstream URLs so they continue to resolve from this repository.
A small wrapper for libc to perform simple DNS lookups.
You can use the lookup_host function to get a list of IP Addresses for a
given hostname, and the lookup_name function to get the reverse dns entry for
the given IP Address.
PS: If you only need a single result, consider ToSocketAddrs in libstd.
The library also includes a safe wrapper for getaddrinfo and getnameinfo.
use dns_lookup::{lookup_host, lookup_addr};
{
let hostname = "localhost";
let ips: Vec<std::net::IpAddr> = lookup_host(hostname).unwrap().collect::<Vec<_>>();
assert!(ips.contains(&"127.0.0.1".parse().unwrap()));
}
{
let ip: std::net::IpAddr = "127.0.0.1".parse().unwrap();
let host = lookup_addr(&ip).unwrap();
// The string "localhost" on unix, and the hostname on Windows.
}{
extern crate dns_lookup;
use dns_lookup::{getaddrinfo, AddrInfoHints, SockType};
fn main() {
let hostname = "localhost";
let service = "ssh";
let hints = AddrInfoHints {
socktype: SockType::Stream.into(),
.. AddrInfoHints::default()
};
let sockets =
getaddrinfo(Some(hostname), Some(service), Some(hints))
.unwrap().collect::<std::io::Result<Vec<_>>>().unwrap();
for socket in sockets {
// Try connecting to socket
println!("{:?}", socket);
}
}
}
{
use dns_lookup::getnameinfo;
use std::net::{IpAddr, SocketAddr};
let ip: IpAddr = "127.0.0.1".parse().unwrap();
let port = 22;
let socket: SocketAddr = (ip, port).into();
let (name, service) = match getnameinfo(&socket, 0) {
Ok((n, s)) => (n, s),
Err(e) => panic!("Failed to lookup socket {:?}", e),
};
println!("{:?} {:?}", name, service);
let _ = (name, service);
}
{
use dns_lookup::gethostname;
let hostname = gethostname().unwrap();
}dependencies {
implementation("io.github.kotlinmania:dns-lookup-kotlin:0.1.4")
}./gradlew build
./gradlew testSee AGENTS.md for translator discipline, port-lint header convention, and Rust → Kotlin idiom mapping.
This Kotlin port is distributed under the same MIT license as the upstream keeperofdakeys/dns-lookup. See LICENSE (and any sibling LICENSE-* / NOTICE files mirrored from upstream) for the full text.
Original work copyrighted by the dns-lookup authors.
Kotlin port: Copyright (c) 2026 Sydney Renee and The Solace Project.
Thanks to the keeperofdakeys/dns-lookup maintainers and contributors for the original Rust implementation. This port reproduces their work in Kotlin Multiplatform; bug reports about upstream design or behavior should go to the upstream repository.