Skip to main content

TcpFlags

Struct TcpFlags 

Source
pub struct TcpFlags {
    pub fin: bool,
    pub syn: bool,
    pub rst: bool,
    pub psh: bool,
    pub ack: bool,
    pub urg: bool,
    pub ece: bool,
    pub cwr: bool,
    pub ns: bool,
}
Expand description

TCP flags structure (9 bits).

Bit layout (from MSB to LSB in the 16-bit flags/reserved field):

  • NS (Nonce Sum) - ECN nonce concealment
  • CWR (Congestion Window Reduced)
  • ECE (ECN-Echo)
  • URG (Urgent)
  • ACK (Acknowledgment)
  • PSH (Push)
  • RST (Reset)
  • SYN (Synchronize)
  • FIN (Finish)

Scapy uses the string “FSRPAUECN” for flags (reversed order).

Fields§

§fin: bool

FIN - No more data from sender

§syn: bool

SYN - Synchronize sequence numbers

§rst: bool

RST - Reset the connection

§psh: bool

PSH - Push function

§ack: bool

ACK - Acknowledgment field significant

§urg: bool

URG - Urgent pointer field significant

§ece: bool

ECE - ECN-Echo (RFC 3168)

§cwr: bool

CWR - Congestion Window Reduced (RFC 3168)

§ns: bool

NS - ECN-nonce concealment protection (RFC 3540)

Implementations§

Source§

impl TcpFlags

Source

pub const NONE: Self

No flags set

Source

pub const S: Self

SYN flag only (connection initiation)

Source

pub const SA: Self

SYN+ACK flags (connection acknowledgment)

Source

pub const A: Self

ACK flag only

Source

pub const FA: Self

FIN+ACK flags (connection termination)

Source

pub const R: Self

RST flag only (connection reset)

Source

pub const RA: Self

RST+ACK flags

Source

pub const PA: Self

PSH+ACK flags (data push)

Source

pub const FIN_BIT: u16 = 0x001

Flag bit positions (in the 9-bit flags field)

Source

pub const SYN_BIT: u16 = 0x002

Source

pub const RST_BIT: u16 = 0x004

Source

pub const PSH_BIT: u16 = 0x008

Source

pub const ACK_BIT: u16 = 0x010

Source

pub const URG_BIT: u16 = 0x020

Source

pub const ECE_BIT: u16 = 0x040

Source

pub const CWR_BIT: u16 = 0x080

Source

pub const NS_BIT: u16 = 0x100

Source

pub fn from_u16(value: u16) -> Self

Create flags from a raw 16-bit value (data offset + reserved + flags).

The flags are in the lower 9 bits (with NS in bit 8 of the high byte).

Source

pub fn from_byte(byte: u8) -> Self

Create flags from just the flags byte (lower 8 bits).

Source

pub fn from_bytes(hi: u8, lo: u8) -> Self

Create flags from two bytes (data_offset_reserved + flags).

Source

pub fn to_u16(self) -> u16

Convert to a raw 9-bit value.

Source

pub fn to_byte(self) -> u8

Convert to the lower flags byte (without NS).

Source

pub fn ns_bit(self) -> u8

Get the NS bit for the high byte.

Source

pub fn from_str(s: &str) -> Self

Create flags from a string like “S”, “SA”, “FA”, “PA”, “R”, etc. Uses Scapy’s “FSRPAUECN” convention.

Source

pub fn is_syn(&self) -> bool

Check if this is a SYN packet (SYN set, ACK not set).

Source

pub fn is_syn_ack(&self) -> bool

Check if this is a SYN-ACK packet.

Source

pub fn is_ack(&self) -> bool

Check if this is a pure ACK packet.

Source

pub fn is_fin(&self) -> bool

Check if this is a FIN packet.

Source

pub fn is_rst(&self) -> bool

Check if this is a RST packet.

Source

pub fn has_ecn(&self) -> bool

Check if ECN is enabled (ECE or CWR set).

Source

pub fn is_empty(&self) -> bool

Check if any flag is set.

Source

pub fn count(&self) -> u8

Count how many flags are set.

Trait Implementations§

Source§

impl BitAnd for TcpFlags

Source§

type Output = TcpFlags

The resulting type after applying the & operator.
Source§

fn bitand(self, rhs: Self) -> Self::Output

Performs the & operation. Read more
Source§

impl BitAndAssign for TcpFlags

Source§

fn bitand_assign(&mut self, rhs: Self)

Performs the &= operation. Read more
Source§

impl BitOr for TcpFlags

Source§

type Output = TcpFlags

The resulting type after applying the | operator.
Source§

fn bitor(self, rhs: Self) -> Self::Output

Performs the | operation. Read more
Source§

impl BitOrAssign for TcpFlags

Source§

fn bitor_assign(&mut self, rhs: Self)

Performs the |= operation. Read more
Source§

impl Clone for TcpFlags

Source§

fn clone(&self) -> TcpFlags

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 TcpFlags

Source§

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

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

impl Default for TcpFlags

Source§

fn default() -> TcpFlags

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

impl Display for TcpFlags

Source§

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

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

impl From<&str> for TcpFlags

Source§

fn from(s: &str) -> Self

Converts to this type from the input type.
Source§

impl From<TcpFlags> for u16

Source§

fn from(flags: TcpFlags) -> Self

Converts to this type from the input type.
Source§

impl From<TcpFlags> for u8

Source§

fn from(flags: TcpFlags) -> Self

Converts to this type from the input type.
Source§

impl From<u16> for TcpFlags

Source§

fn from(value: u16) -> Self

Converts to this type from the input type.
Source§

impl From<u8> for TcpFlags

Source§

fn from(value: u8) -> Self

Converts to this type from the input type.
Source§

impl Hash for TcpFlags

Source§

fn hash<__H: Hasher>(&self, state: &mut __H)

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
Source§

impl PartialEq for TcpFlags

Source§

fn eq(&self, other: &TcpFlags) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl Copy for TcpFlags

Source§

impl Eq for TcpFlags

Source§

impl StructuralPartialEq for TcpFlags

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<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Checks if this value is equivalent to the given key. 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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts 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
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
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> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. 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