import "NetSnifferLog/NetSnifferLogToPcap.jnc"

//..............................................................................

class EthernetTapLogToPcap: NetSnifferLogToPcap {
public:
	construct(log.Log* log) {
		basetype.construct(log);
	}

	override size_t exportRecord(
		log.Record const* record,
		io.MappedFile* pcapFile,
		uint64_t pcapOffset
	);
}

// . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

size_t EthernetTapLogToPcap.exportRecord(
	log.Record const* record,
	io.MappedFile* pcapFile,
	uint64_t pcapOffset
) {
	void const* p;
	size_t size;

	switch (record.m_code) {
	case EthernetTapLogRecordCode.Packet_ch1:
	case EthernetTapLogRecordCode.Packet_ch2:
		uint32_t const* idx = (uint32_t const*)(record + 1);
		PacketHdr const* hdr = (PacketHdr const*)(idx + 1);
		p = hdr + 1;
		size = hdr.m_size;
		break;

	default:
		return 0;
	}

	return log.writePcapPacket(pcapFile, pcapOffset, record.m_timestamp, p, size);
}

//..............................................................................

