Update 24/11/2011 12:14
This commit is contained in:
parent
625d85680d
commit
c20b051093
4 changed files with 16 additions and 49 deletions
|
@ -23,10 +23,7 @@ int main(int argc, char **argv) {
|
|||
options_description desc("Cigarette - Network Packet Parser");
|
||||
desc.add_options()
|
||||
("help", "prints this")
|
||||
("dump", "enable dump mode")
|
||||
("ipv4", "show only IPv4 Packets")
|
||||
("ipv6", "show only IPv6 Packets")
|
||||
("arp", "show only ARP Packets")
|
||||
("dump", "enable dump mode") // TODO
|
||||
;
|
||||
|
||||
variables_map vm;
|
||||
|
@ -39,29 +36,28 @@ int main(int argc, char **argv) {
|
|||
return 1;
|
||||
}
|
||||
|
||||
header_ethernet etherhead;
|
||||
|
||||
void (*dumper)(std::string);
|
||||
if(vm.count("dump")) dumper=decDump; else dumper=rawDump;
|
||||
|
||||
while(1)
|
||||
{
|
||||
string line;
|
||||
getline(cin,line);
|
||||
if(cin.eof()) break;
|
||||
|
||||
header_ethernet etherhead;
|
||||
|
||||
etherhead = parseEthernet(line);
|
||||
std::cout<<"---- Packet ("<<std::dec<<line.length()<<" byte)"<<std::endl;
|
||||
std::cout<<"EtherAddr | "<<etherhead.mac_src<<" --> "<<etherhead.mac_dst<<std::endl;
|
||||
std::cout<<"EtherType | 0x"<<std::hex<<etherhead.ether_type<<" ("<<ether_type_decode(etherhead.ether_type)<<")"<<std::endl;
|
||||
|
||||
int flag = 0;
|
||||
|
||||
// TODO Da ottimizzare, magari sotto un unico parametro.
|
||||
if(vm.count("arp") || vm.count("ipv4") || vm.count("ipv6"))
|
||||
if(etherhead.ether_type == ETHER_TYPE_ARP)
|
||||
{
|
||||
if(vm.count("arp") && etherhead.ether_type == ETHER_TYPE_ARP) flag = 1;
|
||||
if(vm.count("ipv4") && etherhead.ether_type == ETHER_TYPE_IPV4) flag = 1;
|
||||
if(vm.count("ipv6") && etherhead.ether_type == ETHER_TYPE_IPV6) flag = 1;
|
||||
} else flag = 1;
|
||||
header_arp arphead;
|
||||
arphead = parseArp(line);
|
||||
std::cout<<"ARP | "<<arphead.mac_src<<" ("<<arphead.ip_src<<") --> "<<arphead.mac_dst<<" ("<<arphead.ip_dst<<")"<<std::endl;
|
||||
}
|
||||
|
||||
std::cout<<std::endl;
|
||||
|
||||
if(flag) dumper(line);
|
||||
}
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
|
|
|
@ -74,12 +74,12 @@ int main(int argc, char **argv) {
|
|||
|
||||
if (pcap_compile(pcap_handle, &fp, filter.c_str(), 0, net) == -1)
|
||||
{
|
||||
cerr<< "Couldn't parse filter "<<filter<<": "<<pcap_geterr(pcap_handle)<<endl;
|
||||
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;
|
||||
cerr<< "Couldn't install filter '"<<filter<<"': "<<pcap_geterr(pcap_handle)<<endl;
|
||||
return(2);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -150,31 +150,4 @@ std::string ether_type_decode(int start)
|
|||
}
|
||||
}
|
||||
else return "Ethernet IEEE 802.3";
|
||||
}
|
||||
|
||||
void decDump(std::string line)
|
||||
{
|
||||
header_ethernet etherhead;
|
||||
header_arp arphead;
|
||||
|
||||
etherhead = parseEthernet(line);
|
||||
std::cout<<"---- Packet ("<<std::dec<<line.length()<<" byte)"<<std::endl;
|
||||
std::cout<<"EtherAddr | "<<etherhead.mac_src<<" --> "<<etherhead.mac_dst<<std::endl;
|
||||
std::cout<<"EtherType | 0x"<<std::hex<<etherhead.ether_type<<" ("<<ether_type_decode(etherhead.ether_type)<<")"<<std::endl;
|
||||
|
||||
if(etherhead.ether_type == ETHER_TYPE_ARP)
|
||||
{
|
||||
arphead = parseArp(line);
|
||||
std::cout<<"ARP | "<<arphead.mac_src<<" ("<<arphead.ip_src<<") --> "<<arphead.mac_dst<<" ("<<arphead.ip_dst<<")"<<std::endl;
|
||||
}
|
||||
|
||||
std::cout<<std::endl;
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
void rawDump(std::string line)
|
||||
{
|
||||
std::cout<<line<<std::endl;
|
||||
return;
|
||||
}
|
|
@ -42,7 +42,5 @@ struct header_arp
|
|||
header_ethernet parseEthernet(std::string start);
|
||||
header_arp parseArp(std::string start);
|
||||
std::string ether_type_decode(int start);
|
||||
void decDump(std::string);
|
||||
void rawDump(std::string);
|
||||
|
||||
#endif //LIBCIGARETTE_H
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue