fix: Destination ports used in network traffic
This commit is contained in:
parent
607fb72e65
commit
93754e2cba
1
.gitignore
vendored
1
.gitignore
vendored
@ -5,3 +5,4 @@ core
|
||||
**/core
|
||||
.direnv
|
||||
result
|
||||
sparse-public
|
||||
|
||||
@ -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];
|
||||
|
||||
@ -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,
|
||||
}
|
||||
};
|
||||
|
||||
@ -2,7 +2,7 @@ use std::{
|
||||
collections::HashMap,
|
||||
net::Ipv4Addr,
|
||||
sync::{mpsc::channel, Arc, Mutex},
|
||||
thread, ffi::OsString,
|
||||
thread,
|
||||
};
|
||||
|
||||
use anyhow::{bail, Context};
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user