wpcCapture.cpp

/*
    wpcobj is a C++ wrapper for libpcap (the packet capture library)
    Copyright (C) 2009 Positive Technologies

    This file is part of wpcobj

    wpcobj is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    wpcobj is is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with wpcobj is.  If not, see <http://www.gnu.org/licenses/>.
*/

#ifndef _WIN32_WINNT          // Allow use of features specific to Windows XP or later.                   
#define _WIN32_WINNT 0x0501   // Change this to the appropriate value to target other versions of Windows.
#endif                                    

#include <stdio.h>
#include <wpcobj.h>
#ifdef WIN32
#include <ipHlpApi.h>
#endif //WIN32

int main(int argc, char* argv[])
{
    string filter = "host ";
    string dump;
    int count;
    int maxCount = 10;
    WpcPacket pkt;

    // default to unspecified address family (both)
    try {
        if (argc < 2) {
            printf("Usage: %s <target> [<num of packets>]\n\n", argv[0]);
            return -1;
        }
        WpcAdapter adapt = WpcGetBestAdapter(argv[1]);
        printf("Found suitable adapter: %s\n", adapt.GetIfaceDesc().c_str());
        
        filter += argv[1];
        adapt.StartCapture(filter);
        if (argc > 2) {
            maxCount = atoi(argv[2]);
        }
        for (count = 0; count < maxCount;) {
            if (adapt.ReadPacket(pkt)) {
                dump = pkt.Dump();
                printf("Packet #%d\n%s\n", count++, dump.c_str());
            }
        }
        adapt.StopCapture();

    }
    catch (...) {
        printf("Something strange happens! Exiting...\n");
    }
      return 0;
}



 
©2009 Positive Technologies
 
Generated on Fri May 22 18:17:00 2009 for wpcObj by 
 
 
1.5.7
 
Get wpcObj at SourceForge.net. Fast, secure and Free Open Source software downloads