Esempio n. 1
0
def testPCapPacketHeaderInit():
    header = pcap.PCapPacketHeader()
    assert header._format == 'IIII'
    assert header._size == 16
    assert header.incl_len == 0
    assert header.orig_len == 0
    assert header._data == str(header)
    assert header._swap == '@'

    ts, usec = dmc.getTimestampUTC()
    header.ts_sec, header.ts_usec = ts, usec

    float_ts = float(ts) + (float(usec) / 1e6)
    assert header.ts == float_ts
    assert header.timestamp == datetime.datetime.utcfromtimestamp(float_ts)
Esempio n. 2
0
def testPCapPacketHeaderInit():
    header = pcap.PCapPacketHeader()
    assert header._format == "IIII"
    assert header._size == 16
    assert header.incl_len == 0
    assert header.orig_len == 0
    assert header._data == header.pack()
    assert header._swap == "@"

    ts, usec = dmc.get_timestamp_utc()
    header.ts_sec, header.ts_usec = ts, usec

    float_ts = float(ts) + (float(usec) / 1e6)
    assert header.ts == float_ts
    assert header.timestamp == datetime.datetime.utcfromtimestamp(float_ts)
Esempio n. 3
0
def testSegmentSeconds(log_info):
    try:
        header = pcap.PCapPacketHeader(orig_len=1)
        with pcap.open(TmpFilename, 'w') as output:
            for p in range(10):
                header.ts_sec = p
                output.write(str(p), header)

        pcap.segment(TmpFilename, 'foo.pcap', nseconds=2, dryrun=True)
        expected = 'Would write 58 bytes, 2 packets, 2 seconds to foo.pcap.'

        assert len(log_info.call_args_list) == 5
        for call in log_info.call_args_list:
            assert call[0][0] == expected

    finally:
        os.unlink(TmpFilename)
Esempio n. 4
0
def testPCapPacketHeader():
    header = pcap.PCapPacketHeader()
    assert time.time() - header.ts <= 1
    assert header.incl_len == 0
    assert header.orig_len == 0
    assert str(header) == header._data