~ubuntu-branches/ubuntu/trusty/xprobe/trusty

« back to all changes in this revision

Viewing changes to libs-external/USI++/samples/icmp_sniff.cc

  • Committer: Bazaar Package Importer
  • Author(s): Richard Atterer
  • Date: 2005-02-22 22:54:24 UTC
  • mfrom: (1.2.1 upstream) (2.1.2 hoary)
  • Revision ID: james.westby@ubuntu.com-20050222225424-6cqy8rr45pkna819
Tags: 0.2.2-1
New upstream version

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*** Simple ICMP-monitor. GPL.
 
2
 *** 
 
3
 ***/
 
4
#include <iostream.h>
 
5
#include <string.h>
 
6
#include <usi++/usi++.h>
 
7
 
 
8
int main(int argc, char **argv)
 
9
{
 
10
        ICMP icmp("127.0.0.1");
 
11
        char buf[1000] = {0}, src[1000], dst[1000];
 
12
        int i = 0;
 
13
                
 
14
        if (argc < 2) {
 
15
                cout<<argv[0]<<" [intf]\n";
 
16
                exit(1);
 
17
        }
 
18
        icmp.init_device(argv[1], 1, 500);
 
19
        
 
20
//      icmp.setfilter("icmp");
 
21
        char smac[100], dmac[100];
 
22
        while(1){
 
23
                memset(buf,0,1000);
 
24
                // blocks
 
25
                cout<<icmp.sniffpack(buf, 1000)<<endl;
 
26
#ifdef PRINT_MAC                
 
27
                cout<<"["<<icmp.get_hwsrc(smac, 100)<<"->"<<icmp.get_hwdst(dmac, 100)<<"]:";
 
28
#endif
 
29
                cout<<"type:"<<(int)icmp.get_type()<<" ["<<icmp.get_src(1, src, 1000)<<" -> "
 
30
                    <<icmp.get_dst(1, dst, 1000)<<"] "<<"seq: "<<icmp.get_seq()
 
31
                    <<" ttl: "<<(int)icmp.get_ttl()<<" id: "<<icmp.get_icmpId()<<endl;
 
32
                    //<<buf<<endl;
 
33
                
 
34
        }
 
35
        return 0;
 
36
}
 
37