wpcInit.cpp
#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;
printf("Select adapter (0 - to exit):");
scanf("%d", &idx);
if (idx == 0) {
printf("Bye-bye!");
break;
}
if (idx > 0 && idx <= adaptersList.size()) {
idx--;
try
{
printf("Adapter description: %s\n", WpcAdapter::GetIfaceDesc(adaptersList[idx]).c_str());
printf("Adapter symbolic name: %s\n", adaptersList[idx].c_str());
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;
}