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 moreSource§impl Debug for TcpBuilder
impl Debug for TcpBuilder
Source§impl Default for TcpBuilder
impl Default for TcpBuilder
Source§impl From<TcpBuilder> for LayerStack
impl From<TcpBuilder> for LayerStack
Source§fn from(builder: TcpBuilder) -> Self
fn from(builder: TcpBuilder) -> Self
Source§impl IntoLayerStackEntry for TcpBuilder
impl IntoLayerStackEntry for TcpBuilder
fn into_layer_stack_entry(self) -> LayerStackEntry
Auto Trait Implementations§
impl Freeze for TcpBuilder
impl RefUnwindSafe for TcpBuilder
impl Send for TcpBuilder
impl Sync for TcpBuilder
impl Unpin for TcpBuilder
impl UnsafeUnpin for TcpBuilder
impl UnwindSafe for TcpBuilder
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more