Created
January 26, 2018 01:04
-
-
Save jrussett/a324581b91021a7dc5dd0f83120124b1 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// +build windows | |
package main | |
import ( | |
"fmt" | |
"unsafe" | |
"unicode/utf16" | |
"golang.org/x/sys/windows" | |
) | |
func main() { | |
sizePointer := uint32(15 * 1024) | |
adapterAddresses_ := make([]byte, sizePointer) | |
var adapterAddresses *windows.IpAdapterAddresses = (*windows.IpAdapterAddresses)(unsafe.Pointer(&adapterAddresses_[0])) | |
err := windows.GetAdaptersAddresses(windows.AF_UNSPEC, 0, 0, adapterAddresses, &sizePointer) | |
if err != nil { | |
panic(err) | |
} | |
dumpAddress(adapterAddresses) | |
} | |
func dumpAddress(addr *windows.IpAdapterAddresses) { | |
fmt.Printf("AdapterName = %s\n", bytePtrToString(addr.AdapterName)) | |
fmt.Printf("FriendlyName = %s\n", cStringToString(addr.FriendlyName)) | |
if addr.Next != nil { | |
dumpAddress(addr.Next) | |
} | |
} | |
func bytePtrToString(p *uint8) string { | |
a := (*[10000]uint8)(unsafe.Pointer(p)) | |
i := 0 | |
for a[i] != 0 { | |
i++ | |
} | |
return string(a[:i]) | |
} | |
func cStringToString(cs *uint16) (s string) { | |
if cs != nil { | |
us := make([]uint16, 0, 256) | |
for p := uintptr(unsafe.Pointer(cs)); ; p += 2 { | |
u := *(*uint16)(unsafe.Pointer(p)) | |
if u == 0 { | |
return string(utf16.Decode(us)) | |
} | |
us = append(us, u) | |
} | |
} | |
return "" | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
See referenced: https://github.com/Regner/albiondata-client/blob/master/client/net_interface_filter_win.go