def _decodePacket(self, packet): # Look at the first byte to figure out whether it's IPv4 or IPv6. version = (ord(packet[0]) & 0xf0) >> 4 if version == 4: return IPv4Packet(packet) elif version == 6: return IPv6Packet(packet) else: return packet
def test_Recv(self): srcport = 23456 payload = 'who\'s there?' packet = IPv6Packet(proto = IPv6Packet.PROTO_UDP, src = socket.inet_pton(self._codec.af, self._codec.addr.remote), dst = socket.inet_pton(self._codec.af, TestMulticast6.MULTICAST_GROUP), payload = UDPPacket(src = srcport, dst = self._codec.UDPPort, payload = payload)) self._codec.sendPacket(packet.encode()) self._codec.expectUDP(payload) self.assertTrue(self._codec.runUDP())
def _sendNeighborAdvertisement(self, packet): reply = EthernetFrame( dst = packet.payload.payload.payload.src_lladdr, src = TapPacketCodec.ETHER_ADDR_ANY, type = EthernetFrame.TYPE_IPV6, payload = IPv6Packet( src = socket.inet_pton(self.addr.af, self.addr.remote), dst = packet.payload.src, proto = IPv6Packet.PROTO_ICMPV6, payload = ICMPV6Packet( type = ICMPV6Packet.TYPE_NEIGHBOR_ADVERTISMENT, payload = ICMPV6NeighborAdvertisement( solicited = 1, override = 1, target = socket.inet_pton(self.addr.af, self.addr.remote), target_lladdr = TapPacketCodec.ETHER_ADDR_REMOTE)))) self._harness.char_dev.send(reply.encode())