pub struct TcpBuilder { /* private fields */ }Expand description
Builder for TCP packets.
Implementations§
Source§impl TcpBuilder
impl TcpBuilder
Sourcepub fn from_bytes(data: &[u8]) -> Result<Self, FieldError>
pub fn from_bytes(data: &[u8]) -> Result<Self, FieldError>
Create a builder initialized from an existing packet.
Sourcepub fn data_offset(self, offset: u8) -> Self
pub fn data_offset(self, offset: u8) -> Self
Set the data offset (in 32-bit words).
Sourcepub fn urgent_ptr(self, urgptr: u16) -> Self
pub fn urgent_ptr(self, urgptr: u16) -> Self
Set the urgent pointer.
Sourcepub fn src_ip<T: Into<IpAddr>>(self, ip: T) -> Self
pub fn src_ip<T: Into<IpAddr>>(self, ip: T) -> Self
Set the source IP address (for checksum calculation).
Sourcepub fn dst_ip<T: Into<IpAddr>>(self, ip: T) -> Self
pub fn dst_ip<T: Into<IpAddr>>(self, ip: T) -> Self
Set the destination IP address (for checksum calculation).
Sourcepub fn ipv4_addrs(self, src: Ipv4Addr, dst: Ipv4Addr) -> Self
pub fn ipv4_addrs(self, src: Ipv4Addr, dst: Ipv4Addr) -> Self
Set both source and destination IPv4 addresses.
Sourcepub fn ipv6_addrs(self, src: Ipv6Addr, dst: Ipv6Addr) -> Self
pub fn ipv6_addrs(self, src: Ipv6Addr, dst: Ipv6Addr) -> Self
Set both source and destination IPv6 addresses.
Sourcepub fn options(self, options: TcpOptions) -> Self
pub fn options(self, options: TcpOptions) -> Self
Set the options.
Sourcepub fn with_options<F>(self, f: F) -> Self
pub fn with_options<F>(self, f: F) -> Self
Add options using a builder function.
Sourcepub fn sack(self, blocks: Vec<TcpSackBlock>) -> Self
pub fn sack(self, blocks: Vec<TcpSackBlock>) -> Self
Add a SACK option with blocks.
Sourcepub fn ao(self, key_id: u8, rnext_key_id: u8, mac: Vec<u8>) -> Self
pub fn ao(self, key_id: u8, rnext_key_id: u8, mac: Vec<u8>) -> Self
Add an Authentication Option (TCP-AO).
Sourcepub fn append_payload(self, data: &[u8]) -> Self
pub fn append_payload(self, data: &[u8]) -> Self
Append data to the payload.
Sourcepub fn auto_checksum(self, enabled: bool) -> Self
pub fn auto_checksum(self, enabled: bool) -> Self
Enable or disable automatic checksum calculation.
Sourcepub fn auto_data_offset(self, enabled: bool) -> Self
pub fn auto_data_offset(self, enabled: bool) -> Self
Enable or disable automatic data offset calculation.
Sourcepub fn header_size(&self) -> usize
pub fn header_size(&self) -> usize
Calculate the header size (including options, with padding).
Sourcepub fn packet_size(&self) -> usize
pub fn packet_size(&self) -> usize
Calculate the total packet size.
Sourcepub fn build_into(&self, buf: &mut [u8]) -> Result<usize, FieldError>
pub fn build_into(&self, buf: &mut [u8]) -> Result<usize, FieldError>
Build the TCP packet into an existing buffer.
Sourcepub fn build_header(&self) -> Vec<u8> ⓘ
pub fn build_header(&self) -> Vec<u8> ⓘ
Build only the header (no payload).
Source§impl TcpBuilder
impl TcpBuilder
Sourcepub fn syn_packet() -> Self
pub fn syn_packet() -> Self
Create a SYN packet builder.
Sourcepub fn syn_ack_packet() -> Self
pub fn syn_ack_packet() -> Self
Create a SYN-ACK packet builder.
Sourcepub fn ack_packet() -> Self
pub fn ack_packet() -> Self
Create an ACK packet builder.
Sourcepub fn fin_ack_packet() -> Self
pub fn fin_ack_packet() -> Self
Create a FIN-ACK packet builder.
Sourcepub fn rst_packet() -> Self
pub fn rst_packet() -> Self
Create a RST packet builder.
Sourcepub fn rst_ack_packet() -> Self
pub fn rst_ack_packet() -> Self
Create a RST-ACK packet builder.
Sourcepub fn data_packet() -> Self
pub fn data_packet() -> Self
Create a PSH-ACK packet builder (for data).
Source§impl TcpBuilder
impl TcpBuilder
Sourcepub fn random_seq(self) -> Self
pub fn random_seq(self) -> Self
Set a random sequence number.
Sourcepub fn random_sport(self) -> Self
pub fn random_sport(self) -> Self
Set a random source port (dynamic range: 49152-65535).
Trait Implementations§
Source§impl Clone for TcpBuilder
impl Clone for TcpBuilder
Source§fn clone(&self) -> TcpBuilder
fn clone(&self) -> TcpBuilder
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more