ARP (Address Resolution Protocol) packet encoding and decoding.
Decode an Ethernet/IPv4 ARP request
Decode an Ethernet/IPv4 ARP request
import { assertEquals } from "@std/assert"; import { stringifyAddressv4 } from "@hertzg/ip/addressv4"; import { stringify as stringifyMac } from "@hertzg/mac"; import { ARP_HARDWARE_TYPE, ARP_OPCODE, ARP_PROTOCOL_TYPE, arpData, } from "@binstruct/arp"; // deno-fmt-ignore const wire = new Uint8Array([ 0x00, 0x01, // htype: Ethernet 0x08, 0x00, // ptype: IPv4 0x06, // hlen 0x04, // plen 0x00, 0x01, // oper: request 0x00, 0x11, 0x22, 0x33, 0x44, 0x55, // sha 0xc0, 0xa8, 0x01, 0x01, // spa: 192.168.1.1 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // tha (unknown) 0xc0, 0xa8, 0x01, 0x02, // tpa: 192.168.1.2 ]); const [packet, bytesRead] = arpData().decode(wire); assertEquals(bytesRead, 28); assertEquals(packet.hardwareType, ARP_HARDWARE_TYPE.ETHERNET); assertEquals(packet.protocolType, ARP_PROTOCOL_TYPE.IPV4); assertEquals(packet.operation, ARP_OPCODE.REQUEST); assertEquals(stringifyMac(packet.senderHardwareAddress), "00:11:22:33:44:55"); assertEquals(stringifyAddressv4(packet.senderProtocolAddress), "192.168.1.1"); assertEquals(stringifyAddressv4(packet.targetProtocolAddress), "192.168.1.2");
Creates a coder for the common Ethernet/IPv4 ARP packet (RFC 826).
Decoded Ethernet/IPv4 ARP packet (RFC 826, 28 bytes).
Union of the ARP_HARDWARE_TYPE values.
Union of the ARP_OPCODE values.
Union of the ARP_PROTOCOL_TYPE values.
Total wire size of an Ethernet/IPv4 ARP packet, in bytes.
ARP hardware type values (the htype field) for common link layers.
-
ETHERNET: number
Ethernet (10/100/1000Mb).
Length of an Ethernet hardware address in bytes.
ARP operation codes (the oper field).
-
RARP_REPLY: number
RARP reply — protocol address for the requested hardware address.
-
RARP_REQUEST: number
RARP request — "who am I", given my hardware address (RFC 903).
-
REPLY: number
ARP reply — sender's MAC for the requested protocol address.
-
REQUEST: number
ARP request — "who has TPA, tell SPA".
Length of an IPv4 protocol address in bytes.
ARP protocol type values (the ptype field) for common upper layers.
-
IPV4: number
Internet Protocol version 4.
EtherType assigned to ARP (0x0806). The value an Ethernet II frame's
etherType field carries when its payload is an ARP packet.