---
name: "Net::Frame::Layer::IPv4"
section: "3pm"
platform: "linux"
package: "libnet-frame-perl"
version: "1.21-2"
release: "Debian 13 (Trixie)"
platforms: ["linux"]
url: "https://new.carta.tech/Net::Frame::Layer::IPv4"
---

# Net::Frame::Layer::IPv4(3pm)

Internet Protocol v4 layer object

## NAME

Net::Frame::Layer::IPv4 - Internet Protocol v4 layer object

## SYNOPSIS

```
   use Net::Frame::Layer::IPv4 qw(:consts);
   # Build a layer
   my $layer = Net::Frame::Layer::IPv4->new(
      version  => 4,
      tos      => 0,
      id       => getRandom16bitsInt(),
      length   => NF_IPv4_HDR_LEN,
      hlen     => 5,
      flags    => 0,
      offset   => 0,
      ttl      => 128,
      protocol => NF_IPv4_PROTOCOL_TCP,
      checksum => 0,
      src      => '127.0.0.1',
      dst      => '127.0.0.1',
      options  => '',
      noFixLen => 0,
   );
   $layer->pack;
   print 'RAW: '.$layer->dump."\n";
   # Read a raw layer
   my $layer = Net::Frame::Layer::IPv4->new(raw => $raw);
   print $layer->print."\n";
   print 'PAYLOAD: '.unpack('H*', $layer->payload)."\n"
      if $layer->payload;
```

## DESCRIPTION

This modules implements the encoding and decoding of the IPv4 layer.

RFC: ftp://ftp.rfc-editor.org/in-notes/rfc791.txt

See also **Net::Frame::Layer** for other attributes and methods.

## ATTRIBUTES

- **id**

  IP ID of the datagram.

- **ttl**

  Time to live.

- **src**

  - **dst**

  Source and destination IP addresses.

- **protocol**

  Of which type the layer 4 is.

- **checksum**

  IP checksum.

- **flags**

  IP Flags.

- **offset**

  IP fragment offset.

- **version**

  IP version, here it is 4.

- **tos**

  Type of service flag.

- **length**

  Total length in bytes of the packet, including IP headers (that is, layer 3 + layer 4 + layer 7).

- **hlen**

  Header length in number of words, including IP options.

- **options**

  IP options, as a hexadecimal string.

- **noFixLen**

  Since the byte ordering of **length** attribute varies from system to system, a subroutine inside this module detects which byte order to use. Sometimes, like when you build **Net::Frame::Layer::8021Q** layers, you may have the need to avoid this. So set it to 1 in order to avoid fixing. Default is 0 (that is to fix).

The following are inherited attributes. See **Net::Frame::Layer** for more information.

- **raw**

  - **payload**

  - **nextLayer**

  ## METHODS

- **new**

  - **new** (hash)

  Object constructor. You can pass attributes that will overwrite default ones. See **SYNOPSIS** for default values.

- **getHeaderLength**

  Returns the header length in bytes, not including IP options.

- **getOptionsLength**

  Returns the length in bytes of IP options. 0 if none.

- **computeLengths** ({ payloadLength =\> VALUE })

  In order to compute lengths attributes within IPv4 header, you need to pass via a hashref the number of bytes contained in IPv4 payload (that is, the sum of all layers after the IPv4 one).

- **computeChecksums**

  Computes the IPv4 checksum.

The following are inherited methods. Some of them may be overridden in this layer, and some others may not be meaningful in this layer. See **Net::Frame::Layer** for more information.

- **layer**

  - **computeLengths**

  - **computeChecksums**

  - **pack**

  - **unpack**

  - **encapsulate**

  - **getLength**

  - **getPayloadLength**

  - **print**

  - **dump**

  ## CONSTANTS

Load them: use Net::Frame::Layer::IPv4 qw(:consts);

- **NF\_IPv4\_PROTOCOL\_ICMPv4**

  - **NF\_IPv4\_PROTOCOL\_IGMP**

  - **NF\_IPv4\_PROTOCOL\_IPIP**

  - **NF\_IPv4\_PROTOCOL\_TCP**

  - **NF\_IPv4\_PROTOCOL\_EGP**

  - **NF\_IPv4\_PROTOCOL\_IGRP**

  - **NF\_IPv4\_PROTOCOL\_CHAOS**

  - **NF\_IPv4\_PROTOCOL\_UDP**

  - **NF\_IPv4\_PROTOCOL\_IDP**

  - **NF\_IPv4\_PROTOCOL\_DCCP**

  - **NF\_IPv4\_PROTOCOL\_IPv6**

  - **NF\_IPv4\_PROTOCOL\_IPv6ROUTING**

  - **NF\_IPv4\_PROTOCOL\_IPv6FRAGMENT**

  - **NF\_IPv4\_PROTOCOL\_IDRP**

  - **NF\_IPv4\_PROTOCOL\_RSVP**

  - **NF\_IPv4\_PROTOCOL\_GRE**

  - **NF\_IPv4\_PROTOCOL\_ESP**

  - **NF\_IPv4\_PROTOCOL\_AH**

  - **NF\_IPv4\_PROTOCOL\_ICMPv6**

  - **NF\_IPv4\_PROTOCOL\_EIGRP**

  - **NF\_IPv4\_PROTOCOL\_OSPF**

  - **NF\_IPv4\_PROTOCOL\_ETHERIP**

  - **NF\_IPv4\_PROTOCOL\_PIM**

  - **NF\_IPv4\_PROTOCOL\_VRRP**

  - **NF\_IPv4\_PROTOCOL\_STP**

  - **NF\_IPv4\_PROTOCOL\_SCTP**

  - **NF\_IPv4\_PROTOCOL\_UDPLITE**

  Various protocol type constants.

- **NF\_IPv4\_MORE\_FRAGMENT**

  - **NF\_IPv4\_DONT\_FRAGMENT**

  - **NF\_IPv4\_RESERVED\_FRAGMENT**

  Various possible flags.

## SEE ALSO

Net::Frame::Layer

## AUTHOR

Patrice \<GomoR\> Auffret

## COPYRIGHT AND LICENSE

Copyright (c) 2006-2019, Patrice \<GomoR\> Auffret

You may distribute this module under the terms of the Artistic license. See LICENSE.Artistic file in the source distribution archive.
