Skip to content
Open
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
16 changes: 15 additions & 1 deletion src/main.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
mod encrypt;
use std::fs;
use std::net::{IpAddr, ToSocketAddrs};
use std::time::Duration;
use std::{io, thread};

Expand All @@ -14,8 +15,21 @@ fn extract<'a>(text: &'a str, prefix: &'a str, suffix: &'a str) -> io::Result<&'
Err(io::ErrorKind::InvalidData.into())
}

// minreq has no happy-eyeballs and locks onto the first address from
// getaddrinfo. Pin to IPv4 so we don't stall retrying an unroutable
// IPv6 path, which is common on captive-portal Wi-Fi before auth.
fn resolve_v4(host: &str) -> io::Result<IpAddr> {
(host, 80)
.to_socket_addrs()?
.find(|a| a.is_ipv4())
.map(|a| a.ip())
.ok_or_else(|| io::Error::new(io::ErrorKind::AddrNotAvailable, "no IPv4 for host"))
}

fn login(username: &str, password: &str) -> io::Result<()> {
let resp = minreq::get("http://www.baidu.com")
let baidu_ip = resolve_v4("www.baidu.com")?;
let resp = minreq::get(format!("http://{}/", baidu_ip))
.with_header("Host", "www.baidu.com")
.with_timeout(10)
.send()
.map_err(|e| {
Expand Down