IPv4

IPv4 protocol layer

Constructor

new IPv4(data, opts)

Parameters:
NameTypeDescription
dataBuffer | ObjectInput buffer or object with protocol fields.
optsObjectOptions for the layer.
Properties
NameTypeDescription
headerLengthnumberIP header length, has the value of 5 for IPv4.
versionnumberIP version number, has the value of 4 for IPv4.
typeOfServicenumbertype of service, same as Differentiated Services Code Point (DSCP)
totalLengthnumberEntire packet (fragment) size, including header and data, in bytes
idnumberIdentification field. Primarily used for uniquely identifying the group of fragments of a single IP datagram
fragmentOffsetRawnumberFragment offset field, measured in units of eight-byte blocks (64 bits) @LE
timeToLivenumberAn eight-bit time to live field helps prevent datagrams from persisting (e.g. going in circles) on an internet. In practice, the field has become a hop count
protocolnumberDefines the protocol used in the data portion of the IP datagram. Must be one of ::IPProtocolTypes
checksumnumberError-checking of the header
srcstringIPv4 address of the sender of the packet
dststringIPv4 address of the receiver of the packet
Implements

Members

dst :string

The destination IP address in human-readable format.
Type:
  • string

fragmentOffsetFlags :number

Type:
  • number

fragmentOffsetValue :number

Type:
  • number

isFirstFragment :boolean

Type:
  • boolean

isFragment :boolean

Type:
  • boolean

isLastFragment :boolean

Type:
  • boolean

length :number

Number of bytes occupied by the layer.
Type:
  • number
Implements

osi :OsiModelLayers

Respective protocol OSI layer.
Implements

src :string

The source IP address in human-readable format.
Type:
  • string

Methods

calculateChecksum()

Calculates and updates the checksum for the IPv4 layer. This method mutates the object by setting the `checksum` property based on the current state of the `buffer`.

toObject() → {Object}

Returns an object with all protcol fields without owning the underlying buffer. Useful to read all the data and use it without having to deal with binary representation.
Implements
Returns:
- All protocol fields
Type: 
Object