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

GetIpAddrTable

関数
各インターフェイスに割り当てられたIPv4アドレスの一覧表を取得する。
DLLIPHLPAPI.dll呼出規約winapi対応OSWindows 2000 以降

シグネチャ

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

DWORD GetIpAddrTable(
    MIB_IPADDRTABLE* pIpAddrTable,   // optional
    DWORD* pdwSize,
    BOOL bOrder
);

パラメーター

名前方向
pIpAddrTableMIB_IPADDRTABLE*outoptional
pdwSizeDWORD*inout
bOrderBOOLin

戻り値の型: DWORD

各言語での呼び出し定義

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

DWORD GetIpAddrTable(
    MIB_IPADDRTABLE* pIpAddrTable,   // optional
    DWORD* pdwSize,
    BOOL bOrder
);
[DllImport("IPHLPAPI.dll", ExactSpelling = true)]
static extern uint GetIpAddrTable(
    IntPtr pIpAddrTable,   // MIB_IPADDRTABLE* optional, out
    ref uint pdwSize,   // DWORD* in/out
    bool bOrder   // BOOL
);
<DllImport("IPHLPAPI.dll", ExactSpelling:=True)>
Public Shared Function GetIpAddrTable(
    pIpAddrTable As IntPtr,   ' MIB_IPADDRTABLE* optional, out
    ByRef pdwSize As UInteger,   ' DWORD* in/out
    bOrder As Boolean   ' BOOL
) As UInteger
End Function
' pIpAddrTable : MIB_IPADDRTABLE* optional, out
' pdwSize : DWORD* in/out
' bOrder : BOOL
Declare PtrSafe Function GetIpAddrTable Lib "iphlpapi" ( _
    ByVal pIpAddrTable As LongPtr, _
    ByRef pdwSize As Long, _
    ByVal bOrder As Long) As Long
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。
import ctypes
from ctypes import wintypes

GetIpAddrTable = ctypes.windll.iphlpapi.GetIpAddrTable
GetIpAddrTable.restype = wintypes.DWORD
GetIpAddrTable.argtypes = [
    ctypes.c_void_p,  # pIpAddrTable : MIB_IPADDRTABLE* optional, out
    ctypes.POINTER(wintypes.DWORD),  # pdwSize : DWORD* in/out
    wintypes.BOOL,  # bOrder : BOOL
]
require 'fiddle'
require 'fiddle/import'

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

var (
	iphlpapi = windows.NewLazySystemDLL("IPHLPAPI.dll")
	procGetIpAddrTable = iphlpapi.NewProc("GetIpAddrTable")
)

// pIpAddrTable (MIB_IPADDRTABLE* optional, out), pdwSize (DWORD* in/out), bOrder (BOOL)
r1, _, err := procGetIpAddrTable.Call(
	uintptr(pIpAddrTable),
	uintptr(pdwSize),
	uintptr(bOrder),
)
_ = err  // syscall.Errno (valid when the call sets last-error)
_ = r1   // DWORD
function GetIpAddrTable(
  pIpAddrTable: Pointer;   // MIB_IPADDRTABLE* optional, out
  pdwSize: Pointer;   // DWORD* in/out
  bOrder: BOOL   // BOOL
): DWORD; stdcall;
  external 'IPHLPAPI.dll' name 'GetIpAddrTable';
result := DllCall("IPHLPAPI\GetIpAddrTable"
    , "Ptr", pIpAddrTable   ; MIB_IPADDRTABLE* optional, out
    , "Ptr", pdwSize   ; DWORD* in/out
    , "Int", bOrder   ; BOOL
    , "UInt")   ; return: DWORD
●GetIpAddrTable(pIpAddrTable, pdwSize, bOrder) = DLL("IPHLPAPI.dll", "dword GetIpAddrTable(void*, void*, bool)")
# 呼び出し: GetIpAddrTable(pIpAddrTable, pdwSize, bOrder)
# pIpAddrTable : MIB_IPADDRTABLE* optional, out -> "void*"
# pdwSize : DWORD* in/out -> "void*"
# bOrder : BOOL -> "bool"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。