def split_for_transport(orig_pkt, transport_proto):
 header = orig_pkt.__class__(str(orig_pkt))
 next_hdr = header.payload
 nh = None
 if (header.version == 4):
  nh = header.proto
  header.proto = transport_proto
  header.remove_payload()
  del header.chksum
  del header.len
  return (header, nh, next_hdr)
 else:
  found_rt_hdr = False
  prev = header
  while isinstance(next_hdr, (IPv6ExtHdrHopByHop, IPv6ExtHdrRouting, IPv6ExtHdrDestOpt)):
   if isinstance(next_hdr, IPv6ExtHdrHopByHop):
    pass
   if isinstance(next_hdr, IPv6ExtHdrRouting):
    found_rt_hdr = True
   elif (isinstance(next_hdr, IPv6ExtHdrDestOpt) and found_rt_hdr):
    break
   prev = next_hdr
   next_hdr = next_hdr.payload
  nh = prev.nh
  prev.nh = transport_proto
  prev.remove_payload()
  del header.plen
  return (header, nh, next_hdr)

def split_for_transport ( orig_pkt , transport_proto ) : header = orig_pkt . __class__ ( str ( orig_pkt ) ) next_hdr = header . payload nh = None if ( header . version == 4 ) : nh = header . proto header . proto = transport_proto header . remove_payload ( ) del header . chksum del header . len return ( header , nh , next_hdr ) else : found_rt_hdr = False prev = header while isinstance ( next_hdr , ( IPv6ExtHdrHopByHop , IPv6ExtHdrRouting , IPv6ExtHdrDestOpt ) ) : if isinstance ( next_hdr , IPv6ExtHdrHopByHop ) : pass if isinstance ( next_hdr , IPv6ExtHdrRouting ) : found_rt_hdr = True elif ( isinstance ( next_hdr , IPv6ExtHdrDestOpt ) and found_rt_hdr ) : break prev = next_hdr next_hdr = next_hdr . payload nh = prev . nh prev . nh = transport_proto prev . remove_payload ( ) del header . plen return ( header , nh , next_hdr )
split an ip packet in the correct location to insert an esp or ah header .