I define a class named sessionSeparator
then I define a callback function name packet_handler like bellow :
Code:
void SessionSeparator::packet_handler(u_char *dumpfile, const struct pcap_pkthdr *header, const u_char *pkt_data)
{
// TODO
}
I call pcap_loop in another public function but eclipse notify a bellow error
Code:
cannot convert ‘Tins::SessionSeparator::packet_handler’ from type ‘void (Tins::SessionSeparator::)(u_char*, const pcap_pkthdr*, const u_char*) {aka void (Tins::SessionSeparator::)(unsigned char*, const pcap_pkthdr*, const unsigned char*)}’ to type ‘pcap_handler {aka void (*)(unsigned char*, const pcap_pkthdr*, const unsigned char*)}’
the complete cpp file is as bellow
Code:
]#include "SessionSeparator.h"
namespace Tins {
void SessionSeparator::set_in_out_files (char * infile, char * outfile) {
infile_ = infile;
outfile_ = outfile;
}
void SessionSeparator::run(){
pcap_t *fp;
pcap_dumper_t *dumpfile;
fp = pcap_open_offline(infile_, NULL);
if ( fp == NULL)
{
fprintf(stderr,"\nUnable to find input file.\n");
return;
}
dumpfile = pcap_dump_open(fp, this->outfile_);
if(dumpfile == NULL)
{
fprintf(stderr,"\nError opening output file\n");
return;
}
pcap_loop(fp, 0, packet_handler, (u_char *)dumpfile);
}
void SessionSeparator::packet_handler(u_char *dumpfile, const struct pcap_pkthdr *header, const u_char *pkt_data)
{
// TODO
}
} /* namespace Tins */
and header file :
Code:
#include <stdlib.h>
#include <stdio.h>
#include <linux/ip.h>
#include <stdbool.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <string.h>
#include <net/ethernet.h>
#include <math.h>
#include <unistd.h>
#include <pcap.h>
#ifndef SESSIONSEPARATOR_H_
#define SESSIONSEPARATOR_H_
namespace Tins {
class SessionSeparator {
public:
void set_in_out_files (char * infile, char * outfile);
void run() ;
void packet_handler(u_char *dumpfile, const struct pcap_pkthdr *header, const u_char *pkt_data);
private:
char * infile_;
char * outfile_;
};
} /* namespace Tins */
#endif /* SESSIONSEPARATOR_H_ *
what is the correct solution to implement this code ?