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

GetUnicastIpAddressTable

関数
ユニキャストIPアドレスの一覧テーブルを取得する。
DLLIPHLPAPI.dll呼出規約winapi対応OSWindows Vista 以降

シグネチャ

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

WIN32_ERROR GetUnicastIpAddressTable(
    ADDRESS_FAMILY Family,
    MIB_UNICASTIPADDRESS_TABLE** Table
);

パラメーター

名前方向
FamilyADDRESS_FAMILYin
TableMIB_UNICASTIPADDRESS_TABLE**out

戻り値の型: WIN32_ERROR

各言語での呼び出し定義

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

WIN32_ERROR GetUnicastIpAddressTable(
    ADDRESS_FAMILY Family,
    MIB_UNICASTIPADDRESS_TABLE** Table
);
[DllImport("IPHLPAPI.dll", ExactSpelling = true)]
static extern uint GetUnicastIpAddressTable(
    ushort Family,   // ADDRESS_FAMILY
    IntPtr Table   // MIB_UNICASTIPADDRESS_TABLE** out
);
<DllImport("IPHLPAPI.dll", ExactSpelling:=True)>
Public Shared Function GetUnicastIpAddressTable(
    Family As UShort,   ' ADDRESS_FAMILY
    Table As IntPtr   ' MIB_UNICASTIPADDRESS_TABLE** out
) As UInteger
End Function
' Family : ADDRESS_FAMILY
' Table : MIB_UNICASTIPADDRESS_TABLE** out
Declare PtrSafe Function GetUnicastIpAddressTable 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

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

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

var (
	iphlpapi = windows.NewLazySystemDLL("IPHLPAPI.dll")
	procGetUnicastIpAddressTable = iphlpapi.NewProc("GetUnicastIpAddressTable")
)

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