Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Fix deprecation warning on ping and dns binaries #31

Merged
merged 1 commit into from
Mar 4, 2018
Merged
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
32 changes: 16 additions & 16 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 2 additions & 4 deletions src/dns/main.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
#![feature(lookup_host)]

use std::{env, process};
use std::io::{stderr, Write};
use std::net::lookup_host;
use std::net::ToSocketAddrs;

fn main(){
if let Some(name) = env::args().nth(1) {
for addr in lookup_host(&name).unwrap() {
for addr in (name.as_str(), 0).to_socket_addrs().unwrap() {
println!("{}", addr.ip());
}
} else {
Expand Down
20 changes: 8 additions & 12 deletions src/ping/main.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
#![feature(lookup_host)]

extern crate syscall;
extern crate event;

Expand All @@ -11,7 +9,7 @@ use std::io::{Read, Write};
use std::io::Error as IOError;
use std::num::ParseIntError;
use std::mem;
use std::net::{Ipv4Addr, SocketAddr, lookup_host};
use std::net::{IpAddr, ToSocketAddrs};
use std::ops::{DerefMut, Deref};
use std::os::unix::io::{RawFd, FromRawFd};
use std::process;
Expand Down Expand Up @@ -135,7 +133,7 @@ impl DerefMut for EchoPayload {
}

struct Ping {
remote_host: Ipv4Addr,
remote_host: IpAddr,
time_file: File,
echo_file: File,
seq: usize,
Expand All @@ -152,7 +150,7 @@ fn time_diff_ms(from: &TimeSpec, to: &TimeSpec) -> f32 {
}

impl Ping {
pub fn new(remote_host: Ipv4Addr,
pub fn new(remote_host: IpAddr,
packets_to_send: usize,
interval: i64,
echo_file: File,
Expand Down Expand Up @@ -264,13 +262,11 @@ impl Ping {
}
}

fn resolve_host(host: &str) -> Result<Ipv4Addr> {
Ipv4Addr::from_str(host)
.or_else(|_| if let Some(SocketAddr::V4(addr)) = lookup_host(host)?.next() {
Ok(*addr.ip())
} else {
Err(Error::new_local("Failed to resolve remote host's IPv4 address"))
})
fn resolve_host(host: &str) -> Result<IpAddr> {
match (host, 0).to_socket_addrs()?.next() {
Some(addr) => Ok(addr.ip()),
None => Err(Error::new_local("Failed to resolve remote host's IP address"))
}
}

fn run() -> Result<()> {
Expand Down