Beispiel #1
0
func (cInfo *connectionInfo) getAdapterList() (*syscall.IpAdapterInfo, error) {
	bTmp := make([]byte, 1000)
	length := uint32(len(bTmp))
	adtr := (*syscall.IpAdapterInfo)(unsafe.Pointer(&bTmp[0]))

	if err := syscall.GetAdaptersInfo(adtr, &length); err == syscall.ERROR_BUFFER_OVERFLOW {
		bTmp = make([]byte, length)
		adtr = (*syscall.IpAdapterInfo)(unsafe.Pointer(&bTmp[0]))
		if err = syscall.GetAdaptersInfo(adtr, &length); err != nil {
			return nil, os.NewSyscallError("GetAdaptersInfo", err)
		}
	}
	return adtr, nil
}
Beispiel #2
0
// borrowed from src/pkg/net/interface_windows.go
func getAdapterList() (*syscall.IpAdapterInfo, error) {
	b := make([]byte, 1000)
	l := uint32(len(b))
	a := (*syscall.IpAdapterInfo)(unsafe.Pointer(&b[0]))
	err := syscall.GetAdaptersInfo(a, &l)
	if err == syscall.ERROR_BUFFER_OVERFLOW {
		b = make([]byte, l)
		a = (*syscall.IpAdapterInfo)(unsafe.Pointer(&b[0]))
		err = syscall.GetAdaptersInfo(a, &l)
	}
	if err != nil {
		return nil, os.NewSyscallError("GetAdaptersInfo", err)
	}
	return a, nil
}
func getAdapterList() (*syscall.IpAdapterInfo, error) {
	b := make([]byte, 1000)
	l := uint32(len(b))
	a := (*syscall.IpAdapterInfo)(unsafe.Pointer(&b[0]))
	// TODO(mikio): GetAdaptersInfo returns IP_ADAPTER_INFO that
	// contains IPv4 address list only. We should use another API
	// for fetching IPv6 stuff from the kernel.
	err := syscall.GetAdaptersInfo(a, &l)
	if err == syscall.ERROR_BUFFER_OVERFLOW {
		b = make([]byte, l)
		a = (*syscall.IpAdapterInfo)(unsafe.Pointer(&b[0]))
		err = syscall.GetAdaptersInfo(a, &l)
	}
	if err != nil {
		return nil, os.NewSyscallError("GetAdaptersInfo", err)
	}
	return a, nil
}