default

PPPoE (PPP over Ethernet) header encoding and decoding (RFC 2516).

Examples

Round-trip a PADI discovery packet

import { assertEquals } from "@std/assert";
import { pppoeHeader, PPPOE_CODE, PPPOE_HEADER_SIZE } from "@binstruct/pppoe";

const coder = pppoeHeader();
const packet = {
  versionType: { version: 1, type: 1 },
  code: PPPOE_CODE.PADI,
  sessionId: 0,
  length: 4,
  payload: new Uint8Array([0x01, 0x01, 0x00, 0x00]),
};

const buffer = new Uint8Array(PPPOE_HEADER_SIZE + packet.payload.length);
const written = coder.encode(packet, buffer);
const [decoded, read] = coder.decode(buffer.subarray(0, written));

assertEquals(written, read);
assertEquals(decoded.code, PPPOE_CODE.PADI);
assertEquals(decoded.sessionId, 0);
assertEquals(decoded.payload, packet.payload);

Functions

f
pppoeHeader(): Coder<PppoeHeader>

Creates a coder for a PPPoE header and its payload (RFC 2516).

Interfaces

Variables

v
ETHERTYPE_PPPOE_DISCOVERY: 34915

EtherType assigned to the PPPoE Discovery stage (0x8863). The value an Ethernet II frame's etherType field carries when its payload is a Discovery stage PPPoE packet (PADI, PADO, PADR, PADS, PADT).

v
ETHERTYPE_PPPOE_SESSION: 34916

EtherType assigned to the PPPoE Session stage (0x8864). The value an Ethernet II frame's etherType field carries when its payload is a Session stage PPPoE packet carrying a PPP frame.

v
PPPOE_CODE: { SESSION_DATA: number; PADO: number; PADI: number; PADR: number; PADS: number; PADT: number; }

Values used by the PPPoE header's code field, distinguishing Session data from the five Discovery stage packet types.

  • PADI: number

    PPPoE Active Discovery Initiation, broadcast by a Host to begin Discovery.

  • PADO: number

    PPPoE Active Discovery Offer, sent by an Access Concentrator in reply to a PADI.

  • PADR: number

    PPPoE Active Discovery Request, sent by a Host to the chosen Access Concentrator.

  • PADS: number

    PPPoE Active Discovery Session-confirmation, sent by an Access Concentrator in reply to a PADR.

  • PADT: number

    PPPoE Active Discovery Terminate, sent by either peer to end a session.

  • SESSION_DATA: number

    Session stage data — the payload carries a PPP frame.

v
PPPOE_HEADER_SIZE: 6

Size in bytes of the fixed PPPoE header (version/type, code, session ID, length). The length field does not include these 6 bytes — it covers only the payload that follows.