Timestamp con millisecondi in uscita da Riddle e in entrata a Cigarette.
This commit is contained in:
parent
a198892cd4
commit
207ecbefee
4 changed files with 42 additions and 23 deletions
|
@ -14,6 +14,8 @@
|
|||
#include <cstdlib>
|
||||
#include <string>
|
||||
#include <boost/program_options.hpp>
|
||||
#include <boost/algorithm/string/split.hpp>
|
||||
#include <boost/algorithm/string/classification.hpp>
|
||||
#include "libCigarette.h"
|
||||
#include "libExtract.h"
|
||||
|
||||
|
@ -39,14 +41,18 @@ int main(int argc, char **argv) {
|
|||
|
||||
while(1)
|
||||
{
|
||||
string line;
|
||||
getline(cin,line);
|
||||
string packet;
|
||||
getline(cin,packet);
|
||||
if(cin.eof()) break;
|
||||
|
||||
std::vector< std::string > line;
|
||||
boost::algorithm::split(line, packet, boost::algorithm::is_any_of("!"));
|
||||
|
||||
header_ethernet etherhead;
|
||||
|
||||
etherhead = parseEthernet(line);
|
||||
std::cout<<"---- Packet ("<<std::dec<<line.length()<<" byte)"<<std::endl;
|
||||
etherhead = parseEthernet(line[2]);
|
||||
std::cout<<"---- ["<<line[0]<<" "<<line[1];
|
||||
std::cout<<"] Packet ("<<std::dec<<line[2].length()<<" byte)"<<std::endl;
|
||||
std::cout<<"Ether | "<<print_mac_address(etherhead.mac_src);
|
||||
std::cout<<" --> "<<print_mac_address(etherhead.mac_dst)<<std::endl;
|
||||
std::cout<<"Ether | Type: 0x"<<std::hex<<etherhead.ether_type<<" ";
|
||||
|
@ -56,7 +62,7 @@ int main(int argc, char **argv) {
|
|||
{
|
||||
case ETHER_TYPE_ARP:
|
||||
header_arp arp;
|
||||
arp = parseArp(line);
|
||||
arp = parseArp(line[2]);
|
||||
if(arp.opcode == 1)
|
||||
{
|
||||
// Request
|
||||
|
|
18
Riddle.cpp
18
Riddle.cpp
|
@ -61,29 +61,29 @@ int main(int argc, char **argv) {
|
|||
if(pcap_handle == NULL){
|
||||
pcap_fatal("pcap_open_live", error_buffer);
|
||||
}
|
||||
|
||||
|
||||
cerr<<"Sniffing on device "<<pcap_device<<endl;
|
||||
|
||||
|
||||
if(vm.count("filter"))
|
||||
{
|
||||
string filter = vm["filter"].as<string>();
|
||||
struct bpf_program fp;
|
||||
bpf_u_int32 net;
|
||||
|
||||
|
||||
cerr<<"Filtering with '"<<filter<<"'"<<endl;
|
||||
|
||||
if (pcap_compile(pcap_handle, &fp, filter.c_str(), 0, net) == -1)
|
||||
|
||||
if (pcap_compile(pcap_handle, &fp, filter.c_str(), 0, net) == -1)
|
||||
{
|
||||
cerr<< "Couldn't parse filter '"<<filter<<"': "<<pcap_geterr(pcap_handle)<<endl;
|
||||
return(2);
|
||||
}
|
||||
|
||||
|
||||
if (pcap_setfilter(pcap_handle, &fp) == -1) {
|
||||
cerr<< "Couldn't install filter '"<<filter<<"': "<<pcap_geterr(pcap_handle)<<endl;
|
||||
return(2);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
int maxpacket = numeric_limits<int>::max();
|
||||
|
||||
if(vm.count("limit"))
|
||||
|
@ -91,7 +91,7 @@ int main(int argc, char **argv) {
|
|||
maxpacket=vm["limit"].as<int>();
|
||||
}
|
||||
|
||||
void (*dumper)(const unsigned char*,int);
|
||||
void (*dumper)(const unsigned char*,struct pcap_pkthdr);
|
||||
if(vm.count("dump")) dumper=hexDump; else dumper=rawDump;
|
||||
|
||||
const u_char *packet;
|
||||
|
@ -100,7 +100,7 @@ int main(int argc, char **argv) {
|
|||
for(;maxpacket > 0;)
|
||||
{
|
||||
packet = pcap_next(pcap_handle, &header);
|
||||
dumper(packet, header.len);
|
||||
dumper(packet, header);
|
||||
if(maxpacket!=numeric_limits<int>::max()) maxpacket--;
|
||||
}
|
||||
|
||||
|
|
|
@ -40,22 +40,26 @@ static void memPrint(const unsigned char *start, char len, int index)
|
|||
printf("\n");
|
||||
}
|
||||
|
||||
void hexDump(const unsigned char *start, int len)
|
||||
void hexDump(const unsigned char *start, struct pcap_pkthdr header)
|
||||
{
|
||||
std::cout<<std::endl<<"Received "<<len<<" byte:"<<std::endl;
|
||||
std::cout<<std::endl<<"[TS: "<<header.ts.tv_sec;
|
||||
std::cout<<" uS: "<<header.ts.tv_usec;
|
||||
std::cout<<"] Received "<<header.len<<" byte:"<<std::endl;
|
||||
int index=0;
|
||||
while(len>16)
|
||||
while(header.len>16)
|
||||
{
|
||||
memPrint(start,16,index);
|
||||
len-=16;
|
||||
header.len-=16;
|
||||
start+=16;
|
||||
index+=16;
|
||||
}
|
||||
if(len>0) memPrint(start,len,index);
|
||||
if(header.len>0) memPrint(start,header.len,index);
|
||||
}
|
||||
|
||||
void rawDump(const unsigned char *start, int len)
|
||||
void rawDump(const unsigned char *start, struct pcap_pkthdr header)
|
||||
{
|
||||
for(int i=0;i<len;i++) printf("%02x",start[i]);
|
||||
printf("%d!",header.ts.tv_sec);
|
||||
printf("%d!",header.ts.tv_usec);
|
||||
for(int i=0;i<header.len;i++) printf("%02x",start[i]);
|
||||
printf("\n");
|
||||
}
|
||||
|
|
13
libRiddle.h
13
libRiddle.h
|
@ -12,8 +12,17 @@
|
|||
#ifndef LIBRIDDLE_H
|
||||
#define LIBRIDDLE_H
|
||||
|
||||
#include <pcap.h>
|
||||
|
||||
/* struct pcap_pkthdr {
|
||||
* struct timeval ts; time stamp
|
||||
* bpf_u_int32 caplen; length of portion present
|
||||
* bpf_u_int32; lebgth this packet (off wire)
|
||||
} *
|
||||
*/
|
||||
|
||||
void pcap_fatal(const char *error_in, const char *error_buffer);
|
||||
void hexDump(const unsigned char *start, int len);
|
||||
void rawDump(const unsigned char *start, int len);
|
||||
void hexDump(const unsigned char *start, struct pcap_pkthdr header);
|
||||
void rawDump(const unsigned char *start, struct pcap_pkthdr header);
|
||||
|
||||
#endif //LIBRIDDLE_H
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue