Debian Codegraph @

Source/Core/Common/PcapFile.h

raw symbols SCIP
1 // Copyright 2014 Dolphin Emulator Project
2 // SPDX-License-Identifier: GPL-2.0-or-later
3
4 // PCAP is a standard file format for network capture files. This also extends
5 // to any capture of packetized intercommunication data. This file provides a
6 // class called PCAP which is a very light wrapper around the file format,
7 // allowing only creating a new PCAP capture file and appending packets to it.
8 //
9 // Example use:
10 // PCAP pcap(new IOFile("test.pcap", "wb"));
11 // pcap.AddPacket(pkt); // pkt is automatically casted to u8*
12
13 #pragma once
14
15 #include <cstddef>
16 #include <memory>
17
18 #include "Common/CommonTypes.h"
19 #include "Common/IOFile.h"
20
21 namespace Common
22 {
23 class PCAP final
24 {
25 public:
26 enum class LinkType : u32
27 {
28 Ethernet = 1, // IEEE 802.3 Ethernet
29 User = 147, // Reserved for internal use
30 };
31
32 // Takes ownership of the file object. Assumes the file object is already
33 // opened in write mode.
34 explicit PCAP(File::IOFile* fp, LinkType link_type = LinkType::User) : m_fp(fp)
35 {
36 AddHeader(static_cast<u32>(link_type));
37 }
38 template <typename T>
39 void AddPacket(const T& obj)
40 {
41 AddPacket(reinterpret_cast<const u8*>(&obj), sizeof(obj));
42 }
43
44 void AddPacket(const u8* bytes, size_t size);
45
46 private:
47 void AddHeader(u32 link_type);
48
49 std::unique_ptr<File::IOFile> m_fp;
50 };
51 } // namespace Common