Constructor
new Packet(dataopt)
Parameters:
| Name | Type | Attributes | Description | ||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
data | Object | <optional> | Packet data, options object, or existing packetProperties
|
Examples
// Create an ICMP echo request packet
const packet = new Packet({ iface: 'eth0' })
.Ethernet({ dst: 'ff:ff:ff:ff:ff:ff', src: '00:11:22:33:44:55' })
.IPv4({ src: '192.168.1.1', dst: '8.8.8.8', timeToLive: 64 })
.ICMP({ type: 8, code: 0, id: 12345, sequence: 1 });// Parse existing packet
const packet = new Packet({ buffer: rawBuffer });
console.log(packet.layers.IPv4.src);Extends
- LayersList
Members
buffer
Raw buffer containing the complete packet data Automatically builds packet if layers were added
Methods
ARP(data) → {Packet}
Adds ARP layer to the packet stack
Parameters:
| Name | Type | Description | ||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
data | Object | The layer dataProperties
|
Returns:
the packet instance
- Type:
- Packet
DHCP(data) → {Packet}
Adds DHCP layer to the packet stack
Parameters:
| Name | Type | Description | ||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
data | Object | The layer dataProperties
|
Returns:
the packet instance
- Type:
- Packet
DNS(data) → {Packet}
Adds DNS layer to the packet stack
Parameters:
| Name | Type | Description | |||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
data | Object | The layer dataProperties
|
Returns:
the packet instance
- Type:
- Packet
Ethernet(data) → {Packet}
Adds Ethernet layer to the packet stack
Parameters:
| Name | Type | Description | ||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
data | Object | The layer dataProperties
|
Returns:
the packet instance
- Type:
- Packet
GRE(data) → {Packet}
Adds GRE layer to the packet stack
Parameters:
| Name | Type | Description | ||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
data | Object | The layer dataProperties
|
Returns:
the packet instance
- Type:
- Packet
ICMP(data) → {Packet}
Adds ICMP layer to the packet stack
Parameters:
| Name | Type | Description | ||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
data | Object | The layer dataProperties
|
Returns:
the packet instance
- Type:
- Packet
ICMPv6(data) → {Packet}
Adds ICMPv6 layer to the packet stack
Parameters:
| Name | Type | Description | ||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
data | Object | The layer dataProperties
|
Returns:
the packet instance
- Type:
- Packet
IPv4(data) → {Packet}
Adds IPv4 layer to the packet stack
Parameters:
| Name | Type | Description | ||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
data | Object | The layer dataProperties
|
Returns:
the packet instance
- Type:
- Packet
IPv6(data) → {Packet}
Adds IPv6 layer to the packet stack
Parameters:
| Name | Type | Description | |||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
data | Object | The layer dataProperties
|
Returns:
the packet instance
- Type:
- Packet
NTP(data) → {Packet}
Adds NTP layer to the packet stack
Parameters:
| Name | Type | Description | ||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
data | Object | The layer dataProperties
|
Returns:
the packet instance
- Type:
- Packet
Payload(data) → {Packet}
Adds Payload layer to the packet stack
Parameters:
| Name | Type | Description |
|---|---|---|
data | Object | The layer data |
Returns:
the packet instance
- Type:
- Packet
TCP(data) → {Packet}
Adds TCP layer to the packet stack
Parameters:
| Name | Type | Description | |||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
data | Object | The layer dataProperties
|
Returns:
the packet instance
- Type:
- Packet
UDP(data) → {Packet}
Adds UDP layer to the packet stack
Parameters:
| Name | Type | Description | |||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
data | Object | The layer dataProperties
|
Returns:
the packet instance
- Type:
- Packet
Vlan(data) → {Packet}
Adds Vlan layer to the packet stack
Parameters:
| Name | Type | Description | |||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
data | Object | The layer dataProperties
|
Returns:
the packet instance
- Type:
- Packet
clone() → {Packet}
Creates a deep clone of the packet Preserves all layers, timestamps, and interface settings
Returns:
New packet instance identical to this one
- Type:
- Packet
equals(pkt) → {boolean}
Compares this packet with another packet for equality
Parameters:
| Name | Type | Description |
|---|---|---|
pkt | Packet | The packet to compare with |
Returns:
True if packets are identical (same interface, timestamp, and buffer content)
- Type:
- boolean
Example
const packet1 = new Packet({ buffer: data });
const packet2 = new Packet({ buffer: data });
if (packet1.equals(packet2)) {
console.log('Packets are identical');
}toObject() → {Object|Object|Object}
Converts the packet to a plain JavaScript object
Returns:
- Plain object representation
- Type:
- Object
- returns.iface - Interface configuration
- Type:
- Object
- returns.layers - Layer objects with their fields
- Type:
- Object
Example
const obj = packet.toObject();
console.log(obj.layers.IPv4.src);