def ip_frag(packet):
    '''
    Not fragments:
        ip_frag(packet) == 0
        not ip_frag(packet)
        
    First packet of fragments:
        ip_frag(packet) == IP_FRAG_ANY
    
    Not first packet of fragments:
        ip_frag(packet) & IP_FRAG_LATER
    
    All fragments:
        ip_frag(packet) & IP_FRAG_ANY

    '''
    return ((packet.frag_off & IP_OFFMASK) and IP_FRAG_LATER) | ((packet.frag_off & (IP_OFFMASK | IP_MF)) and IP_FRAG_ANY)
Not fragments:
        ip_frag(packet) == 0
        not ip_frag(packet)
        
    First packet of fragments:
        ip_frag(packet) == IP_FRAG_ANY
    
    Not first packet of fragments:
        ip_frag(packet) & IP_FRAG_LATER
    
    All fragments:
        ip_frag(packet) & IP_FRAG_ANY