(pkt, fragsize=1480)
return lst
Fragment a big IP datagram
Fragment a big IP datagram
Fragment a big IP datagram
def fragment(pkt, fragsize=1480):
    """Fragment a big IP datagram"""
    fragsize = (fragsize+7)/8*8
    lst = []
    for p in pkt:
        s = str(p[IP].payload)
        nb = (len(s)+fragsize-1)/fragsize
        for i in range(nb):            
            q = p.copy()
            del(q[IP].payload)
            del(q[IP].chksum)
            del(q[IP].len)
            if i == nb-1:
                q[IP].flags &= ~1
            else:
                q[IP].flags |= 1 
            q[IP].frag = i*fragsize/8
            r = Raw(load=s[i*fragsize:(i+1)*fragsize])
            r.overload_fields = p[IP].payload.overload_fields.copy()
            q.add_payload(r)
            lst.append(q)
    return lst
def fragment ( pkt , fragsize = 1480 ) : fragsize = ( fragsize + 7 ) / 8 * 8 lst = [ ] for p in pkt : s = str ( p [ IP ] . payload ) nb = ( len ( s ) + fragsize - 1 ) / fragsize for i in range ( nb ) : q = p . copy ( ) del ( q [ IP ] . payload ) del ( q [ IP ] . chksum ) del ( q [ IP ] . len ) if i == nb - 1 : q [ IP ] . flags &= ~ 1 else : q [ IP ] . flags |= 1 q [ IP ] . frag = i * fragsize / 8 r = Raw ( load = s [ i * fragsize : ( i + 1 ) * fragsize ] ) r . overload_fields = p [ IP ] . payload . overload_fields . copy ( ) q . add_payload ( r ) lst . append ( q ) return lst