try_dns.rs 680 B

123456789101112131415161718192021222324
  1. use wasmedge_wasi_socket::{resolve, Ipv4Addr, TcpStream};
  2. fn main() {
  3. let mut code = 0;
  4. for name in std::env::args().skip(1) {
  5. println!("resolve {name}");
  6. let mut conn = TcpStream::connect("127.0.0.1:8000").unwrap();
  7. conn.as_ref()
  8. .set_recv_timeout(Some(std::time::Duration::from_secs(3)))
  9. .unwrap();
  10. match resolve::<_, Ipv4Addr>(&mut conn, &name) {
  11. Ok(address) => {
  12. println!("{:#?}", address);
  13. }
  14. Err(e) => {
  15. eprintln!("Error resolving {:?}: {}", name, e);
  16. code = 1;
  17. }
  18. }
  19. }
  20. std::process::exit(code);
  21. }