1
0
mirror of https://github.com/esp8266/Arduino.git synced 2025-07-26 07:02:15 +03:00

Migrate from astyle to clang-format (#8464)

This commit is contained in:
Maxim Prokhorov
2022-02-20 19:23:33 +03:00
committed by Max Prokhorov
parent 46190b61f1
commit 19b7a29720
241 changed files with 15925 additions and 16197 deletions

View File

@ -23,7 +23,6 @@
#include <lwip/init.h>
#include "Schedule.h"
namespace NetCapture
{
@ -69,24 +68,26 @@ void Netdump::reset()
void Netdump::printDump(Print& out, Packet::PacketDetail ndd, const Filter nf)
{
out.printf_P(PSTR("netDump starting\r\n"));
setCallback([&out, ndd, this](const Packet & ndp)
{
printDumpProcess(out, ndd, ndp);
}, nf);
setCallback(
[&out, ndd, this](const Packet& ndp)
{
printDumpProcess(out, ndd, ndp);
},
nf);
}
void Netdump::fileDump(File& outfile, const Filter nf)
{
writePcapHeader(outfile);
setCallback([&outfile, this](const Packet & ndp)
{
fileDumpProcess(outfile, ndp);
}, nf);
setCallback(
[&outfile, this](const Packet& ndp)
{
fileDumpProcess(outfile, ndp);
},
nf);
}
bool Netdump::tcpDump(WiFiServer &tcpDumpServer, const Filter nf)
bool Netdump::tcpDump(WiFiServer& tcpDumpServer, const Filter nf)
{
if (!packetBuffer)
{
packetBuffer = new (std::nothrow) char[tcpBufferSize];
@ -98,10 +99,11 @@ bool Netdump::tcpDump(WiFiServer &tcpDumpServer, const Filter nf)
}
bufferIndex = 0;
schedule_function([&tcpDumpServer, this, nf]()
{
tcpDumpLoop(tcpDumpServer, nf);
});
schedule_function(
[&tcpDumpServer, this, nf]()
{
tcpDumpLoop(tcpDumpServer, nf);
});
return true;
}
@ -109,7 +111,8 @@ void Netdump::capture(int netif_idx, const char* data, size_t len, int out, int
{
if (lwipCallback.execute(netif_idx, data, len, out, success) == 0)
{
phy_capture = nullptr; // No active callback/netdump instances, will be set again by new object.
phy_capture
= nullptr; // No active callback/netdump instances, will be set again by new object.
}
}
@ -118,7 +121,7 @@ void Netdump::netdumpCapture(int netif_idx, const char* data, size_t len, int ou
if (netDumpCallback)
{
Packet np(millis(), netif_idx, data, len, out, success);
if (netDumpFilter && !netDumpFilter(np))
if (netDumpFilter && !netDumpFilter(np))
{
return;
}
@ -131,8 +134,8 @@ void Netdump::writePcapHeader(Stream& s) const
uint32_t pcapHeader[6];
pcapHeader[0] = 0xa1b2c3d4; // pcap magic number
pcapHeader[1] = 0x00040002; // pcap major/minor version
pcapHeader[2] = 0; // pcap UTC correction in seconds
pcapHeader[3] = 0; // pcap time stamp accuracy
pcapHeader[2] = 0; // pcap UTC correction in seconds
pcapHeader[3] = 0; // pcap time stamp accuracy
pcapHeader[4] = maxPcapLength; // pcap max packet length per record
pcapHeader[5] = 1; // pacp data linkt type = ethernet
s.write(reinterpret_cast<char*>(pcapHeader), 24);
@ -145,7 +148,7 @@ void Netdump::printDumpProcess(Print& out, Packet::PacketDetail ndd, const Packe
void Netdump::fileDumpProcess(File& outfile, const Packet& np) const
{
size_t incl_len = np.getPacketSize() > maxPcapLength ? maxPcapLength : np.getPacketSize();
size_t incl_len = np.getPacketSize() > maxPcapLength ? maxPcapLength : np.getPacketSize();
uint32_t pcapHeader[4];
struct timeval tv;
@ -154,7 +157,7 @@ void Netdump::fileDumpProcess(File& outfile, const Packet& np) const
pcapHeader[1] = tv.tv_usec;
pcapHeader[2] = incl_len;
pcapHeader[3] = np.getPacketSize();
outfile.write(reinterpret_cast<char*>(pcapHeader), 16); // pcap record header
outfile.write(reinterpret_cast<char*>(pcapHeader), 16); // pcap record header
outfile.write(np.rawData(), incl_len);
}
@ -168,16 +171,16 @@ void Netdump::tcpDumpProcess(const Packet& np)
}
size_t incl_len = np.getPacketSize() > maxPcapLength ? maxPcapLength : np.getPacketSize();
if (bufferIndex + 16 + incl_len < tcpBufferSize) // only add if enough space available
if (bufferIndex + 16 + incl_len < tcpBufferSize) // only add if enough space available
{
struct timeval tv;
gettimeofday(&tv, nullptr);
uint32_t* pcapHeader = reinterpret_cast<uint32_t*>(&packetBuffer[bufferIndex]);
pcapHeader[0] = tv.tv_sec; // add pcap record header
pcapHeader[1] = tv.tv_usec;
pcapHeader[2] = incl_len;
pcapHeader[3] = np.getPacketSize();
bufferIndex += 16; // pcap header size
pcapHeader[0] = tv.tv_sec; // add pcap record header
pcapHeader[1] = tv.tv_usec;
pcapHeader[2] = incl_len;
pcapHeader[3] = np.getPacketSize();
bufferIndex += 16; // pcap header size
memcpy(&packetBuffer[bufferIndex], np.rawData(), incl_len);
bufferIndex += incl_len;
}
@ -189,7 +192,7 @@ void Netdump::tcpDumpProcess(const Packet& np)
}
}
void Netdump::tcpDumpLoop(WiFiServer &tcpDumpServer, const Filter nf)
void Netdump::tcpDumpLoop(WiFiServer& tcpDumpServer, const Filter nf)
{
if (tcpDumpServer.hasClient())
{
@ -199,10 +202,12 @@ void Netdump::tcpDumpLoop(WiFiServer &tcpDumpServer, const Filter nf)
bufferIndex = 0;
writePcapHeader(tcpDumpClient);
setCallback([this](const Packet & ndp)
{
tcpDumpProcess(ndp);
}, nf);
setCallback(
[this](const Packet& ndp)
{
tcpDumpProcess(ndp);
},
nf);
}
if (!tcpDumpClient || !tcpDumpClient.connected())
{
@ -216,11 +221,12 @@ void Netdump::tcpDumpLoop(WiFiServer &tcpDumpServer, const Filter nf)
if (tcpDumpServer.status() != CLOSED)
{
schedule_function([&tcpDumpServer, this, nf]()
{
tcpDumpLoop(tcpDumpServer, nf);
});
schedule_function(
[&tcpDumpServer, this, nf]()
{
tcpDumpLoop(tcpDumpServer, nf);
});
}
}
} // namespace NetCapture
} // namespace NetCapture