default

ARP (Address Resolution Protocol) packet encoding and decoding.

Examples

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");

Functions

f
arpData(): Coder<ArpData>

Creates a coder for the common Ethernet/IPv4 ARP packet (RFC 826).

Interfaces

Type Aliases

T
ArpOpcode = (ARP_OPCODE)[keyof ARP_OPCODE]

Union of the ARP_OPCODE values.

Variables

v
ARP_ETHERNET_IPV4_SIZE: 28

Total wire size of an Ethernet/IPv4 ARP packet, in bytes.

v
ARP_HARDWARE_TYPE: { ETHERNET: number; }

ARP hardware type values (the htype field) for common link layers.

v
ARP_HW_LEN_ETHERNET: 6

Length of an Ethernet hardware address in bytes.

v
ARP_OPCODE: { REQUEST: number; REPLY: number; RARP_REQUEST: number; RARP_REPLY: number; }

ARP operation codes (the oper field).

v
ARP_PROTO_LEN_IPV4: 4

Length of an IPv4 protocol address in bytes.

v
ARP_PROTOCOL_TYPE: { IPV4: number; }

ARP protocol type values (the ptype field) for common upper layers.

v
ETHERTYPE_ARP: 2054

EtherType assigned to ARP (0x0806). The value an Ethernet II frame's etherType field carries when its payload is an ARP packet.