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

GetIpForwardTable2

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

シグネチャ

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

WIN32_ERROR GetIpForwardTable2(
    ADDRESS_FAMILY Family,
    MIB_IPFORWARD_TABLE2** Table
);

パラメーター

名前方向
FamilyADDRESS_FAMILYin
TableMIB_IPFORWARD_TABLE2**out

戻り値の型: WIN32_ERROR

各言語での呼び出し定義

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

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

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

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

var (
	iphlpapi = windows.NewLazySystemDLL("IPHLPAPI.dll")
	procGetIpForwardTable2 = iphlpapi.NewProc("GetIpForwardTable2")
)

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