Skip to content

Commit

Permalink
Remove unused code
Browse files Browse the repository at this point in the history
  • Loading branch information
uweseimet committed Sep 7, 2023
1 parent 11d39bc commit 36cdde9
Show file tree
Hide file tree
Showing 4 changed files with 2 additions and 54 deletions.
48 changes: 0 additions & 48 deletions cpp/devices/ctapdriver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -73,14 +73,6 @@ CTapDriver::~CTapDriver()
// Release TAP defice
close(m_hTAP);
}

if (m_pcap_dumper != nullptr) {
pcap_dump_close(m_pcap_dumper);
}

if (m_pcap != nullptr) {
pcap_close(m_pcap);
}
}

static bool ip_link(int fd, const char* ifname, bool up) {
Expand Down Expand Up @@ -361,22 +353,6 @@ bool CTapDriver::Init(const unordered_map<string, string>& const_params)
#endif
}

void CTapDriver::OpenDump(const string& path) {
if (m_pcap == nullptr) {
m_pcap = pcap_open_dead(DLT_EN10MB, 65535);
}
if (m_pcap_dumper != nullptr) {
pcap_dump_close(m_pcap_dumper);
}
m_pcap_dumper = pcap_dump_open(m_pcap, path.c_str());
if (m_pcap_dumper == nullptr) {
spdlog::error("Can't open pcap file: " + string(pcap_geterr(m_pcap)));
throw io_exception("Can't open pcap file");
}

spdlog::trace("Opened " + path + " for dumping");
}

bool CTapDriver::Enable() const
{
const int fd = socket(PF_INET, SOCK_DGRAM, 0);
Expand Down Expand Up @@ -481,18 +457,6 @@ int CTapDriver::Receive(uint8_t *buf)
dwReceived += 4;
}

if (m_pcap_dumper != nullptr) {
pcap_pkthdr h = {
.ts = {},
.caplen = dwReceived,
.len = dwReceived
};
gettimeofday(&h.ts, nullptr);
pcap_dump((u_char*)m_pcap_dumper, &h, buf);
spdlog::trace("Dumped " + to_string(dwReceived) + " byte packet (first byte: " +
to_string(buf[0]) + ", last byte: " + to_string(buf[dwReceived-1]) + ")");
}

// Return the number of bytes
return dwReceived;
}
Expand All @@ -501,18 +465,6 @@ int CTapDriver::Send(const uint8_t *buf, int len)
{
assert(m_hTAP != -1);

if (m_pcap_dumper != nullptr) {
pcap_pkthdr h = {
.ts = {},
.caplen = (bpf_u_int32)len,
.len = (bpf_u_int32)len,
};
gettimeofday(&h.ts, nullptr);
pcap_dump((u_char*)m_pcap_dumper, &h, buf);
spdlog::trace("Dumped " + to_string(h.len) + " byte packet (first byte: " + to_string(buf[0]) +
", last byte: " + to_string(buf[h.len-1]) + ")");
}

// Start sending
return static_cast<int>(write(m_hTAP, buf, len));
}
6 changes: 0 additions & 6 deletions cpp/devices/ctapdriver.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@

#pragma once

#include <pcap/pcap.h>
#include <net/ethernet.h>
#include <unordered_map>
#include <vector>
#include <string>
Expand All @@ -33,7 +31,6 @@ class CTapDriver
CTapDriver& operator=(const CTapDriver&) = default;

bool Init(const unordered_map<string, string>&);
void OpenDump(const string& path); // Capture packets
void GetMacAddr(uint8_t *mac) const;
int Receive(uint8_t *buf);
int Send(const uint8_t *buf, int len);
Expand All @@ -49,9 +46,6 @@ class CTapDriver

int m_hTAP = -1; // File handle

pcap_t *m_pcap = nullptr;
pcap_dumper_t *m_pcap_dumper = nullptr;

// Prioritized comma-separated list of interfaces to create the bridge for
vector<string> interfaces;

Expand Down
1 change: 1 addition & 0 deletions cpp/devices/scsi_daynaport.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
#include "interfaces/byte_writer.h"
#include "primary_device.h"
#include "ctapdriver.h"
#include <net/ethernet.h>
#include <string>
#include <span>
#include <unordered_map>
Expand Down
1 change: 1 addition & 0 deletions cpp/test/ctapdriver_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
//---------------------------------------------------------------------------

#include "mocks.h"
#include <net/ethernet.h>
#include "devices/ctapdriver.h"

TEST(CTapDriverTest, Crc32)
Expand Down

0 comments on commit 36cdde9

Please sign in to comment.