需要帮忙!调试信息:运行时检查失败#2 - 变量'IpNetRow2'周围的堆栈已损坏。 [英] Need Help! Debug Info: Run-Time Check Failure #2 - Stack around the variable 'IpNetRow2' was corrupted.
问题描述
亲爱的,
我正在尝试使用GetIpNetEntry2和ResolveIpNetEntry2函数从IPv4获取MAC地址。我得到了:
I am trying to use GetIpNetEntry2 and ResolveIpNetEntry2 functions to get MAC address from a IPv4. I am getting:
运行时检查失败#2 - 变量'IpNetRow2'周围的堆栈已损坏。
在以下函数结束时:
#define DEFAULT_MAC_LEN 6 // IPv4
static int GetMacAddress(SOCKADDR_IN ClientAddr)
{
MIB_IPNET_ROW2 IpNetRow2 = { 0 };
DWORD dwBestIfIndex = 0;
int nRet = -1;
unsigned char MACAddress[DEFAULT_MAC_LEN];
// Retrieves the index of the interface that has the best route to the client IP address.
GetBestInterface(inet_addr(inet_ntoa(ClientAddr.sin_addr)), &dwBestIfIndex);
// Finds MAC address from the local computer
IpNetRow2.InterfaceIndex = dwBestIfIndex;
memcpy(&IpNetRow2.Address, &ClientAddr, sizeof(SOCKADDR_IN));
nRet = GetIpNetEntry2(&IpNetRow2);
if (nRet != NO_ERROR)
{
// Could not find the MAC address in the cache, lets hit the wire.
nRet = ResolveIpNetEntry2(&IpNetRow2, NULL);
}
if (nRet == NO_ERROR)
{
if (DEFAULT_MAC_LEN == IpNetRow2.PhysicalAddressLength)
{
memset(&MACAddress, 0, DEFAULT_MAC_LEN);
memcpy(MACAddress, IpNetRow2.PhysicalAddress, DEFAULT_MAC_LEN);
sprintf(strMACAddress, "%.2X-%.2X-%.2X-%.2X-%.2X-%.2X",
MACAddress [0] ,MACAddress [1],MACAddress [2],MACAddress [3],MACAddress [4],MACAddress [5]);
}
}
返回nRet;
}
MACAddress[0], MACAddress[1], MACAddress[2], MACAddress[3], MACAddress[4], MACAddress[5]); } } return nRet; }
我搜索过就像我可以描述如何诊断问题一样;但是我没有找到任何相关的解决方案。代码很简单,我不知道
会导致这样的问题。有人可以帮帮我吗?非常感谢。
此致,
James
推荐答案
亲爱的,
我正在尝试使用GetIpNetEntry2和ResolveIpNetEntry2函数来从Visual Studio 2017(SDK版本8.1)中的Windows 10(Enterprise 1803)上的IPv4获取MAC地址。我得到了:
I am trying to use GetIpNetEntry2 and ResolveIpNetEntry2 functions to get MAC address from a IPv4 on Windows 10 (Enterprise 1803) in Visual Studio 2017 (SDK version 8.1). I am getting:
运行时检查失败#2 - 变量'IpNetRow2'周围的堆栈已损坏。
在以下函数结束时:
static int GetMacAddress(SOCKADDR_IN ClientAddr)
{
MIB_IPNET_ROW2 IpNetRow2 = { 0 };
DWORD dwBestIfIndex = 0;
int nRet = -1;
// Retrieves the index of the interface that has the best route to the client IP address.
GetBestInterface(inet_addr(inet_ntoa(ClientAddr.sin_addr)), &dwBestIfIndex);
// Finds MAC address from the local computer
IpNetRow2.InterfaceIndex = dwBestIfIndex;
memcpy(&IpNetRow2.Address, &ClientAddr, sizeof(SOCKADDR_IN));
nRet = GetIpNetEntry2(&IpNetRow2);
if (nRet != NO_ERROR)
{
// Could not find the MAC address in the cache, lets hit the wire.
nRet = ResolveIpNetEntry2(&IpNetRow2, NULL);
}
return nRet;
}
Results: dwBestIfIndex = 22; nRet = 0;
我已经尽可能多地搜索了如何描述诊断问题;但是我没有找到任何相关的解决方案。代码很简单,我不知道
会导致这样的问题。有人可以帮帮我吗?非常感谢。
此致,
James
这篇关于需要帮忙!调试信息:运行时检查失败#2 - 变量'IpNetRow2'周围的堆栈已损坏。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!