Files
dolphin/Source/Core/Common/PcapFile.h
T

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

52 lines
1.3 KiB
C++
Raw Normal View History

2014-04-21 02:43:45 +02:00
// Copyright 2014 Dolphin Emulator Project
// SPDX-License-Identifier: GPL-2.0-or-later
2014-04-21 02:43:45 +02:00
// PCAP is a standard file format for network capture files. This also extends
// to any capture of packetized intercommunication data. This file provides a
// class called PCAP which is a very light wrapper around the file format,
// allowing only creating a new PCAP capture file and appending packets to it.
//
// Example use:
// PCAP pcap(new IOFile("test.pcap", "wb"));
// pcap.AddPacket(pkt); // pkt is automatically casted to u8*
#pragma once
#include <cstddef>
#include <memory>
#include "Common/CommonTypes.h"
2020-09-15 03:29:41 -07:00
#include "Common/IOFile.h"
2014-04-21 02:43:45 +02:00
namespace Common
{
2017-08-04 23:57:12 +02:00
class PCAP final
2014-04-21 02:43:45 +02:00
{
public:
2017-08-29 22:14:01 +01:00
enum class LinkType : u32
{
Ethernet = 1, // IEEE 802.3 Ethernet
User = 147, // Reserved for internal use
};
2014-04-21 02:43:45 +02:00
// Takes ownership of the file object. Assumes the file object is already
// opened in write mode.
2017-08-29 22:14:01 +01:00
explicit PCAP(File::IOFile* fp, LinkType link_type = LinkType::User) : m_fp(fp)
{
AddHeader(static_cast<u32>(link_type));
}
2014-04-21 02:43:45 +02:00
template <typename T>
void AddPacket(const T& obj)
{
AddPacket(reinterpret_cast<const u8*>(&obj), sizeof(obj));
}
void AddPacket(const u8* bytes, size_t size);
private:
2017-08-29 22:14:01 +01:00
void AddHeader(u32 link_type);
2014-04-21 02:43:45 +02:00
std::unique_ptr<File::IOFile> m_fp;
};
} // namespace Common