Skip to content

Commit 94ad893

Browse files
database64128alexbrainman
authored andcommitted
windows: add GetIfTable2Ex, GetIpInterface{Entry,Table}, GetUnicastIpAddressTable
GetIfTable2Ex retrieves the MIB-II interface table. GetIpInterfaceEntry retrieves IP information for the specified interface. GetIpInterfaceTable retrieves the IP interface entries. GetUnicastIpAddressTable retrieves the unicast IP address table. Change-Id: If9f619cb48da204da3bac8b429b3231432337b0a Reviewed-on: https://go-review.googlesource.com/c/sys/+/744880 LUCI-TryBot-Result: golang-scoped@luci-project-accounts.iam.gserviceaccount.com <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: Damien Neil <dneil@google.com> Reviewed-by: Carlos Amedee <carlos@golang.org> Reviewed-by: Alex Brainman <alex.brainman@gmail.com>
1 parent 54fe89f commit 94ad893

3 files changed

Lines changed: 69 additions & 0 deletions

File tree

windows/syscall_windows.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -892,9 +892,13 @@ const socket_error = uintptr(^uint32(0))
892892
//sys MultiByteToWideChar(codePage uint32, dwFlags uint32, str *byte, nstr int32, wchar *uint16, nwchar int32) (nwrite int32, err error) = kernel32.MultiByteToWideChar
893893
//sys getBestInterfaceEx(sockaddr unsafe.Pointer, pdwBestIfIndex *uint32) (errcode error) = iphlpapi.GetBestInterfaceEx
894894
//sys GetIfEntry2Ex(level uint32, row *MibIfRow2) (errcode error) = iphlpapi.GetIfEntry2Ex
895+
//sys GetIfTable2Ex(level uint32, table **MibIfTable2) (errcode error) = iphlpapi.GetIfTable2Ex
895896
//sys GetIpForwardEntry2(row *MibIpForwardRow2) (errcode error) = iphlpapi.GetIpForwardEntry2
896897
//sys GetIpForwardTable2(family uint16, table **MibIpForwardTable2) (errcode error) = iphlpapi.GetIpForwardTable2
898+
//sys GetIpInterfaceEntry(row *MibIpInterfaceRow) (errcode error) = iphlpapi.GetIpInterfaceEntry
899+
//sys GetIpInterfaceTable(family uint16, table **MibIpInterfaceTable) (errcode error) = iphlpapi.GetIpInterfaceTable
897900
//sys GetUnicastIpAddressEntry(row *MibUnicastIpAddressRow) (errcode error) = iphlpapi.GetUnicastIpAddressEntry
901+
//sys GetUnicastIpAddressTable(family uint16, table **MibUnicastIpAddressTable) (errcode error) = iphlpapi.GetUnicastIpAddressTable
898902
//sys FreeMibTable(memory unsafe.Pointer) = iphlpapi.FreeMibTable
899903
//sys NotifyIpInterfaceChange(family uint16, callback uintptr, callerContext unsafe.Pointer, initialNotification bool, notificationHandle *Handle) (errcode error) = iphlpapi.NotifyIpInterfaceChange
900904
//sys NotifyRouteChange2(family uint16, callback uintptr, callerContext unsafe.Pointer, initialNotification bool, notificationHandle *Handle) (errcode error) = iphlpapi.NotifyRouteChange2

windows/types_windows.go

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2320,6 +2320,21 @@ type MibIfRow2 struct {
23202320
OutQLen uint64
23212321
}
23222322

2323+
// MIB_IF_TABLE_LEVEL enumeration from netioapi.h or
2324+
// https://learn.microsoft.com/en-us/windows/win32/api/netioapi/ne-netioapi-mib_if_table_level.
2325+
const (
2326+
MibIfTableNormal = 0
2327+
MibIfTableRaw = 1
2328+
MibIfTableNormalWithoutStatistics = 2
2329+
)
2330+
2331+
// MibIfTable2 contains a table of logical and physical interface entries. See
2332+
// https://learn.microsoft.com/en-us/windows/win32/api/netioapi/ns-netioapi-mib_if_table2.
2333+
type MibIfTable2 struct {
2334+
NumEntries uint32
2335+
Table [1]MibIfRow2
2336+
}
2337+
23232338
// IP_ADDRESS_PREFIX stores an IP address prefix. See
23242339
// https://learn.microsoft.com/en-us/windows/win32/api/netioapi/ns-netioapi-ip_address_prefix.
23252340
type IpAddressPrefix struct {
@@ -2413,6 +2428,13 @@ type MibUnicastIpAddressRow struct {
24132428
CreationTimeStamp Filetime
24142429
}
24152430

2431+
// MibUnicastIpAddressTable contains a table of unicast IP address entries. See
2432+
// https://learn.microsoft.com/en-us/windows/win32/api/netioapi/ns-netioapi-mib_unicastipaddress_table.
2433+
type MibUnicastIpAddressTable struct {
2434+
NumEntries uint32
2435+
Table [1]MibUnicastIpAddressRow
2436+
}
2437+
24162438
const ScopeLevelCount = 16
24172439

24182440
// MIB_IPINTERFACE_ROW stores interface management information for a particular IP address family on a network interface.
@@ -2455,6 +2477,13 @@ type MibIpInterfaceRow struct {
24552477
DisableDefaultRoutes uint8
24562478
}
24572479

2480+
// MibIpInterfaceTable contains a table of IP interface entries. See
2481+
// https://learn.microsoft.com/en-us/windows/win32/api/netioapi/ns-netioapi-mib_ipinterface_table.
2482+
type MibIpInterfaceTable struct {
2483+
NumEntries uint32
2484+
Table [1]MibIpInterfaceRow
2485+
}
2486+
24582487
// Console related constants used for the mode parameter to SetConsoleMode. See
24592488
// https://docs.microsoft.com/en-us/windows/console/setconsolemode for details.
24602489

windows/zsyscall_windows.go

Lines changed: 36 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)