SendARP 没有设置我的 mac 数组,所以同样当我尝试将 mac 数组转换为 BYTE 以将其转换为人类可读时,它也会在其中获取随机字符。memset 似乎也没有使 MacAddr 为 0!
std::wstring GetMacAddress(IPAddr destip)
{
DWORD ret;
ULONG MacAddr[2] = {0}; //initialize instead of memset
ULONG PhyAddrLen = 6; /* default to length of six bytes */
unsigned char mac[6];
//memset(MacAddr, 0, sizeof(MacAddr)); //MacAddr doesn't get set to 0!
//Send an arp packet
ret = SendARP(destip , 0, MacAddr , &PhyAddrLen); //MacAddr stays
//Prepare the mac address
if (ret == NO_ERROR)
{
BYTE *bMacAddr = (BYTE *) & MacAddr;
if(PhyAddrLen)
{
for (int i = 0; i < (int) PhyAddrLen; i++)
{
mac[i] = (char)bMacAddr[i];
}
}
}
}
我已经尝试了多种方法让 MacAddr 由 SendARP 函数设置,但它似乎不起作用并且它不返回错误。