Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

Fix examples/arp_packet.rs #586

Merged
merged 1 commit into from Feb 3, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
19 changes: 11 additions & 8 deletions examples/arp_packet.rs
Expand Up @@ -58,13 +58,16 @@ fn get_mac_through_arp(interface: NetworkInterface, target_ip: Ipv4Addr) -> MacA

println!("Sent ARP request");

let buf = receiver.next().unwrap();

let arp = ArpPacket::new(&buf[MutableEthernetPacket::minimum_packet_size()..]).unwrap();

println!("Received reply");

arp.get_sender_hw_addr()
while let buf = receiver.next().unwrap() {
let arp = ArpPacket::new(&buf[MutableEthernetPacket::minimum_packet_size()..]).unwrap();
if arp.get_sender_proto_addr() == target_ip
&& arp.get_target_hw_addr() == interface.mac.unwrap()
{
println!("Received reply");
return arp.get_sender_hw_addr();
}
}
panic!("Never reach here")
}

fn main() {
Expand Down Expand Up @@ -103,4 +106,4 @@ fn main() {
let target_mac = get_mac_through_arp(interface, target_ip.unwrap());

println!("Target MAC address: {}", target_mac);
}
}