Inet stack coder for the @binstruct/* packet family.
Round-trip a UDP-over-IPv4-over-Ethernet frame
Round-trip a UDP-over-IPv4-over-Ethernet frame
import { assert, assertEquals } from "@std/assert"; import { parseAddressv4 } from "@hertzg/ip/addressv4"; import { ETHERTYPE_IPV4 } from "@binstruct/ipv4"; import { IP_PROTOCOL_UDP } from "@binstruct/udp"; import { inetFrame } from "@binstruct/inet"; const value = { dstMac: new Uint8Array([0, 0, 0, 0, 0, 1]), srcMac: new Uint8Array([0, 0, 0, 0, 0, 2]), etherType: ETHERTYPE_IPV4, payload: { versionIhl: { version: 4, ihl: 5 }, typeOfService: 0, totalLength: 32, identification: 0, flagsFragmentOffset: { reserved: 0, dontFragment: 0, moreFragments: 0, fragmentOffset: 0 }, timeToLive: 64, protocol: IP_PROTOCOL_UDP, headerChecksum: 0, sourceAddress: parseAddressv4("192.0.2.1").address, destinationAddress: parseAddressv4("192.0.2.2").address, options: new Uint8Array(0), payload: { srcPort: 53, dstPort: 49152, length: 12, checksum: 0, payload: new Uint8Array([0xde, 0xad, 0xbe, 0xef]), }, }, }; const coder = inetFrame(); const buf = new Uint8Array(64); const written = coder.encode(value, buf); const [decoded] = coder.decode(buf.subarray(0, written)); assert(!(decoded.payload instanceof Uint8Array)); assert("protocol" in decoded.payload); assert(!(decoded.payload.payload instanceof Uint8Array)); assert("srcPort" in decoded.payload.payload); assertEquals(decoded.payload.payload.payload, new Uint8Array([0xde, 0xad, 0xbe, 0xef]));
Creates a composed coder that walks an Ethernet II frame
(@binstruct/ethernet) top-down, dispatching the L2.5/L3 payload by
etherType and every deeper layer by its own discriminator field. Frames
whose tag has no matching coder surface their payload as a raw
Uint8Array.
Computes the 16-bit Internet checksum (RFC 1071) over a span of bytes.
Creates a composed coder that walks a Linux cooked capture (SLL v1)
header (@binstruct/sll) top-down, dispatching the payload by protocol
— the same EtherType-space dispatch inetFrame performs on
Ethernet's etherType, reused here via l3Refiners. Payloads
whose tag has no matching coder surface as a raw Uint8Array.
Ethernet frame whose payload is an Ethernet/IPv4 ARP packet.
| Ipv6Frame
| ArpFrame
| PppoeDiscoveryFrame
| PppoeSessionFrame
| VlanFrame
| Frame
Decoded Ethernet II frame as produced by inetFrame.
IPv4 datagram with a typed ESP transport payload.
Ethernet frame whose payload is a typed IPv4 datagram.
IPv4 datagram with a typed ICMPv4 transport payload.
IPv4 datagram with a typed IGMP transport payload.
| Ipv4UdpPacket
| Ipv4IcmpPacket
| Ipv4IgmpPacket
| Ipv4EspPacket
| Ipv4Packet
Refined IPv4 datagram — payload narrows by shape (TCP / UDP / ICMP /
IGMP / ESP / raw bytes) and the host's protocol field is the on-wire
discriminator.
IPv4 datagram with a typed TCP transport payload.
IPv4 datagram with a typed UDP transport payload.
IPv6 packet with a typed ESP transport payload.
Ethernet frame whose payload is a typed IPv6 packet.
IPv6 packet with a typed ICMPv6 transport payload.
| Ipv6UdpPacket
| Ipv6Icmpv6Packet
| Ipv6EspPacket
| Ipv6Packet
Refined IPv6 packet — payload narrows by shape (TCP / UDP / ICMPv6 /
ESP / raw bytes) and the host's nextHeader field is the on-wire
discriminator.
IPv6 packet with a typed TCP transport payload.
IPv6 packet with a typed UDP transport payload.
Ethernet frame whose payload is a PPPoE Discovery-stage packet.
PPP frame with a typed IPv4 payload.
PPP frame with a typed IPv6 payload.
Ethernet frame whose payload is a PPPoE Session-stage packet.
& { payload: PppoeSessionRefined; }
PPPoE Session-stage header whose payload is a typed PPP frame.
Refined PPP frame as carried inside a PPPoE Session payload — payload
narrows by shape (IPv4 / IPv6 / raw bytes), dispatched by the PPP
protocol ID.
Linux cooked capture (SLL) header whose payload is an ARP packet.
| SllIpv6Frame
| SllArpFrame
| SllPppoeDiscoveryFrame
| SllPppoeSessionFrame
| SllVlanFrame
| SllHeader
Decoded Linux cooked capture (SLL v1) header as produced by
sllInetFrame. Mirrors FrameRefined one layer down —
SLL replaces the real link layer with its own fixed header, but dispatches
through the exact same l3Refiners arms via protocol in place
of Ethernet's etherType.
Linux cooked capture (SLL) header whose payload is a typed IPv4 datagram.
Linux cooked capture (SLL) header whose payload is a typed IPv6 packet.
Linux cooked capture (SLL) header whose payload is a PPPoE Discovery-stage packet.
& { payload: PppoeSessionPacket; }
Linux cooked capture (SLL) header whose payload is a PPPoE Session-stage packet.
Linux cooked capture (SLL) header whose payload is a typed VLAN tag.
UDP datagram with a typed BFD control payload.
UDP datagram with a typed NTP transport payload.
Refined UDP datagram — payload narrows by shape (VXLAN / NTP / BFD /
raw bytes), dispatched by destination port (falling back to source port)
since UDP carries no in-band type tag. See udpFrame.
& { payload: VxlanEthernetFrame; }
UDP datagram with a typed VXLAN transport payload.
VLAN tag with a typed ARP payload.
Ethernet frame whose payload is a typed VLAN tag.
VLAN tag with a typed IPv4 payload.
VLAN tag with a typed IPv6 payload.
VLAN tag with a typed PPPoE Discovery-stage payload.
VLAN tag with a typed PPPoE Session-stage payload.
VLAN tag carrying a single further nested (QinQ) VLAN tag.
Refined VLAN tag — payload narrows by shape (IPv4 / IPv6 / ARP / PPPoE
Discovery / PPPoE Session / one further nested VLAN tag / raw bytes),
dispatched by the tag's own encapsulated EtherType. This is what
vlanFrame``(1) produces, the depth used at every true root
(inetFrame, sllInetFrame).
| VlanIpv6Frame
| VlanArpFrame
| VlanPppoeDiscoveryFrame
| VlanPppoeSessionFrame
| VlanTag
Refined VLAN tag with no further VLAN dispatch available — payload
narrows by shape (IPv4 / IPv6 / ARP / PPPoE Discovery / PPPoE Session /
raw bytes). This is what vlanFrame``(0) produces: the inner
tag of a QinQ pair, which does not itself dispatch a third stacked VLAN
tag.
& { innerFrame: FrameRefined; }
VXLAN header whose inner frame is a typed Ethernet stack.