IPV4(3)

πŸ’– IPV4(3) β€” the ipv4 module, bestie edition πŸ’–

okay so this is packet.internet.ipv4, from ipv4 1.3, and it's the glow-up your packet parsing deserved. sit down, grab a boba, we're decoding the internet layer together 🧚✨


✨ NAME ✨

packet.internet.ipv4 β€” the IPv4 module. that's it, that's the name, she's simple and she serves πŸ’…


🌸 DESCRIPTION 🌸

Decode the IP version 4 layer. like, that whole "hello i am an IPv4 header and i contain the plot" situation. literally the main character of the network stack πŸ‘‘


πŸŽ€ CLASSES πŸŽ€

πŸ’œ class Flags(baseobj.BaseObj)

the Flags object. tiny, but she holds the drama (the fragment drama, specifically).

Methods defined here:


  • __init__(self, data) β€” the constructor, and she takes exactly one thing: a single byte as input. one byte. that's all she needs 🫢

πŸ¦‹ class IPv4(baseobj.BaseObj)

the IPv4 object herself. iconic. no notes.

Usage:

from packet.internet.ipv4 import IPv4

x = IPv4(pktt)

Object definition:

IPv4(
    version         = int,
    IHL             = int, # Internet Header Length (in 32bit words)
    header_size     = int, # IHL in actual bytes
    DSCP            = int, # Differentiated Services Code Point
    ECN             = int, # Explicit Congestion Notification
    total_size      = int, # Total length
    id              = int, # Identification
    flags = Flags(         # Flags:
        DF = int,          #   Don't Fragment
        MF = int,          #   More Fragments
    )
    fragment_offset = int, # Fragment offset (in 8-byte blocks)
    TTL             = int, # Time to Live
    protocol        = int, # Protocol of next layer (RFC790)
    checksum        = int, # Header checksum
    src             = "%d.%d.%d.%d", # source IP address
    dst             = "%d.%d.%d.%d", # destination IP address
    options = string, # IP options if available
    psize = int       # Payload data size
    data = string,    # Raw data of payload if protocol
                      # is not supported
)

Methods defined here:


πŸ“ __init__(self, pktt)

Constructor. she initializes the object's private data, very "let me set up my little world" energy πŸ’«

  • pktt: the Packet trace object (packet.pktt.Pktt), passed in so this layer has access to the parent layers. it's giving family reunion, but useful 🫢

⭐ __str__(self)

String representation of the object. and the way she represents depends on the verbose level you set with debug_repr() πŸ‘€

  • if it's set to 0, you get the generic object representation. no frills, just vibes.
  • if it's set to 1, the representation of the object is condensed:
'192.168.0.20 -> 192.168.0.61 '
  • if it's set to 2, the representation of the object also includes the protocol and the length of payload:
'192.168.0.20 -> 192.168.0.61, protocol: 17(UDP), len: 84'

so basically level 2 is the full lore drop πŸ”₯


🌈 SEE ALSO 🌈

baseobj(3), packet.transport.tcp(3), packet.transport.udp(3), packet.utils(3)

the friend group. go say hi πŸ’–


πŸ’€ BUGS πŸ’€

No known bugs. she's clean, she's unproblematic, we love to see it ✨


πŸ‘‘ AUTHOR πŸ‘‘

Jorge Mora (mora@netapp.com) β€” thank you for your service, king πŸ«‘πŸ’œ


and that's the whole page, bestie!! this was NFStest 3.2, dated 21 March 2023, and honestly? a classic. go forth and decode some packets. mwah πŸ’…πŸ’–