Struct etherparse::PacketBuilderStep
source · pub struct PacketBuilderStep<LastStep> { /* private fields */ }
Expand description
An unfinished packet that is build with the packet builder
Implementations§
source§impl PacketBuilderStep<Ethernet2Header>
impl PacketBuilderStep<Ethernet2Header>
sourcepub fn ipv4(
self,
source: [u8; 4],
destination: [u8; 4],
time_to_live: u8
) -> PacketBuilderStep<IpHeader>
pub fn ipv4(
self,
source: [u8; 4],
destination: [u8; 4],
time_to_live: u8
) -> PacketBuilderStep<IpHeader>
Add an ip v4 header
sourcepub fn ip(self, ip_header: IpHeader) -> PacketBuilderStep<IpHeader>
pub fn ip(self, ip_header: IpHeader) -> PacketBuilderStep<IpHeader>
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])
.ip(IpHeader::Version4(Ipv4Header{
header_length: 0, //will be replaced during write
differentiated_services_code_point: 0,
explicit_congestion_notification: 0,
total_length: 0, //will be replaced during write
identification: 0,
dont_fragment: true,
more_fragments: false,
fragments_offset: 0,
time_to_live: 12,
protocol: 0, //will be replaced during write
header_checksum: 0, //will be replaced during write
source: [0,1,2,3],
destination: [4,5,6,7]
}));
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]
}));
sourcepub fn ipv6(
self,
source: [u8; 16],
destination: [u8; 16],
hop_limit: u8
) -> PacketBuilderStep<IpHeader>
pub fn ipv6(
self,
source: [u8; 16],
destination: [u8; 16],
hop_limit: u8
) -> PacketBuilderStep<IpHeader>
Add an ip v6 header
sourcepub fn vlan(self, vlan: VlanHeader) -> PacketBuilderStep<VlanHeader>
pub fn vlan(self, vlan: VlanHeader) -> PacketBuilderStep<VlanHeader>
Adds a vlan tagging header with the given vlan identifier
sourcepub fn single_vlan(self, vlan_identifier: u16) -> PacketBuilderStep<VlanHeader>
pub fn single_vlan(self, vlan_identifier: u16) -> PacketBuilderStep<VlanHeader>
Adds a vlan tagging header with the given vlan identifier
sourcepub fn double_vlan(
self,
outer_vlan_identifier: u16,
inner_vlan_identifier: u16
) -> PacketBuilderStep<VlanHeader>
pub fn double_vlan(
self,
outer_vlan_identifier: u16,
inner_vlan_identifier: u16
) -> PacketBuilderStep<VlanHeader>
Adds two vlan tagging header with the given vlan identifiers (also known as double vlan tagging).
source§impl PacketBuilderStep<VlanHeader>
impl PacketBuilderStep<VlanHeader>
sourcepub fn ip(self, ip_header: IpHeader) -> PacketBuilderStep<IpHeader>
pub fn ip(self, ip_header: IpHeader) -> PacketBuilderStep<IpHeader>
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])
.ip(IpHeader::Version4(Ipv4Header{
header_length: 0, //will be replaced during write
differentiated_services_code_point: 0,
explicit_congestion_notification: 0,
total_length: 0, //will be replaced during write
identification: 0,
dont_fragment: true,
more_fragments: false,
fragments_offset: 0,
time_to_live: 12,
protocol: 0, //will be replaced during write
header_checksum: 0, //will be replaced during write
source: [0,1,2,3],
destination: [4,5,6,7]
}));
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]
}));
source§impl PacketBuilderStep<TcpHeader>
impl PacketBuilderStep<TcpHeader>
sourcepub fn ns(self) -> PacketBuilderStep<TcpHeader>
pub fn ns(self) -> PacketBuilderStep<TcpHeader>
Set ns flag (ECN-nonce - concealment protection; experimental: see RFC 3540)
sourcepub fn fin(self) -> PacketBuilderStep<TcpHeader>
pub fn fin(self) -> PacketBuilderStep<TcpHeader>
Set fin flag (No more data from sender)
sourcepub fn syn(self) -> PacketBuilderStep<TcpHeader>
pub fn syn(self) -> PacketBuilderStep<TcpHeader>
Set the syn flag (synchronize sequence numbers)
sourcepub fn rst(self) -> PacketBuilderStep<TcpHeader>
pub fn rst(self) -> PacketBuilderStep<TcpHeader>
Sets the rst flag (reset the connection)
sourcepub fn psh(self) -> PacketBuilderStep<TcpHeader>
pub fn psh(self) -> PacketBuilderStep<TcpHeader>
Sets the psh flag (push function)
sourcepub fn ack(self, acknowledgment_number: u32) -> PacketBuilderStep<TcpHeader>
pub fn ack(self, acknowledgment_number: u32) -> PacketBuilderStep<TcpHeader>
Sets the ack flag and the acknowledgment_number.
sourcepub fn urg(self, urgent_pointer: u16) -> PacketBuilderStep<TcpHeader>
pub fn urg(self, urgent_pointer: u16) -> PacketBuilderStep<TcpHeader>
Set the urg flag & the urgent pointer field.
The urgent pointer points to the sequence number of the octet following the urgent data.
sourcepub fn ece(self) -> PacketBuilderStep<TcpHeader>
pub fn ece(self) -> PacketBuilderStep<TcpHeader>
Sets ece flag (ECN-Echo, RFC 3168)
sourcepub fn cwr(self) -> PacketBuilderStep<TcpHeader>
pub fn cwr(self) -> PacketBuilderStep<TcpHeader>
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).
sourcepub fn options(
self,
options: &[TcpOptionElement]
) -> Result<PacketBuilderStep<TcpHeader>, TcpOptionWriteError>
pub fn options(
self,
options: &[TcpOptionElement]
) -> Result<PacketBuilderStep<TcpHeader>, TcpOptionWriteError>
Set the tcp options of the header.
sourcepub fn options_raw(
self,
options: &[u8]
) -> Result<PacketBuilderStep<TcpHeader>, TcpOptionWriteError>
pub fn options_raw(
self,
options: &[u8]
) -> Result<PacketBuilderStep<TcpHeader>, TcpOptionWriteError>
Set the tcp options of the header (setting the bytes directly).