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

GetIpForwardTable

関数
IPv4のルーティングテーブル(経路情報)を取得する。
DLLIPHLPAPI.dll呼出規約winapi対応OSWindows 2000 以降

シグネチャ

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

DWORD GetIpForwardTable(
    MIB_IPFORWARDTABLE* pIpForwardTable,   // optional
    DWORD* pdwSize,
    BOOL bOrder
);

パラメーター

名前方向
pIpForwardTableMIB_IPFORWARDTABLE*outoptional
pdwSizeDWORD*inout
bOrderBOOLin

戻り値の型: DWORD

各言語での呼び出し定義

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

DWORD GetIpForwardTable(
    MIB_IPFORWARDTABLE* pIpForwardTable,   // optional
    DWORD* pdwSize,
    BOOL bOrder
);
[DllImport("IPHLPAPI.dll", ExactSpelling = true)]
static extern uint GetIpForwardTable(
    IntPtr pIpForwardTable,   // MIB_IPFORWARDTABLE* optional, out
    ref uint pdwSize,   // DWORD* in/out
    bool bOrder   // BOOL
);
<DllImport("IPHLPAPI.dll", ExactSpelling:=True)>
Public Shared Function GetIpForwardTable(
    pIpForwardTable As IntPtr,   ' MIB_IPFORWARDTABLE* optional, out
    ByRef pdwSize As UInteger,   ' DWORD* in/out
    bOrder As Boolean   ' BOOL
) As UInteger
End Function
' pIpForwardTable : MIB_IPFORWARDTABLE* optional, out
' pdwSize : DWORD* in/out
' bOrder : BOOL
Declare PtrSafe Function GetIpForwardTable Lib "iphlpapi" ( _
    ByVal pIpForwardTable 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

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

lib = Fiddle.dlopen('IPHLPAPI.dll')
GetIpForwardTable = Fiddle::Function.new(
  lib['GetIpForwardTable'],
  [
    Fiddle::TYPE_VOIDP,  # pIpForwardTable : MIB_IPFORWARDTABLE* optional, out
    Fiddle::TYPE_VOIDP,  # pdwSize : DWORD* in/out
    Fiddle::TYPE_INT,  # bOrder : BOOL
  ],
  -Fiddle::TYPE_INT)
#[link(name = "iphlpapi")]
extern "system" {
    fn GetIpForwardTable(
        pIpForwardTable: *mut MIB_IPFORWARDTABLE,  // MIB_IPFORWARDTABLE* 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 GetIpForwardTable(IntPtr pIpForwardTable, ref uint pdwSize, bool bOrder);
"@
$api = Add-Type -MemberDefinition $sig -Name 'IPHLPAPI_GetIpForwardTable' -Namespace Win32 -PassThru
# $api::GetIpForwardTable(pIpForwardTable, pdwSize, bOrder)
#uselib "IPHLPAPI.dll"
#func global GetIpForwardTable "GetIpForwardTable" sptr, sptr, sptr
; GetIpForwardTable varptr(pIpForwardTable), varptr(pdwSize), bOrder   ; 戻り値は stat
; pIpForwardTable : MIB_IPFORWARDTABLE* optional, out -> "sptr"
; pdwSize : DWORD* in/out -> "sptr"
; bOrder : BOOL -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。
出力引数:
#uselib "IPHLPAPI.dll"
#cfunc global GetIpForwardTable "GetIpForwardTable" var, var, int
; res = GetIpForwardTable(pIpForwardTable, pdwSize, bOrder)
; pIpForwardTable : MIB_IPFORWARDTABLE* optional, out -> "var"
; pdwSize : DWORD* in/out -> "var"
; bOrder : BOOL -> "int"
; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。
出力引数:
; DWORD GetIpForwardTable(MIB_IPFORWARDTABLE* pIpForwardTable, DWORD* pdwSize, BOOL bOrder)
#uselib "IPHLPAPI.dll"
#cfunc global GetIpForwardTable "GetIpForwardTable" var, var, int
; res = GetIpForwardTable(pIpForwardTable, pdwSize, bOrder)
; pIpForwardTable : MIB_IPFORWARDTABLE* 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")
	procGetIpForwardTable = iphlpapi.NewProc("GetIpForwardTable")
)

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