From fc35908cb3bdb351222a7e199a2ddc71c29abc16 Mon Sep 17 00:00:00 2001 From: Jeremy Wall Date: Wed, 27 Jan 2021 19:15:28 -0500 Subject: [PATCH] Examples can take an argument now --- examples/ping4.rs | 5 +++-- examples/ping6.rs | 3 ++- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/examples/ping4.rs b/examples/ping4.rs index 4e571c7..dd1eab4 100644 --- a/examples/ping4.rs +++ b/examples/ping4.rs @@ -17,14 +17,15 @@ use icmp_socket::socket::IcmpSocket; use icmp_socket::*; pub fn main() { + let address = std::env::args().nth(1).unwrap_or("127.0.0.1".to_owned()); let mut socket4 = IcmpSocket4::new().unwrap(); socket4 - .bind("0.0.0.0".parse::().unwrap()) + .bind("127.0.0.1".parse::().unwrap()) .unwrap(); let mut echo_socket = echo::EchoSocket::new(socket4); echo_socket .send_ping( - "127.0.0.1".parse::().unwrap(), + address.parse::().unwrap(), 42, &[ 0x20, 0x20, 0x75, 0x73, 0x74, 0x20, 0x61, 0x20, 0x66, 0x6c, 0x65, 0x73, 0x68, 0x20, diff --git a/examples/ping6.rs b/examples/ping6.rs index 989e318..665f924 100644 --- a/examples/ping6.rs +++ b/examples/ping6.rs @@ -17,12 +17,13 @@ use icmp_socket::socket::IcmpSocket; use icmp_socket::*; pub fn main() { + let address = std::env::args().nth(1).unwrap_or("::1".to_owned()); let mut socket6 = IcmpSocket6::new().unwrap(); socket6.bind("::1".parse::().unwrap()).unwrap(); let mut echo_socket = echo::EchoSocket::new(socket6); echo_socket .send_ping( - "::1".parse::().unwrap(), + address.parse::().unwrap(), 42, &[ 0x20, 0x20, 0x75, 0x73, 0x74, 0x20, 0x61, 0x20, 0x66, 0x6c, 0x65, 0x73, 0x68, 0x20,