This commit is contained in:
Andrea Bontempi 2012-10-07 22:12:41 +02:00
commit b880ae0cd3
3 changed files with 18 additions and 14 deletions

View file

@ -109,11 +109,16 @@ int main ( int argc, char **argv ) {
pcap_t *pcap_handle;
if ( vm.count ( "input" ) ) {
pcap_handle = pcap_open_offline ( vm["input"].as<string>().c_str(), error_buffer );
if ( pcap_handle == NULL ) {
pcap_fatal ( "pcap_open_offline", error_buffer );
cerr << "ERROR >> pcap_open_offline: " << error_buffer << endl;
return EXIT_FAILURE;
}
cerr << ">> Reading packets from " << vm["input"].as<string>() << endl;
} else {
string pcap_device;
@ -121,17 +126,26 @@ int main ( int argc, char **argv ) {
if ( vm.count ( "iface" ) ) {
pcap_device=vm["iface"].as<string>();
} else {
// Cerca e restituisce interfaccia
char *dev=pcap_lookupdev ( error_buffer );
if ( dev!=NULL ) pcap_device = dev;
else pcap_fatal ( "pcap_lookupdev", error_buffer );
if ( dev!=NULL ) {
pcap_device = dev;
} else {
cerr << "ERROR >> pcap_lookupdev: " << error_buffer << endl;
return EXIT_FAILURE;
}
}
// Apre il device in mod promiscua
pcap_handle = pcap_open_live ( pcap_device.c_str(), 4096, 1, 0, error_buffer );
if ( pcap_handle == NULL ) {
pcap_fatal ( "pcap_open_live", error_buffer );
cerr << "ERROR >> pcap_open_live: " << error_buffer << endl;
return EXIT_FAILURE;
}
cerr << ">> Sniffing on device " << pcap_device << endl;
}

View file

@ -34,14 +34,6 @@
#include "libRiddle.h"
#include "../commons/libDump.h"
// Non mettere using namespace generali in header file.
void pcap_fatal ( const char *error_in, const char *error_buffer ) {
std::stringstream ss;
ss<<"Fatal Error in "<<error_in<<": "<<error_buffer;
throw ( std::runtime_error ( ss.str() ) );
}
static void memPrint ( const unsigned char *start, char len, int index ) {
printf ( "0x%08x | ",index );
int i;

View file

@ -38,8 +38,6 @@
} *
*/
void pcap_fatal ( const char *error_in, const char *error_buffer );
/* Funzioni per la stampa su schermo dei dati in formato esadecimale */
void hexDump ( const unsigned char *start, struct pcap_pkthdr header );
void rawDump ( const unsigned char *start, struct pcap_pkthdr header );