Fix binding of socket for examples

This commit is contained in:
Jeremy Wall 2021-01-27 20:49:48 -05:00
parent 931113a868
commit b85822c95d
3 changed files with 4 additions and 6 deletions

View File

@ -20,7 +20,7 @@ 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("127.0.0.1".parse::<Ipv4Addr>().unwrap())
.bind("0.0.0.0".parse::<Ipv4Addr>().unwrap())
.unwrap();
let mut echo_socket = echo::EchoSocket::new(socket4);
echo_socket

View File

@ -19,7 +19,7 @@ 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::<Ipv6Addr>().unwrap()).unwrap();
socket6.bind("::0".parse::<Ipv6Addr>().unwrap()).unwrap();
let mut echo_socket = echo::EchoSocket::new(socket6);
echo_socket
.send_ping(

View File

@ -79,10 +79,8 @@ impl IcmpSocket for IcmpSocket4 {
fn send_to(&mut self, dest: Self::AddrType, packet: Self::PacketType) -> std::io::Result<()> {
let dest = ip_to_socket(&IpAddr::V4(dest));
self.inner.set_ttl(self.opts.hops)?;
self.inner.send_to(
dbg!(&packet.with_checksum().get_bytes(true)),
&(dbg!(dest.into())),
)?;
self.inner
.send_to(&packet.with_checksum().get_bytes(true), &(dest.into()))?;
Ok(())
}