1#!/usr/local/bin/python2.7
2# send a ping6 packet with routing header type 0
3# the address pointer is at the final destination
4# hide the routing header behind a fragment header to avoid header scan
5# we expect an echo reply, as there are no more hops
6
7import os
8from addr import *
9from scapy.all import *
10
11pid=os.getpid()
12payload="ABCDEFGHIJKLMNOP"
13packet=IPv6(src=SRC_OUT6, dst=DST_IN6)/\
14    IPv6ExtHdrFragment(id=pid)/\
15    IPv6ExtHdrRouting(addresses=[SRT_IN6, SRT_OUT6], segleft=0)/\
16    ICMPv6EchoRequest(id=pid, data=payload)
17eth=Ether(src=SRC_MAC, dst=DST_MAC)/packet
18
19if os.fork() == 0:
20	time.sleep(1)
21	sendp(eth, iface=SRC_IF)
22	os._exit(0)
23
24ans=sniff(iface=SRC_IF, timeout=3, filter=
25    "ip6 and dst "+SRC_OUT6+" and icmp6")
26for a in ans:
27	if a and a.type == scapy.layers.dot11.ETHER_TYPES.IPv6 and \
28	    ipv6nh[a.payload.nh] == 'ICMPv6' and \
29	    icmp6types[a.payload.payload.type] == 'Echo Reply':
30		reply=a.payload.payload
31		id=reply.id
32		print "id=%#x" % (id)
33		if id != pid:
34			print "WRONG ECHO REPLY ID"
35			exit(2)
36		data=reply.data
37		print "payload=%s" % (data)
38		if data != payload:
39			print "WRONG PAYLOAD"
40			exit(2)
41		exit(0)
42print "NO ICMP6 ECHO REPLY"
43exit(1)
44