wpcGetMac.cpp
Demostrates static functions of
WpcAdapter and routing subsystem.
#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[])
{
WpcMacAddr mac;
bpf_u_int32 ipaddr;
try {
if (argc < 2) {
printf("Usage: %s <target>\n\n", argv[0]);
printf("Sample tries to resolve MAC address of the given target.\n");
printf("It may be host's address or the router address if the "
"target is outside local network.\n");
return -1;
}
if (WpcGetArpRecord(argv[1], &mac)) {
printf("MAC address for host \"%s\" found!\nResult is: %s\n", argv[1], mac.ToString().c_str());
}
else {
ipaddr = WpcGetNextHop(argv[1]);
if(WpcIsLocalIP(ipaddr)) {
printf("Host \"%s\" is localhost!\n", argv[1]);
return 0;
}
if (WpcGetArpRecord(ipaddr, &mac)) {
WpcAddress routeAddr(ipaddr);
printf("Host \"%s\" is out of local segment!\n", argv[1]);
printf("MAC address for router \"%s\" is: %s\n",
routeAddr.GetAddressStr().c_str(), mac.ToString().c_str());
}
else {
printf("Can't find MAC address of the target. Sorry.\n");
}
}
}
catch (...) {
printf("Something strange happens! Exiting...\n");
}
return 0;
}