[][src]Struct etherparse::PacketBuilderStep

pub struct PacketBuilderStep<LastStep> { /* fields omitted */ }

An unfinished packet that is build with the packet builder

Methods

impl PacketBuilderStep<Ethernet2Header>[src]

pub fn ipv4(
    self,
    source: [u8; 4],
    destination: [u8; 4],
    time_to_live: u8
) -> PacketBuilderStep<IpHeader>
[src]

Add an ip v4 header

pub fn ip(self, ip_header: IpHeader) -> PacketBuilderStep<IpHeader>[src]

Add an ip header (length, protocol/next_header & checksum fields will be overwritten based on the rest of the packet).

Examples

With an IPv4 header:

let builder = PacketBuilder::
    ethernet2([1,2,3,4,5,6],
              [7,8,9,10,11,12])
   //payload_len, protocol & checksum will be replaced during write
   .ip(IpHeader::Version4(Ipv4Header::new(
       0, //payload_len will be replaced during write
       12, //time_to_live
       IpTrafficClass::Udp, //will be replaced during write
       [0,1,2,3], //source
       [4,5,6,7] //destination
    )));

With an IPv6 header:

let builder = PacketBuilder::
    ethernet2([1,2,3,4,5,6],
              [7,8,9,10,11,12])
   .ip(IpHeader::Version6(Ipv6Header{
        traffic_class: 0,
        flow_label: 0,
        payload_length: 0, //will be replaced during write
        next_header: 0, //will be replaced during write
        hop_limit: 4,
        source: [0;16],
        destination: [0;16]
    }));

pub fn ipv6(
    self,
    source: [u8; 16],
    destination: [u8; 16],
    hop_limit: u8
) -> PacketBuilderStep<IpHeader>
[src]

Add an ip v6 header

pub fn vlan(self, vlan: VlanHeader) -> PacketBuilderStep<VlanHeader>[src]

Adds a vlan tagging header with the given vlan identifier

pub fn single_vlan(self, vlan_identifier: u16) -> PacketBuilderStep<VlanHeader>[src]

Adds a vlan tagging header with the given vlan identifier

pub fn double_vlan(
    self,
    outer_vlan_identifier: u16,
    inner_vlan_identifier: u16
) -> PacketBuilderStep<VlanHeader>
[src]

Adds two vlan tagging header with the given vlan identifiers (also known as double vlan tagging).

impl PacketBuilderStep<VlanHeader>[src]

pub fn ip(self, ip_header: IpHeader) -> PacketBuilderStep<IpHeader>[src]

Add an ip header (length, protocol/next_header & checksum fields will be overwritten based on the rest of the packet).

Example IPv4

let builder = PacketBuilder::
    ethernet2([1,2,3,4,5,6],
              [7,8,9,10,11,12])
   //payload_len, protocol & checksum will be replaced during write
   .ip(IpHeader::Version4(Ipv4Header::new(
       0, //payload_len will be replaced during write
       12, //time_to_live
       IpTrafficClass::Udp, //will be replaced during write
       [0,1,2,3], //source
       [4,5,6,7] //destination
    )));

Example IPv6

let builder = PacketBuilder::
    ethernet2([1,2,3,4,5,6],
              [7,8,9,10,11,12])
   .ip(IpHeader::Version6(Ipv6Header{
        traffic_class: 0,
        flow_label: 0,
        payload_length: 0, //will be replaced during write
        next_header: 0, //will be replaced during write
        hop_limit: 4,
        source: [0;16],
        destination: [0;16]
    }));

pub fn ipv6(
    self,
    source: [u8; 16],
    destination: [u8; 16],
    hop_limit: u8
) -> PacketBuilderStep<IpHeader>
[src]

Add a ip v6 header

pub fn ipv4(
    self,
    source: [u8; 4],
    destination: [u8; 4],
    time_to_live: u8
) -> PacketBuilderStep<IpHeader>
[src]

Add a ip v4 header

impl PacketBuilderStep<IpHeader>[src]

pub fn udp(
    self,
    source_port: u16,
    destination_port: u16
) -> PacketBuilderStep<UdpHeader>
[src]

pub fn tcp(
    self,
    source_port: u16,
    destination_port: u16,
    sequence_number: u32,
    window_size: u16
) -> PacketBuilderStep<TcpHeader>
[src]

impl PacketBuilderStep<UdpHeader>[src]

pub fn write<T: Write + Sized>(
    self,
    writer: &mut T,
    payload: &[u8]
) -> Result<(), WriteError>
[src]

Write all the headers and the payload.

pub fn size(&self, payload_size: usize) -> usize[src]

Returns the size of the packet when it is serialized

impl PacketBuilderStep<TcpHeader>[src]

pub fn ns(self) -> PacketBuilderStep<TcpHeader>[src]

Set ns flag (ECN-nonce - concealment protection; experimental: see RFC 3540)

pub fn fin(self) -> PacketBuilderStep<TcpHeader>[src]

Set fin flag (No more data from sender)

pub fn syn(self) -> PacketBuilderStep<TcpHeader>[src]

Set the syn flag (synchronize sequence numbers)

pub fn rst(self) -> PacketBuilderStep<TcpHeader>[src]

Sets the rst flag (reset the connection)

pub fn psh(self) -> PacketBuilderStep<TcpHeader>[src]

Sets the psh flag (push function)

pub fn ack(self, acknowledgment_number: u32) -> PacketBuilderStep<TcpHeader>[src]

Sets the ack flag and the acknowledgment_number.

pub fn urg(self, urgent_pointer: u16) -> PacketBuilderStep<TcpHeader>[src]

Set the urg flag & the urgent pointer field.

The urgent pointer points to the sequence number of the octet following the urgent data.

pub fn ece(self) -> PacketBuilderStep<TcpHeader>[src]

Sets ece flag (ECN-Echo, RFC 3168)

pub fn cwr(self) -> PacketBuilderStep<TcpHeader>[src]

Set cwr flag (Congestion Window Reduced)

This flag is set by the sending host to indicate that it received a TCP segment with the ECE flag set and had responded in congestion control mechanism (added to header by RFC 3168).

pub fn options(
    self,
    options: &[TcpOptionElement]
) -> Result<PacketBuilderStep<TcpHeader>, TcpOptionWriteError>
[src]

Set the tcp options of the header.

pub fn options_raw(
    self,
    options: &[u8]
) -> Result<PacketBuilderStep<TcpHeader>, TcpOptionWriteError>
[src]

Set the tcp options of the header (setting the bytes directly).

pub fn write<T: Write + Sized>(
    self,
    writer: &mut T,
    payload: &[u8]
) -> Result<(), WriteError>
[src]

Write all the headers and the payload.

pub fn size(&self, payload_size: usize) -> usize[src]

Returns the size of the packet when it is serialized

Auto Trait Implementations

impl<LastStep> Send for PacketBuilderStep<LastStep> where
    LastStep: Send

impl<LastStep> Sync for PacketBuilderStep<LastStep> where
    LastStep: Sync

Blanket Implementations

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

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

The type returned in the event of a conversion error.

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> Any for T where
    T: 'static + ?Sized
[src]