Need Help! Debug Info: Run-Time Check Failure #2 - Stack around the variable 'IpNetRow2' was corrupted.

  • Thread starter Thread starter FaTrEE
  • Start date Start date
F

FaTrEE

Guest
Dear all,

I am trying to use GetIpNetEntry2 and ResolveIpNetEntry2 functions to get MAC address from a IPv4. I am getting:

Run-Time Check Failure #2 - Stack around the variable 'IpNetRow2' was corrupted.

by the end of the following function:


#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]);
}
}
return nRet;
}


I have searched as much as I can for a description of how to diagnose the issue; however I have not found any solution that is relevant. The code is so simple and I do not have any idea on what part would cause such issue. Could anyone help me out please? Thank you very much.

Sincerely,

James

Continue reading...
 
Back
Top