Skip to content

Commit

Permalink
Remove unnecessary conversion
Browse files Browse the repository at this point in the history
  • Loading branch information
SajjadPourali committed Mar 3, 2024
1 parent b19a1fa commit 848ea0d
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 10 deletions.
3 changes: 0 additions & 3 deletions src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,6 @@ pub enum IpStackError {
#[error("ValueTooBigError<u16> {0}")]
ValueTooBigErrorU16(#[from] etherparse::err::ValueTooBigError<u16>),

#[error("ValueTooBigError<u32> {0}")]
ValueTooBigErrorU32(#[from] etherparse::err::ValueTooBigError<u32>),

#[error("ValueTooBigError<usize> {0}")]
ValueTooBigErrorUsize(#[from] etherparse::err::ValueTooBigError<usize>),

Expand Down
10 changes: 5 additions & 5 deletions src/stream/tcp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use crate::{
stream::tcb::{Tcb, TcpState},
DROP_TTL, TTL,
};
use etherparse::{IpNumber, Ipv4Extensions, Ipv4Header, Ipv6Extensions};
use etherparse::{IpNumber, Ipv4Extensions, Ipv4Header, Ipv6Extensions, Ipv6FlowLabel};
use std::{
cmp,
future::Future,
Expand Down Expand Up @@ -90,13 +90,13 @@ impl IpStackTcpStream {
&self,
flags: u8,
ttl: u8,
seq: Option<u32>,
seq: impl Into<Option<u32>>,
mut payload: Vec<u8>,
) -> Result<NetworkPacket, Error> {
let mut tcp_header = etherparse::TcpHeader::new(
self.dst_addr.port(),
self.src_addr.port(),
seq.unwrap_or(self.tcb.get_seq()),
seq.into().unwrap_or(self.tcb.get_seq()),
self.tcb.get_recv_window(),
);

Expand Down Expand Up @@ -134,7 +134,7 @@ impl IpStackTcpStream {
(std::net::IpAddr::V6(dst), std::net::IpAddr::V6(src)) => {
let mut ip_h = etherparse::Ipv6Header {
traffic_class: 0,
flow_label: 0.try_into().map_err(IpStackError::from)?,
flow_label: Ipv6FlowLabel::ZERO,
payload_length: 0,
next_header: IpNumber::TCP,
hop_limit: ttl,
Expand Down Expand Up @@ -455,7 +455,7 @@ impl AsyncWrite for IpStackTcpStream {
.and_then(|p| self.tcb.inflight_packets.get(p))
{
let flags = tcp_flags::PSH | tcp_flags::ACK;
let packet = self.create_rev_packet(flags, TTL, Some(i.seq), i.payload.to_vec())?;
let packet = self.create_rev_packet(flags, TTL, i.seq, i.payload.to_vec())?;

self.packet_sender
.send(packet)
Expand Down
6 changes: 4 additions & 2 deletions src/stream/unknown.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
use std::{io::Error, mem, net::IpAddr};

use etherparse::{IpNumber, Ipv4Extensions, Ipv4Header, Ipv6Extensions, Ipv6Header, NetHeaders};
use etherparse::{
IpNumber, Ipv4Extensions, Ipv4Header, Ipv6Extensions, Ipv6FlowLabel, Ipv6Header, NetHeaders,
};
use tokio::sync::mpsc::UnboundedSender;

use crate::{
Expand Down Expand Up @@ -86,7 +88,7 @@ impl IpStackUnknownTransport {
(std::net::IpAddr::V6(dst), std::net::IpAddr::V6(src)) => {
let mut ip_h = Ipv6Header {
traffic_class: 0,
flow_label: 0.try_into().map_err(crate::IpStackError::from)?,
flow_label: Ipv6FlowLabel::ZERO,
payload_length: 0,
next_header: IpNumber::UDP,
hop_limit: TTL,
Expand Down

0 comments on commit 848ea0d

Please sign in to comment.