Skip to content

Commit

Permalink
add param slice
Browse files Browse the repository at this point in the history
  • Loading branch information
robbie.tu committed Dec 2, 2021
1 parent bd2b116 commit 1710bbb
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 3 deletions.
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ endif ()
# set PKTMINERG_MAJOR_VERSION, PKTMINERG_MINOR_VERSION, etc.
set(PKTMINERG_MAJOR_VERSION "0")
set(PKTMINERG_MINOR_VERSION "5")
set(PKTMINERG_PATCH_VERSION "8")
set(PKTMINERG_PATCH_VERSION "9")
set(PKTMINERG_VERSION_STRING "${PKTMINERG_MAJOR_VERSION}.${PKTMINERG_MINOR_VERSION}.${PKTMINERG_PATCH_VERSION}")

if(WIN32)
Expand Down
12 changes: 10 additions & 2 deletions src/pcaphandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,14 @@ void PcapHandler::closeExports() {

return;
}

uint32_t PcapHandler::getPacketLen (uint32_t length) {
if (_sliceLen == 0) {
return length;
}
else{
return (_sliceLen < length)? _sliceLen : length;
}
};
void PcapHandler::packetHandler(const struct pcap_pkthdr* header, const uint8_t* pkt_data) {
ether_header* eth;
iphdr* ip;
Expand All @@ -156,6 +163,7 @@ void PcapHandler::packetHandler(const struct pcap_pkthdr* header, const uint8_t*
uint16_t eth_type;
uint16_t sport = 0;
uint16_t dport = 0;
_sliceLen = 0;
int direct;
int cap_len = header->len;

Expand Down Expand Up @@ -206,7 +214,7 @@ void PcapHandler::packetHandler(const struct pcap_pkthdr* header, const uint8_t*
default:
break;
}

((struct pcap_pkthdr*)header)->caplen = getPacketLen(header->caplen);
std::for_each(_exports.begin(), _exports.end(),
[header, pkt_data, this, direct](std::shared_ptr<PcapExportBase> pcapExport) {
int ret = pcapExport->exportPacket(header, pkt_data, direct);
Expand Down
3 changes: 3 additions & 0 deletions src/pcaphandler.h
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ class PcapHandler {
std::string _dumpDir;
std::int16_t _dumpInterval;
std::time_t _timeStamp;
uint32_t _sliceLen;

int _need_update_status;

Expand All @@ -98,6 +99,7 @@ class PcapHandler {
protected:
int openPcapDumper(pcap_t *pcap_handle);
void closePcapDumper();
uint32_t getPacketLen (uint32_t length);

int checkPktDirection(const in_addr *sip, const in_addr *dip, const uint16_t sport, const uint16_t dport);
public:
Expand All @@ -111,6 +113,7 @@ class PcapHandler {
bool dumpfile=false) = 0;
void closePcap();
void setDirIPPorts(std::string str) {_addr.init(str);};
void setSliceLength(uint32_t len) { _sliceLen = len; };
bool handlePacket();
void closeExports();
};
Expand Down
5 changes: 5 additions & 0 deletions src/pktminerg.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,8 @@ int main(int argc, char* argv[]) {

("dump", boost::program_options::value<std::string>()->default_value("./")->value_name("DUMP"),
"specify pcap dump file dump dir")
("slice", boost::program_options::value<int>()->default_value(0)->value_name("SLICE"),
"specify the length of the received packets that will be transferred or dumped.")
("interval", boost::program_options::value<int>()->default_value(-1)->value_name("INTERVAL"),
"specify the interval for dump file creation")
("mbps", boost::program_options::value<double>()->default_value(0)->value_name("mbps"),
Expand Down Expand Up @@ -349,6 +351,9 @@ int main(int argc, char* argv[]) {
return err;
}
}
if (vm.count("slice")) {
handler->setSliceLength(vm["slice"].as<int>());
}
handler->addExport(exportPtr);
handlers.push_back(handler);
}
Expand Down

0 comments on commit 1710bbb

Please sign in to comment.