Skip to main content

TcpBuilder

Struct TcpBuilder 

Source
pub struct TcpBuilder { /* private fields */ }
Expand description

Builder for TCP packets.

Implementations§

Source§

impl TcpBuilder

Source

pub fn new() -> Self

Create a new TCP builder with default values.

Source

pub fn from_bytes(data: &[u8]) -> Result<Self, FieldError>

Create a builder initialized from an existing packet.

Source

pub fn src_port(self, port: u16) -> Self

Set the source port.

Source

pub fn sport(self, port: u16) -> Self

Alias for src_port (Scapy compatibility).

Source

pub fn dst_port(self, port: u16) -> Self

Set the destination port.

Source

pub fn dport(self, port: u16) -> Self

Alias for dst_port (Scapy compatibility).

Source

pub fn seq(self, seq: u32) -> Self

Set the sequence number.

Source

pub fn ack_num(self, ack: u32) -> Self

Set the acknowledgment number.

Source

pub fn data_offset(self, offset: u8) -> Self

Set the data offset (in 32-bit words).

Source

pub fn dataofs(self, offset: u8) -> Self

Alias for data_offset (Scapy compatibility).

Source

pub fn reserved(self, reserved: u8) -> Self

Set the reserved bits.

Source

pub fn flags(self, flags: TcpFlags) -> Self

Set the flags.

Source

pub fn flags_str(self, s: &str) -> Self

Set flags from a string like “S”, “SA”, “FA”, etc.

Source

pub fn syn(self) -> Self

Set the SYN flag.

Source

pub fn ack(self) -> Self

Set the ACK flag.

Source

pub fn fin(self) -> Self

Set the FIN flag.

Source

pub fn rst(self) -> Self

Set the RST flag.

Source

pub fn psh(self) -> Self

Set the PSH flag.

Source

pub fn urg(self) -> Self

Set the URG flag.

Source

pub fn ece(self) -> Self

Set the ECE flag.

Source

pub fn cwr(self) -> Self

Set the CWR flag.

Source

pub fn ns(self) -> Self

Set the NS flag.

Source

pub fn syn_ack(self) -> Self

Set SYN+ACK flags.

Source

pub fn fin_ack(self) -> Self

Set FIN+ACK flags.

Source

pub fn psh_ack(self) -> Self

Set PSH+ACK flags.

Source

pub fn window(self, window: u16) -> Self

Set the window size.

Source

pub fn checksum(self, checksum: u16) -> Self

Set the checksum manually.

Source

pub fn chksum(self, checksum: u16) -> Self

Alias for checksum (Scapy compatibility).

Source

pub fn urgent_ptr(self, urgptr: u16) -> Self

Set the urgent pointer.

Source

pub fn urgptr(self, urgptr: u16) -> Self

Alias for urgent_ptr (Scapy compatibility).

Source

pub fn src_ip<T: Into<IpAddr>>(self, ip: T) -> Self

Set the source IP address (for checksum calculation).

Source

pub fn dst_ip<T: Into<IpAddr>>(self, ip: T) -> Self

Set the destination IP address (for checksum calculation).

Source

pub fn ipv4_addrs(self, src: Ipv4Addr, dst: Ipv4Addr) -> Self

Set both source and destination IPv4 addresses.

Source

pub fn ipv6_addrs(self, src: Ipv6Addr, dst: Ipv6Addr) -> Self

Set both source and destination IPv6 addresses.

Source

pub fn options(self, options: TcpOptions) -> Self

Set the options.

Source

pub fn option(self, option: TcpOption) -> Self

Add a single option.

Source

pub fn with_options<F>(self, f: F) -> Self

Add options using a builder function.

Source

pub fn mss(self, mss: u16) -> Self

Add an MSS (Maximum Segment Size) option.

Source

pub fn wscale(self, scale: u8) -> Self

Add a Window Scale option.

Source

pub fn sack_ok(self) -> Self

Add SACK Permitted option.

Source

pub fn sack(self, blocks: Vec<TcpSackBlock>) -> Self

Add a SACK option with blocks.

Source

pub fn timestamp(self, ts_val: u32, ts_ecr: u32) -> Self

Add a Timestamp option.

Source

pub fn nop(self) -> Self

Add a NOP (padding) option.

Source

pub fn eol(self) -> Self

Add an EOL (End of Options) option.

Source

pub fn tfo(self, cookie: Option<Vec<u8>>) -> Self

Add a TFO (TCP Fast Open) option.

Source

pub fn md5(self, signature: [u8; 16]) -> Self

Add an MD5 signature option.

Source

pub fn ao(self, key_id: u8, rnext_key_id: u8, mac: Vec<u8>) -> Self

Add an Authentication Option (TCP-AO).

Source

pub fn payload(self, payload: impl Into<Vec<u8>>) -> Self

Set the payload data.

Source

pub fn append_payload(self, data: &[u8]) -> Self

Append data to the payload.

Source

pub fn auto_checksum(self, enabled: bool) -> Self

Enable or disable automatic checksum calculation.

Source

pub fn auto_data_offset(self, enabled: bool) -> Self

Enable or disable automatic data offset calculation.

Source

pub fn header_size(&self) -> usize

Calculate the header size (including options, with padding).

Source

pub fn packet_size(&self) -> usize

Calculate the total packet size.

Source

pub fn build(&self) -> Vec<u8>

Build the TCP packet.

Source

pub fn build_into(&self, buf: &mut [u8]) -> Result<usize, FieldError>

Build the TCP packet into an existing buffer.

Source

pub fn build_header(&self) -> Vec<u8>

Build only the header (no payload).

Source§

impl TcpBuilder

Source

pub fn syn_packet() -> Self

Create a SYN packet builder.

Source

pub fn syn_ack_packet() -> Self

Create a SYN-ACK packet builder.

Source

pub fn ack_packet() -> Self

Create an ACK packet builder.

Source

pub fn fin_ack_packet() -> Self

Create a FIN-ACK packet builder.

Source

pub fn rst_packet() -> Self

Create a RST packet builder.

Source

pub fn rst_ack_packet() -> Self

Create a RST-ACK packet builder.

Source

pub fn data_packet() -> Self

Create a PSH-ACK packet builder (for data).

Source§

impl TcpBuilder

Source

pub fn random_seq(self) -> Self

Set a random sequence number.

Source

pub fn random_sport(self) -> Self

Set a random source port (dynamic range: 49152-65535).

Trait Implementations§

Source§

impl Clone for TcpBuilder

Source§

fn clone(&self) -> TcpBuilder

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for TcpBuilder

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for TcpBuilder

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl From<TcpBuilder> for LayerStack

Source§

fn from(builder: TcpBuilder) -> Self

Converts to this type from the input type.
Source§

impl IntoLayerStackEntry for TcpBuilder

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V