Win32 API 日本語リファレンス
ホームNetworkManagement.IpHelper › GetIpInterfaceTable

GetIpInterfaceTable

関数
指定アドレスファミリのIPインターフェイス構成テーブルを取得する。
DLLIPHLPAPI.dll呼出規約winapi対応OSWindows Vista 以降

シグネチャ

// IPHLPAPI.dll
#include <windows.h>

WIN32_ERROR GetIpInterfaceTable(
    ADDRESS_FAMILY Family,
    MIB_IPINTERFACE_TABLE** Table
);

パラメーター

名前方向
FamilyADDRESS_FAMILYin
TableMIB_IPINTERFACE_TABLE**out

戻り値の型: WIN32_ERROR

各言語での呼び出し定義

// IPHLPAPI.dll
#include <windows.h>

WIN32_ERROR GetIpInterfaceTable(
    ADDRESS_FAMILY Family,
    MIB_IPINTERFACE_TABLE** Table
);
[DllImport("IPHLPAPI.dll", ExactSpelling = true)]
static extern uint GetIpInterfaceTable(
    ushort Family,   // ADDRESS_FAMILY
    IntPtr Table   // MIB_IPINTERFACE_TABLE** out
);
<DllImport("IPHLPAPI.dll", ExactSpelling:=True)>
Public Shared Function GetIpInterfaceTable(
    Family As UShort,   ' ADDRESS_FAMILY
    Table As IntPtr   ' MIB_IPINTERFACE_TABLE** out
) As UInteger
End Function
' Family : ADDRESS_FAMILY
' Table : MIB_IPINTERFACE_TABLE** out
Declare PtrSafe Function GetIpInterfaceTable Lib "iphlpapi" ( _
    ByVal Family As Integer, _
    ByVal Table As LongPtr) As Long
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。
import ctypes
from ctypes import wintypes

GetIpInterfaceTable = ctypes.windll.iphlpapi.GetIpInterfaceTable
GetIpInterfaceTable.restype = wintypes.DWORD
GetIpInterfaceTable.argtypes = [
    ctypes.c_ushort,  # Family : ADDRESS_FAMILY
    ctypes.c_void_p,  # Table : MIB_IPINTERFACE_TABLE** out
]
require 'fiddle'
require 'fiddle/import'

lib = Fiddle.dlopen('IPHLPAPI.dll')
GetIpInterfaceTable = Fiddle::Function.new(
  lib['GetIpInterfaceTable'],
  [
    -Fiddle::TYPE_SHORT,  # Family : ADDRESS_FAMILY
    Fiddle::TYPE_VOIDP,  # Table : MIB_IPINTERFACE_TABLE** out
  ],
  -Fiddle::TYPE_INT)
#[link(name = "iphlpapi")]
extern "system" {
    fn GetIpInterfaceTable(
        Family: u16,  // ADDRESS_FAMILY
        Table: *mut *mut MIB_IPINTERFACE_TABLE  // MIB_IPINTERFACE_TABLE** out
    ) -> u32;
}
// crates: windows-sys provides ready-made bindings for this API.
$sig = @"
[DllImport("IPHLPAPI.dll")]
public static extern uint GetIpInterfaceTable(ushort Family, IntPtr Table);
"@
$api = Add-Type -MemberDefinition $sig -Name 'IPHLPAPI_GetIpInterfaceTable' -Namespace Win32 -PassThru
# $api::GetIpInterfaceTable(Family, Table)
#uselib "IPHLPAPI.dll"
#func global GetIpInterfaceTable "GetIpInterfaceTable" sptr, sptr
; GetIpInterfaceTable Family, varptr(Table)   ; 戻り値は stat
; Family : ADDRESS_FAMILY -> "sptr"
; Table : MIB_IPINTERFACE_TABLE** out -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。
出力引数:
#uselib "IPHLPAPI.dll"
#cfunc global GetIpInterfaceTable "GetIpInterfaceTable" int, var
; res = GetIpInterfaceTable(Family, Table)
; Family : ADDRESS_FAMILY -> "int"
; Table : MIB_IPINTERFACE_TABLE** out -> "var"
; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。
出力引数:
; WIN32_ERROR GetIpInterfaceTable(ADDRESS_FAMILY Family, MIB_IPINTERFACE_TABLE** Table)
#uselib "IPHLPAPI.dll"
#cfunc global GetIpInterfaceTable "GetIpInterfaceTable" int, var
; res = GetIpInterfaceTable(Family, Table)
; Family : ADDRESS_FAMILY -> "int"
; Table : MIB_IPINTERFACE_TABLE** out -> "var"
; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。
import (
	"golang.org/x/sys/windows"
	"unsafe"
)

var (
	iphlpapi = windows.NewLazySystemDLL("IPHLPAPI.dll")
	procGetIpInterfaceTable = iphlpapi.NewProc("GetIpInterfaceTable")
)

// Family (ADDRESS_FAMILY), Table (MIB_IPINTERFACE_TABLE** out)
r1, _, err := procGetIpInterfaceTable.Call(
	uintptr(Family),
	uintptr(Table),
)
_ = err  // syscall.Errno (valid when the call sets last-error)
_ = r1   // WIN32_ERROR
function GetIpInterfaceTable(
  Family: Word;   // ADDRESS_FAMILY
  Table: Pointer   // MIB_IPINTERFACE_TABLE** out
): DWORD; stdcall;
  external 'IPHLPAPI.dll' name 'GetIpInterfaceTable';
result := DllCall("IPHLPAPI\GetIpInterfaceTable"
    , "UShort", Family   ; ADDRESS_FAMILY
    , "Ptr", Table   ; MIB_IPINTERFACE_TABLE** out
    , "UInt")   ; return: WIN32_ERROR
●GetIpInterfaceTable(Family, Table) = DLL("IPHLPAPI.dll", "dword GetIpInterfaceTable(int, void*)")
# 呼び出し: GetIpInterfaceTable(Family, Table)
# Family : ADDRESS_FAMILY -> "int"
# Table : MIB_IPINTERFACE_TABLE** out -> "void*"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。