winnet_windows.go 481 B

1234567891011121314151617181920212223242526
  1. // Copyright (c) Tailscale Inc & AUTHORS
  2. // SPDX-License-Identifier: BSD-3-Clause
  3. package winnet
  4. import (
  5. "fmt"
  6. "syscall"
  7. "unsafe"
  8. "github.com/go-ole/go-ole"
  9. )
  10. func (v *INetworkConnection) GetAdapterId() (string, error) {
  11. buf := ole.GUID{}
  12. hr, _, _ := syscall.Syscall(
  13. v.VTable().GetAdapterId,
  14. 2,
  15. uintptr(unsafe.Pointer(v)),
  16. uintptr(unsafe.Pointer(&buf)),
  17. 0)
  18. if hr != 0 {
  19. return "", fmt.Errorf("GetAdapterId failed: %08x", hr)
  20. }
  21. return buf.String(), nil
  22. }