fix: Destination ports used in network traffic

This commit is contained in:
Andrew Rioux 2024-02-08 19:03:28 -05:00
parent 607fb72e65
commit 93754e2cba
Signed by: andrew.rioux
GPG Key ID: 9B8BAC47C17ABB94
4 changed files with 7 additions and 4 deletions

1
.gitignore vendored
View File

@ -5,3 +5,4 @@ core
**/core
.direnv
result
sparse-public

View File

@ -110,8 +110,8 @@ pub async fn connect(config: PathBuf, ip: SocketAddr) -> anyhow::Result<()> {
Ok(packet) => {
let (count, addr) = packet?;
if addr != ip {
bail!("received response from wrong source");
if addr.ip() != ip.ip() {
bail!("received response from wrong source (expected {ip:?}; got {addr:?})");
}
let data = &buf[..count];

View File

@ -40,6 +40,7 @@ struct ConnectionInformation {
srcip: Ipv4Addr,
dstip: Ipv4Addr,
srcport: u16,
listen_port: u16,
packet_sender: Sender<EthernetPacket>,
}
@ -47,7 +48,7 @@ impl ConnectionInformation {
fn format_udp_packet(&self, data: &[u8]) -> EthernetPacket {
use packets::*;
let udp_packet = UDPPacket::construct(54248, self.srcport, data);
let udp_packet = UDPPacket::construct(self.listen_port, self.srcport, data);
let ip_packet =
IPv4Packet::construct(self.dstip, self.srcip, &Layer4Packet::UDP(udp_packet));
EthernetPacket::construct(self.dstmac, self.srcmac, &Layer3Packet::IPv4(ip_packet))
@ -147,6 +148,7 @@ pub fn spawn_connection_handler(
srcip: ip_pkt.source_ip(),
dstip: ip_pkt.dest_ip(),
srcport: udp_pkt.srcport(),
listen_port: udp_pkt.dstport(),
packet_sender,
}
};

View File

@ -2,7 +2,7 @@ use std::{
collections::HashMap,
net::Ipv4Addr,
sync::{mpsc::channel, Arc, Mutex},
thread, ffi::OsString,
thread,
};
use anyhow::{bail, Context};