I'm trying to call a Windows API SendARP from Go to send arp request on Windows, but it always returns 1168
, AKA ERROR_NOT_FOUND
, description by MSDN on this error code:
Element not found. This error is returned on Windows Vista if the the SrcIp parameter does not specify a source IPv4 address on an interface on the local computer or the INADDR_ANY IP address (an IPv4 address of 0.0.0.0).
but I'm on Windows 7, moreover I do specify a right source IPv4 address. And I see no ARP packet sent in Wireshark. So where is the problem?
package main
import (
"fmt"
"syscall"
"net"
"unsafe"
)
var (
iphlp, _ = syscall.LoadLibrary("iphlpapi.dll")
SendARP, _ = syscall.GetProcAddress(iphlp, "SendARP")
)
func sendARP(src, dst net.IP) {
//var nargs uintptr = 4
var len uint = 6
mac := []byte{0xff, 0xff, 0xff, 0xff, 0xff, 0xff}
ret, _, callErr := syscall.Syscall6(
uintptr(SendARP), 4,
uintptr(unsafe.Pointer(&dst[0])),
uintptr(unsafe.Pointer(&src[0])),
uintptr(unsafe.Pointer(&mac[0])),
uintptr(unsafe.Pointer(&len)),
0,
0)
if callErr == 0 {
fmt.Printf("result %v
", int(ret))
}
}
func main() {
defer syscall.FreeLibrary(iphlp)
fmt.Printf("addr: %v
", sendARP)
dst := net.IPv4(192,168,1,1)
src := net.IPv4(192,168,1,103)
sendARP(src, dst)
}