Example #1
0
 def test_writeARecord(self):
     p = pcap.Pcap("_tmp.pcap", forreading=False)
     p.writeGlobalHeader()
     r = pcap.PcapRecord()
     r.setCurrentTime()
     r.packet = struct.pack("H", 0x5)
     p.writeARecord(r)
     p.close()
     p = pcap.Pcap("_tmp.pcap")
     p.readGlobalHeader()
     self.assertEqual(p.magic, 0xa1b2c3d4)
     self.assertEqual(p.network, 1)
     self.assertEqual(p.sigfigs, 0)
     self.assertEqual(p.snaplen, 65535)
     self.assertEqual(p.versionmaj, 2)
     self.assertEqual(p.versionmin, 4)
     self.assertEqual(p.zone, 0)
     self.assertEqual(p.filesize, 42)
     os.remove("_tmp.pcap")
Example #2
0
        else:
            currenttime = int(time.time())
        if args.type == "iena":
            avionics_packet.sequence = (avionics_packet.sequence + 1) % 65536
            udp_packet.srcport = 5000
        else:
            avionics_packet.sequence = (avionics_packet.sequence +
                                        1) % 0x100000000
            udp_packet.srcport = 5001

        avionics_packet.setPacketTime(currenttime)
        udp_packet.payload = avionics_packet.pack()

    ip_packet.payload = udp_packet.pack()
    ethernet_packet.payload = ip_packet.pack()
    record = pcap.PcapRecord()
    if args.ignoretime:
        record.usec = 0
        record.sec = 0
    else:
        record.setCurrentTime()
    record.packet = ethernet_packet.pack()
    mypcap.writeARecord(record)

    packets_written += 1

mypcap.close()
end_time = time.time()
print(
    "INFO: Wrote {} packets of type {} with payload of {} bytes in {} seconds".
    format(PACKETS_TO_WRITE, args.type, PAYLOAD_SIZE, end_time - start_time))