dpkt icon indicating copy to clipboard operation
dpkt copied to clipboard

Get header ip options and padding with dpkt

Open andypitcher opened this issue 6 years ago • 1 comments

Hi,

Is there a way to retrieve the ip options and padding from ip.py in dpkt? I would like to get router alert at the end, and the padding, I can't find the options within the below code when hdr is defining the ip header values:

class IP(dpkt.Packet):
    """Internet Protocol.
    TODO: Longer class information....
    Attributes:
        __hdr__: Header fields of IP.
        TODO.
    """

    __hdr__ = (
        ('_v_hl', 'B', (4 << 4) | (20 >> 2)),
        ('tos', 'B', 0),
        ('len', 'H', 20),
        ('id', 'H', 0),
        ('off', 'H', 0),
        ('ttl', 'B', 64),
        ('p', 'B', 0),
        ('sum', 'H', 0),
        ('src', '4s', b'\x00' * 4),
        ('dst', '4s', b'\x00' * 4)
    )
    _protosw = {}
    opts = b''

Thanks!

andypitcher avatar Jul 16 '18 23:07 andypitcher

Hi,

This issue can be partially resolved, here is the code to retrieve IP router alert:

  #Check router alert (HL has to be above 5 and ip.opts == '\x94\x04\x00\x00')
            if ip.hl > 5:
                if ip.opts == dpkt.ip.IP_OPT_RALERT:
                    ip_ralert=1

IP_OPT_RALERT line has been added to dpkt ip.py source code:


# Reserved Addresses
IP_ADDR_ANY = "\x00\x00\x00\x00"    # 0.0.0.0
IP_ADDR_BROADCAST = "\xff\xff\xff\xff"    # 255.255.255.255
IP_ADDR_LOOPBACK = "\x7f\x00\x00\x01"    # 127.0.0.1
IP_ADDR_MCAST_ALL = "\xe0\x00\x00\x01"    # 224.0.0.1
IP_ADDR_MCAST_LOCAL = "\xe0\x00\x00\xff"    # 224.0.0.255
IP_OPT_RALERT= "\x94\x04\x00\x00"

Cheers!

andypitcher avatar Sep 10 '18 19:09 andypitcher