wpcInit.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>

int main(int argc, char* argv[])
{
    WpcStringList adaptersList;
    WpcStringList::iterator it;
    int i;

    WpcAdapter::SetAdaptersOptions();
    if(WpcAdapter::GetIfaceList(&adaptersList) == WPC_OK) {
        i = 1;
        for (it = adaptersList.begin(); it != adaptersList.end(); it++) {
            string ifn = *it;
            printf("%d. %s\n\t%s\n\n", i++, 
                WpcAdapter::GetIfaceDesc(ifn).c_str(), ifn.c_str());
        }
    }
    else {
        printf("Can't get adapters list!\n");
        return -1;
    }
    
    do 
    {
        int idx;
        WpcAdapter iface;
        WpcMacAddr macAddr;
        WpcAddressList addrList;

        string descs;
        // we can't use LOG_MESSAGE because it prints "newline"
        printf("Select adapter (0 - to exit):");
        scanf("%d", &idx);
        if (idx == 0) {
            printf("Bye-bye!");
            break;
        }
        if (idx > 0 && idx <= adaptersList.size()) {
            idx--; // to convert number to index
            try
            {
                printf("Adapter description: %s\n", WpcAdapter::GetIfaceDesc(adaptersList[idx]).c_str());
                printf("Adapter symbolic name: %s\n", adaptersList[idx].c_str());
                // we can't use LOG_MESSAGE because it prints "newline"
                printf("Try to receive adapter object...");
                iface = WpcAdapter::GetIface(adaptersList[idx]);
                printf(" ok\n");
                macAddr = iface.GetMacAddr();
                string locMac = macAddr.ToString();
                printf("Adapter MAC address: %s\n", locMac.c_str());
                printf("Try to receive adapter's addresses list...");
                addrList = iface.GetAddesses();
                printf(" ok\n");
                for (int i = 0; i < addrList.size(); i++) {
                    WpcAddress *addr = addrList[i];
                    printf("Address #%d: %s netmask=%s, broadcast=%s dest=%s\n", i,
                        addr->GetAddressStr().c_str(),
                        addr->GetNetmaskStr().c_str(),
                        addr->GetBcastAddressStr().c_str(),
                        addr->GetDestAddressStr().c_str());
                }
                printf("\n");
            }
            catch (...)
            {
                  printf("Something strange happens! Exiting...\n");
            }
        }
    } while(true);
    
      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