According to information I founded I use MIB_IPNETROW structure while processing my ARP edit program:
const int MAXLEN_PHYSADDR = 8;
const int ERROR_INSUFFICIENT_BUFFER = 122;
[StructLayout(LayoutKind.Sequential)]
private struct MIB_IPNETROW
{
[MarshalAs(UnmanagedType.U4)]
public int dwIndex;
[MarshalAs(UnmanagedType.U4)]
public int dwPhysAddrLen;
[MarshalAs(UnmanagedType.ByValArray, SizeConst =
MAXLEN_PHYSADDR)]
public byte[] bPhysAddr;
[MarshalAs(UnmanagedType.U4)]
public int dwAddr;
[MarshalAs(UnmanagedType.U4)]
public int dwType;
}
And it's OK when I getting ARP table across GetIpNetTable() function, but the problem is in GetIpNetTable() which throws System.AccessViolationException: 'Attempted to read or write protected memory. This is often an indication that other memory is corrupt.'
Here is the code of method (ArpRow just contains some fields, like addresses, for example):
public static void DeleteArpNote(ArpRow toDel)
{
MIB_IPNETROW pArpEntry = new MIB_IPNETROW();
pArpEntry.dwPhysAddrLen = 0;
pArpEntry.dwIndex = toDel.index;
pArpEntry.dwAddr = BitConverter.ToInt32(toDel.ipAddress.GetAddressBytes(), 0);
pArpEntry.bPhysAddr = toDel.macAddress.GetAddressBytes();
pArpEntry.dwType = toDel.type;
DeleteIpNetEntry(pArpEntry);
}