SendARP P/Invoke goes like this:
[DllImport("iphlpapi.dll", ExactSpelling=true)]
public static extern int SendARP( int destIp, int srcIP, byte[] macAddr, ref uint physicalAddrLen );
PInvoke.NET has this example:
IPAddress dst = IPAddress.Parse("192.168.2.1"); // the destination IP address
byte[] macAddr = new byte[6];
uint macAddrLen = (uint)macAddr.Length;
if (SendARP(BitConverter.ToInt32(dst.GetAddressBytes(), 0), 0, macAddr, ref macAddrLen) != 0)
throw new InvalidOperationException("SendARP failed.");
string[] str = new string[(int)macAddrLen];
for (int i=0; i<macAddrLen; i++)
str[i] = macAddr[i].ToString("x2");
Console.WriteLine(string.Join(":", str));
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…