chore: run cargo fmt
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
use std::{io::prelude::*, net::Ipv4Addr, collections::HashMap};
|
||||
use std::{collections::HashMap, io::prelude::*, net::Ipv4Addr};
|
||||
|
||||
use anyhow::anyhow;
|
||||
use tokio::time::{Duration, interval};
|
||||
use tokio::time::{interval, Duration};
|
||||
use tokio_stream::StreamExt;
|
||||
|
||||
use nl_sys::{netlink, route};
|
||||
@@ -26,15 +26,17 @@ async fn main() -> anyhow::Result<()> {
|
||||
let addrs = socket.get_addrs()?;
|
||||
|
||||
routes_inner.sort_by(|r1, r2| {
|
||||
r2.dst().map(|a| a.cidrlen())
|
||||
r2.dst()
|
||||
.map(|a| a.cidrlen())
|
||||
.partial_cmp(&r1.dst().map(|a| a.cidrlen()))
|
||||
.unwrap_or(std::cmp::Ordering::Equal)
|
||||
});
|
||||
|
||||
let (ifname, srcip, srcmac, dstmac) = route::get_macs_and_src_for_ip(&addrs, &routes, &neighs, &links, target)
|
||||
.ok_or(anyhow!("unable to find a route to the IP"))?;
|
||||
let (ifname, srcip, srcmac, dstmac) =
|
||||
route::get_macs_and_src_for_ip(&addrs, &routes, &neighs, &links, target)
|
||||
.ok_or(anyhow!("unable to find a route to the IP"))?;
|
||||
|
||||
( ifname, srcmac, dstmac, srcip )
|
||||
(ifname, srcmac, dstmac, srcip)
|
||||
};
|
||||
|
||||
let mut interface = pcap_sys::new_aggregate_interface(false)?;
|
||||
@@ -43,7 +45,7 @@ async fn main() -> anyhow::Result<()> {
|
||||
interface.set_non_blocking(true)?;
|
||||
interface.set_promisc(false)?;
|
||||
interface.set_timeout(10)?;
|
||||
|
||||
|
||||
let mut interface = interface.activate()?;
|
||||
|
||||
interface.set_filter("inbound and udp port 54248", true, None)?;
|
||||
@@ -52,7 +54,7 @@ async fn main() -> anyhow::Result<()> {
|
||||
|
||||
enum EventType {
|
||||
Packet((String, Result<EthernetPacket, pcap_sys::error::Error>)),
|
||||
Update
|
||||
Update,
|
||||
}
|
||||
|
||||
let mut packets = interface.stream()?;
|
||||
@@ -86,9 +88,12 @@ async fn main() -> anyhow::Result<()> {
|
||||
current_packet_id += 1;
|
||||
sent_updates.insert(current_packet_id, false);
|
||||
|
||||
let udp_packet = UDPPacket::construct(54248, 54248, current_packet_id.to_be_bytes().to_vec());
|
||||
let ip_packet = IPv4Packet::construct(srcip, target, &Layer4Packet::UDP(udp_packet));
|
||||
let eth_packet = EthernetPacket::construct(src_mac, dst_mac, &Layer3Packet::IPv4(ip_packet));
|
||||
let udp_packet =
|
||||
UDPPacket::construct(54248, 54248, current_packet_id.to_be_bytes().to_vec());
|
||||
let ip_packet =
|
||||
IPv4Packet::construct(srcip, target, &Layer4Packet::UDP(udp_packet));
|
||||
let eth_packet =
|
||||
EthernetPacket::construct(src_mac, dst_mac, &Layer3Packet::IPv4(ip_packet));
|
||||
|
||||
packets.sendpacket(&ifname, eth_packet.pkt())?;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user