feat: started to make a TCP state machine
This commit is contained in:
@@ -9,9 +9,13 @@ use pcap_sys::packets::*;
|
||||
|
||||
#[tokio::main]
|
||||
async fn main() -> anyhow::Result<()> {
|
||||
let target = std::env::args().skip(1).next().ok_or(anyhow!("could not get target IP"))?.parse::<Ipv4Addr>()?;
|
||||
let target = std::env::args()
|
||||
.skip(1)
|
||||
.next()
|
||||
.ok_or(anyhow!("could not get target IP"))?
|
||||
.parse::<Ipv4Addr>()?;
|
||||
|
||||
let (ifname, src_mac, dst_mac, srcip) = {
|
||||
let (ifname, _, srcip, src_mac, dst_mac, _) = {
|
||||
let socket = netlink::Socket::new()?;
|
||||
|
||||
let routes = socket.get_routes()?;
|
||||
@@ -19,11 +23,8 @@ async fn main() -> anyhow::Result<()> {
|
||||
let links = socket.get_links()?;
|
||||
let addrs = socket.get_addrs()?;
|
||||
|
||||
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)
|
||||
route::get_macs_and_src_for_ip(&addrs, &routes, &neighs, &links, target)
|
||||
.ok_or(anyhow!("unable to find a route to the IP"))?
|
||||
};
|
||||
|
||||
let mut interface = pcap_sys::new_aggregate_interface(false)?;
|
||||
@@ -56,12 +57,18 @@ async fn main() -> anyhow::Result<()> {
|
||||
match evt {
|
||||
EventType::Packet((_, Ok(pkt))) => {
|
||||
let eth_pkt = pkt.pkt();
|
||||
let Ok(Layer3Pkt::IPv4Pkt(ip_pkt)) = eth_pkt.get_layer3_pkt() else { continue; };
|
||||
let Ok(Layer4Pkt::UDP(udp_pkt)) = ip_pkt.get_layer4_packet() else { continue; };
|
||||
let Ok(Layer3Pkt::IPv4Pkt(ip_pkt)) = eth_pkt.get_layer3_pkt() else {
|
||||
continue;
|
||||
};
|
||||
let Ok(Layer4Pkt::UDP(udp_pkt)) = ip_pkt.get_layer4_packet() else {
|
||||
continue;
|
||||
};
|
||||
|
||||
let data = udp_pkt.get_data();
|
||||
|
||||
let Ok(resp_id) = TryInto::<[u8;4]>::try_into(&data[..4]) else { continue; };
|
||||
let Ok(resp_id) = TryInto::<[u8; 4]>::try_into(&data[..4]) else {
|
||||
continue;
|
||||
};
|
||||
let resp_id = i32::from_be_bytes(resp_id);
|
||||
|
||||
if sent_updates.contains_key(&resp_id) {
|
||||
|
||||
Reference in New Issue
Block a user