def in6_chksum(nh, u, p):
 ph6 = PseudoIPv6()
 ph6.nh = nh
 rthdr = 0
 hahdr = 0
 final_dest_addr_found = 0
 while ((u != None) and (not isinstance(u, IPv6))):
  if (isinstance(u, IPv6ExtHdrRouting) and (u.segleft != 0) and (len(u.addresses) != 0) and (final_dest_addr_found == 0)):
   rthdr = u.addresses[(-1)]
   final_dest_addr_found = 1
  elif (isinstance(u, IPv6ExtHdrDestOpt) and (len(u.options) == 1) and isinstance(u.options[0], HAO)):
   hahdr = u.options[0].hoa
  u = u.underlayer
 if (u is None):
  warning('No IPv6 underlayer to compute checksum. Leaving null.')
  return 0
 if hahdr:
  ph6.src = hahdr
 else:
  ph6.src = u.src
 if rthdr:
  ph6.dst = rthdr
 else:
  ph6.dst = u.dst
 ph6.uplen = len(p)
 ph6s = str(ph6)
 return checksum((ph6s + p))

def in6_chksum ( nh , u , p ) : ph6 = PseudoIPv6 ( ) ph6 . nh = nh rthdr = 0 hahdr = 0 final_dest_addr_found = 0 while ( ( u != None ) and ( not isinstance ( u , IPv6 ) ) ) : if ( isinstance ( u , IPv6ExtHdrRouting ) and ( u . segleft != 0 ) and ( len ( u . addresses ) != 0 ) and ( final_dest_addr_found == 0 ) ) : rthdr = u . addresses [ ( - 1 ) ] final_dest_addr_found = 1 elif ( isinstance ( u , IPv6ExtHdrDestOpt ) and ( len ( u . options ) == 1 ) and isinstance ( u . options [ 0 ] , HAO ) ) : hahdr = u . options [ 0 ] . hoa u = u . underlayer if ( u is None ) : warning ( 'No IPv6 underlayer to compute checksum. Leaving null.' ) return 0 if hahdr : ph6 . src = hahdr else : ph6 . src = u . src if rthdr : ph6 . dst = rthdr else : ph6 . dst = u . dst ph6 . uplen = len ( p ) ph6s = str ( ph6 ) return checksum ( ( ph6s + p ) )
performs ipv6 upper layer checksum computation .