(pktlist)
return IPv6(str(q))
Performs defragmentation of a list of IPv6 packets. Packets are reordered.
    Crap is dropped. What lacks is completed by 'X' characters.
Performs defragmentation of a list of IPv6 packets. Packets are reordered.
    Crap is dropped. What lacks is completed by 'X' characters.
Performs defragmentation of a list of IPv6 packets . Packets are reordered . Crap is dropped . What lacks is completed by X characters .
def defragment6(pktlist):
    """
    Performs defragmentation of a list of IPv6 packets. Packets are reordered.
    Crap is dropped. What lacks is completed by 'X' characters.
    """
    
    l = filter(lambda x: IPv6ExtHdrFragment in x, pktlist) # remove non fragments
    if not l:
        return []

    id = l[0][IPv6ExtHdrFragment].id 

    llen = len(l)
    l = filter(lambda x: x[IPv6ExtHdrFragment].id == id, l)
    if len(l) != llen:
        warning("defragment6: some fragmented packets have been removed from list")
    llen = len(l)

    # reorder fragments 
    i = 0 
    res = []
    while l:
        min_pos = 0
        min_offset  = l[0][IPv6ExtHdrFragment].offset
        for p in l:
            cur_offset = p[IPv6ExtHdrFragment].offset
            if cur_offset < min_offset:
                min_pos = 0
                min_offset  = cur_offset
        res.append(l[min_pos])
        del(l[min_pos])

    # regenerate the fragmentable part
    fragmentable = ""
    for p in res:
        q=p[IPv6ExtHdrFragment]
        offset = 8*q.offset
        if offset != len(fragmentable):
            warning("Expected an offset of %d. Found %d. Padding with XXXX" % (len(fragmentable), offset))
        fragmentable += "X"*(offset - len(fragmentable))
        fragmentable += str(q.payload)

    # Regenerate the unfragmentable part.
    q = res[0]
    nh = q[IPv6ExtHdrFragment].nh
    q[IPv6ExtHdrFragment].underlayer.nh = nh
    q[IPv6ExtHdrFragment].underlayer.payload = None
    q /= Raw(load=fragmentable)
    
    return IPv6(str(q))
def defragment6 ( pktlist ) : l = filter ( lambda x : IPv6ExtHdrFragment in x , pktlist ) # remove non fragments if not l : return [ ] id = l [ 0 ] [ IPv6ExtHdrFragment ] . id llen = len ( l ) l = filter ( lambda x : x [ IPv6ExtHdrFragment ] . id == id , l ) if len ( l ) != llen : warning ( "defragment6: some fragmented packets have been removed from list" ) llen = len ( l ) # reorder fragments  i = 0 res = [ ] while l : min_pos = 0 min_offset = l [ 0 ] [ IPv6ExtHdrFragment ] . offset for p in l : cur_offset = p [ IPv6ExtHdrFragment ] . offset if cur_offset < min_offset : min_pos = 0 min_offset = cur_offset res . append ( l [ min_pos ] ) del ( l [ min_pos ] ) # regenerate the fragmentable part fragmentable = "" for p in res : q = p [ IPv6ExtHdrFragment ] offset = 8 * q . offset if offset != len ( fragmentable ) : warning ( "Expected an offset of %d. Found %d. Padding with XXXX" % ( len ( fragmentable ) , offset ) ) fragmentable += "X" * ( offset - len ( fragmentable ) ) fragmentable += str ( q . payload ) # Regenerate the unfragmentable part. q = res [ 0 ] nh = q [ IPv6ExtHdrFragment ] . nh q [ IPv6ExtHdrFragment ] . underlayer . nh = nh q [ IPv6ExtHdrFragment ] . underlayer . payload = None q /= Raw ( load = fragmentable ) return IPv6 ( str ( q ) )