1
0
Fork 0
mirror of https://github.com/pavel-odintsov/fastnetmon synced 2024-06-09 05:16:17 +02:00
fastnetmon-rewritten/src/example_plugin/example_collector.cpp

64 lines
1.8 KiB
C++
Raw Normal View History

#include "../all_logcpp_libraries.hpp"
2015-01-26 10:10:35 +01:00
// For config map operations
#include <map>
#include <string>
2015-01-26 10:10:35 +01:00
#include "../iana_ip_protocols.hpp"
2015-01-26 10:10:35 +01:00
#include "example_collector.hpp"
2015-01-26 10:10:35 +01:00
2017-05-08 16:21:52 +02:00
// Get log4cpp logger from main program
2015-01-26 10:10:35 +01:00
extern log4cpp::Category& logger;
// Global configuration map
extern std::map<std::string, std::string> configuration_map;
2015-01-26 10:10:35 +01:00
// This variable name should be uniq for every plugin!
process_packet_pointer example_process_func_ptr = NULL;
void start_example_collection(process_packet_pointer func_ptr) {
logger << log4cpp::Priority::INFO << "Example plugin started";
2015-01-26 10:10:35 +01:00
example_process_func_ptr = func_ptr;
std::string example_plugin_config_param = "";
if (configuration_map.count("some_plugin_param_from_global_config") != 0) {
example_plugin_config_param = configuration_map["some_plugin_param_from_global_config"];
}
2015-01-26 10:10:35 +01:00
// We should fill this structure for passing to FastNetMon
2022-02-11 13:38:08 +01:00
simple_packet_t current_packet;
2015-01-26 10:10:35 +01:00
current_packet.src_ip = 0;
current_packet.dst_ip = 0;
2022-04-20 22:45:43 +02:00
current_packet.ts.tv_sec = 0;
2015-01-26 10:10:35 +01:00
current_packet.ts.tv_usec = 0;
2022-04-20 22:45:43 +02:00
current_packet.flags = 0;
2015-01-26 10:10:35 +01:00
// There we store packet length or total length of aggregated stream
current_packet.length = 128;
2015-01-26 10:10:35 +01:00
// Number of received packets, it's not equal to 1 only for aggregated data like netflow
current_packet.number_of_packets = 1;
// If your data sampled
current_packet.sample_ratio = 1;
/* ICMP */
current_packet.protocol = IpProtocolNumberICMP;
2015-01-26 10:10:35 +01:00
/* TCP */
current_packet.protocol = IpProtocolNumberTCP;
2022-04-20 22:45:43 +02:00
current_packet.source_port = 0;
2015-01-26 10:10:35 +01:00
current_packet.destination_port = 0;
/* UDP */
current_packet.protocol = IpProtocolNumberUDP;
2022-04-20 22:45:43 +02:00
current_packet.source_port = 0;
2015-01-26 10:10:35 +01:00
current_packet.destination_port = 0;
example_process_func_ptr(current_packet);
}