Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ regex = "1"
trust-dns-client = "0.23"

tokio = { version = "1", features = ["fs", "net", "time", "io-util"], optional = true }
encoding_rs = "0.8.34"

[dev-dependencies]
tokio = { version = "1", features = ["macros", "rt"] }
Expand Down
15 changes: 13 additions & 2 deletions src/who_is.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ use std::{
time::Duration,
};

use encoding_rs::{UTF_8, WINDOWS_1252};
use once_cell::sync::Lazy;
use regex::Regex;
use serde_json::{Map, Value};
Expand Down Expand Up @@ -243,9 +244,19 @@ impl WhoIs {

client.flush()?;

let mut query_result = String::new();
let mut buf = vec![];
client.read_to_end(&mut buf)?;

client.read_to_string(&mut query_result)?;
let decoders = [UTF_8, WINDOWS_1252];

for decoder in &decoders {
let (cow, _encoding_used, had_errors) = decoder.decode(&buf);
if !had_errors {
return Ok((addr, cow.into_owned()));
}
}

let query_result = String::from_utf8_lossy(&buf).into_owned();

Ok((addr, query_result))
}
Expand Down
11 changes: 11 additions & 0 deletions tests/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,17 @@ fn test_srv() {
println!("{}", result);
}

#[test]
fn test_non_utf8_responses() {
let who = WhoIs::from_host("whois.arin.net").unwrap();

let result = who.lookup(WhoIsLookupOptions::from_string("178.202.0.0").unwrap()).unwrap();
println!("{}", result);

let result = who.lookup(WhoIsLookupOptions::from_string("185.73.124.0").unwrap()).unwrap();
println!("{}", result);
}

#[cfg(feature = "tokio")]
#[tokio::test]
async fn test_async() {
Expand Down