GetIpNetTable
関数シグネチャ
// IPHLPAPI.dll
#include <windows.h>
DWORD GetIpNetTable(
MIB_IPNETTABLE* IpNetTable, // optional
DWORD* SizePointer,
BOOL Order
);パラメーター
| 名前 | 型 | 方向 | 説明 |
|---|---|---|---|
| IpNetTable | MIB_IPNETTABLE* | outoptional | IPv4 アドレスと物理アドレスの対応テーブルを MIB_IPNETTABLE 構造体として受け取るバッファーへのポインター。 |
| SizePointer | DWORD* | inout | 入力時には、pIpNetTable パラメーターが指すバッファーのサイズをバイト単位で指定します。 出力時には、バッファーが返される対応テーブルを保持するのに十分な大きさでない場合、この関数はこのパラメーターに必要なバッファーサイズ(バイト単位)を設定します。 |
| Order | BOOL | in | 返される対応テーブルを IP アドレスの昇順でソートするかどうかを指定する Boolean 値。このパラメーターが TRUE の場合、テーブルはソートされます。 |
戻り値の型: DWORD
公式ドキュメント
GetIpNetTable 関数は、IPv4 アドレスと物理アドレスの対応テーブルを取得します。
戻り値
関数が成功した場合、戻り値は NO_ERROR または ERROR_NO_DATA です。
関数が失敗した場合、またはデータを返さなかった場合、戻り値は次のいずれかのエラーコードになります。
| Return code | Description |
|---|---|
| pIpNetTable パラメーターが指すバッファーが十分な大きさではありません。必要なサイズは、pdwSize パラメーターが指す DWORD 変数に返されます。 | |
| 無効なパラメーターが関数に渡されました。このエラーは、pdwSize パラメーターが NULL の場合、または GetIpNetTable が pdwSize パラメーターの指すメモリに書き込めない場合に返されます。 | |
| 返すデータがありません。IPv4 アドレスと物理アドレスの対応テーブルが空です。この戻り値は、 GetIpNetTable 関数の呼び出しは成功したものの、返すデータが存在しなかったことを示します。 | |
| ローカルコンピューターで IPv4 トランスポートが構成されていません。 | |
|
返されたエラーのメッセージ文字列を取得するには、 FormatMessage を使用してください。 |
解説(Remarks)
GetIpNetTable 関数は、ローカルシステム上の IPv4 アドレスと物理アドレスの対応テーブルから IPv4 用の Address Resolution Protocol (ARP) エントリを列挙し、その情報を MIB_IPNETTABLE 構造体で返します。
IPv4 アドレスエントリは、pIpNetTable パラメーターが指すバッファー内の MIB_IPNETTABLE 構造体に返されます。MIB_IPNETTABLE 構造体には、ARP エントリの数と、各 IPv4 アドレスエントリに対応する MIB_IPNETROW 構造体の配列が含まれます。
pIpNetTable パラメーターが指す返された MIB_IPNETTABLE 構造体には、dwNumEntries メンバーと MIB_IPNETTABLE 構造体の table メンバーにある最初の MIB_IPNETROW 配列エントリとの間に、アライメント用のパディングが含まれる場合があることに注意してください。アライメント用のパディングは、MIB_IPNETROW 配列エントリの間にも存在する場合があります。MIB_IPNETROW 配列エントリにアクセスする際は、パディングが存在する可能性があることを前提とする必要があります。
Windows Vista 以降では、GetIpNetTable2 関数を使用して、IPv6 と IPv4 の両方の近隣 IP アドレスを取得できます。
Microsoft 公式リファレンス: 英語 (en-us) · 日本語 (ja-jp) · 原文ソース (GitHub)
各言語での呼び出し定義
// IPHLPAPI.dll
#include <windows.h>
DWORD GetIpNetTable(
MIB_IPNETTABLE* IpNetTable, // optional
DWORD* SizePointer,
BOOL Order
);[DllImport("IPHLPAPI.dll", ExactSpelling = true)]
static extern uint GetIpNetTable(
IntPtr IpNetTable, // MIB_IPNETTABLE* optional, out
ref uint SizePointer, // DWORD* in/out
bool Order // BOOL
);<DllImport("IPHLPAPI.dll", ExactSpelling:=True)>
Public Shared Function GetIpNetTable(
IpNetTable As IntPtr, ' MIB_IPNETTABLE* optional, out
ByRef SizePointer As UInteger, ' DWORD* in/out
Order As Boolean ' BOOL
) As UInteger
End Function' IpNetTable : MIB_IPNETTABLE* optional, out
' SizePointer : DWORD* in/out
' Order : BOOL
Declare PtrSafe Function GetIpNetTable Lib "iphlpapi" ( _
ByVal IpNetTable As LongPtr, _
ByRef SizePointer As Long, _
ByVal Order As Long) As Long
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。import ctypes
from ctypes import wintypes
GetIpNetTable = ctypes.windll.iphlpapi.GetIpNetTable
GetIpNetTable.restype = wintypes.DWORD
GetIpNetTable.argtypes = [
ctypes.c_void_p, # IpNetTable : MIB_IPNETTABLE* optional, out
ctypes.POINTER(wintypes.DWORD), # SizePointer : DWORD* in/out
wintypes.BOOL, # Order : BOOL
]require 'fiddle'
require 'fiddle/import'
lib = Fiddle.dlopen('IPHLPAPI.dll')
GetIpNetTable = Fiddle::Function.new(
lib['GetIpNetTable'],
[
Fiddle::TYPE_VOIDP, # IpNetTable : MIB_IPNETTABLE* optional, out
Fiddle::TYPE_VOIDP, # SizePointer : DWORD* in/out
Fiddle::TYPE_INT, # Order : BOOL
],
-Fiddle::TYPE_INT)#[link(name = "iphlpapi")]
extern "system" {
fn GetIpNetTable(
IpNetTable: *mut MIB_IPNETTABLE, // MIB_IPNETTABLE* optional, out
SizePointer: *mut u32, // DWORD* in/out
Order: i32 // BOOL
) -> u32;
}
// crates: windows-sys provides ready-made bindings for this API.$sig = @"
[DllImport("IPHLPAPI.dll")]
public static extern uint GetIpNetTable(IntPtr IpNetTable, ref uint SizePointer, bool Order);
"@
$api = Add-Type -MemberDefinition $sig -Name 'IPHLPAPI_GetIpNetTable' -Namespace Win32 -PassThru
# $api::GetIpNetTable(IpNetTable, SizePointer, Order)#uselib "IPHLPAPI.dll"
#func global GetIpNetTable "GetIpNetTable" sptr, sptr, sptr
; GetIpNetTable varptr(IpNetTable), varptr(SizePointer), Order ; 戻り値は stat
; IpNetTable : MIB_IPNETTABLE* optional, out -> "sptr"
; SizePointer : DWORD* in/out -> "sptr"
; Order : BOOL -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。#uselib "IPHLPAPI.dll" #cfunc global GetIpNetTable "GetIpNetTable" var, var, int ; res = GetIpNetTable(IpNetTable, SizePointer, Order) ; IpNetTable : MIB_IPNETTABLE* optional, out -> "var" ; SizePointer : DWORD* in/out -> "var" ; Order : BOOL -> "int" ; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。#uselib "IPHLPAPI.dll" #cfunc global GetIpNetTable "GetIpNetTable" sptr, sptr, int ; res = GetIpNetTable(varptr(IpNetTable), varptr(SizePointer), Order) ; IpNetTable : MIB_IPNETTABLE* optional, out -> "sptr" ; SizePointer : DWORD* in/out -> "sptr" ; Order : BOOL -> "int" ; ※出力/バッファ引数はポインタ方式(token=sptr / 呼び出しは varptr(変数))。
; DWORD GetIpNetTable(MIB_IPNETTABLE* IpNetTable, DWORD* SizePointer, BOOL Order) #uselib "IPHLPAPI.dll" #cfunc global GetIpNetTable "GetIpNetTable" var, var, int ; res = GetIpNetTable(IpNetTable, SizePointer, Order) ; IpNetTable : MIB_IPNETTABLE* optional, out -> "var" ; SizePointer : DWORD* in/out -> "var" ; Order : BOOL -> "int" ; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。; DWORD GetIpNetTable(MIB_IPNETTABLE* IpNetTable, DWORD* SizePointer, BOOL Order) #uselib "IPHLPAPI.dll" #cfunc global GetIpNetTable "GetIpNetTable" intptr, intptr, int ; res = GetIpNetTable(varptr(IpNetTable), varptr(SizePointer), Order) ; IpNetTable : MIB_IPNETTABLE* optional, out -> "intptr" ; SizePointer : DWORD* in/out -> "intptr" ; Order : BOOL -> "int" ; ※出力/バッファ引数はポインタ方式(token=intptr / 呼び出しは varptr(変数))。
import (
"golang.org/x/sys/windows"
"unsafe"
)
var (
iphlpapi = windows.NewLazySystemDLL("IPHLPAPI.dll")
procGetIpNetTable = iphlpapi.NewProc("GetIpNetTable")
)
// IpNetTable (MIB_IPNETTABLE* optional, out), SizePointer (DWORD* in/out), Order (BOOL)
r1, _, err := procGetIpNetTable.Call(
uintptr(IpNetTable),
uintptr(SizePointer),
uintptr(Order),
)
_ = err // syscall.Errno (valid when the call sets last-error)
_ = r1 // DWORDfunction GetIpNetTable(
IpNetTable: Pointer; // MIB_IPNETTABLE* optional, out
SizePointer: Pointer; // DWORD* in/out
Order: BOOL // BOOL
): DWORD; stdcall;
external 'IPHLPAPI.dll' name 'GetIpNetTable';result := DllCall("IPHLPAPI\GetIpNetTable"
, "Ptr", IpNetTable ; MIB_IPNETTABLE* optional, out
, "Ptr", SizePointer ; DWORD* in/out
, "Int", Order ; BOOL
, "UInt") ; return: DWORD●GetIpNetTable(IpNetTable, SizePointer, Order) = DLL("IPHLPAPI.dll", "dword GetIpNetTable(void*, void*, bool)")
# 呼び出し: GetIpNetTable(IpNetTable, SizePointer, Order)
# IpNetTable : MIB_IPNETTABLE* optional, out -> "void*"
# SizePointer : DWORD* in/out -> "void*"
# Order : BOOL -> "bool"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。const std = @import("std");
extern "iphlpapi" fn GetIpNetTable(
IpNetTable: [*c]MIB_IPNETTABLE, // MIB_IPNETTABLE* optional, out
SizePointer: [*c]u32, // DWORD* in/out
Order: i32 // BOOL
) callconv(std.os.windows.WINAPI) u32;proc GetIpNetTable(
IpNetTable: ptr MIB_IPNETTABLE, # MIB_IPNETTABLE* optional, out
SizePointer: ptr uint32, # DWORD* in/out
Order: int32 # BOOL
): uint32 {.importc: "GetIpNetTable", stdcall, dynlib: "IPHLPAPI.dll".}pragma(lib, "iphlpapi");
extern(Windows)
uint GetIpNetTable(
MIB_IPNETTABLE* IpNetTable, // MIB_IPNETTABLE* optional, out
uint* SizePointer, // DWORD* in/out
int Order // BOOL
);ccall((:GetIpNetTable, "IPHLPAPI.dll"), stdcall, UInt32,
(Ptr{MIB_IPNETTABLE}, Ptr{UInt32}, Int32),
IpNetTable, SizePointer, Order)
# IpNetTable : MIB_IPNETTABLE* optional, out -> Ptr{MIB_IPNETTABLE}
# SizePointer : DWORD* in/out -> Ptr{UInt32}
# Order : BOOL -> Int32
# stdcall は 32bit のみ意味を持つ(x64 では無視)。local ffi = require("ffi")
ffi.cdef[[
uint32_t GetIpNetTable(
void* IpNetTable,
uint32_t* SizePointer,
int32_t Order);
]]
local iphlpapi = ffi.load("iphlpapi")
-- iphlpapi.GetIpNetTable(IpNetTable, SizePointer, Order)
-- IpNetTable : MIB_IPNETTABLE* optional, out
-- SizePointer : DWORD* in/out
-- Order : BOOL
-- 構造体/GUIDへのポインタは cdef が通るよう void* で表記(実型は各引数コメント参照)。値渡し構造体・enum は対応する typedef を cdef に追加すること。const koffi = require('koffi');
const lib = koffi.load('IPHLPAPI.dll');
const GetIpNetTable = lib.func('__stdcall', 'GetIpNetTable', 'uint32_t', ['void *', 'uint32_t *', 'int32_t']);
// GetIpNetTable(IpNetTable, SizePointer, Order)
// IpNetTable : MIB_IPNETTABLE* optional, out -> 'void *'
// SizePointer : DWORD* in/out -> 'uint32_t *'
// Order : BOOL -> 'int32_t'
// 出力ポインタは koffi.out(...) で包む。構造体は koffi.struct で定義。const lib = Deno.dlopen("IPHLPAPI.dll", {
GetIpNetTable: { parameters: ["pointer", "pointer", "i32"], result: "u32" },
});
// lib.symbols.GetIpNetTable(IpNetTable, SizePointer, Order)
// IpNetTable : MIB_IPNETTABLE* optional, out -> "pointer"
// SizePointer : DWORD* in/out -> "pointer"
// Order : BOOL -> "i32"
// 文字列引数は "buffer"(NUL 終端のバイト列を Uint8Array で渡す)。
// 値渡し構造体は { struct: [ ...field types... ] } を使用。<?php
$ffi = FFI::cdef(<<<C
uint32_t GetIpNetTable(
void* IpNetTable,
uint32_t* SizePointer,
int32_t Order);
C, "IPHLPAPI.dll");
// $ffi->GetIpNetTable(IpNetTable, SizePointer, Order);
// IpNetTable : MIB_IPNETTABLE* optional, out
// SizePointer : DWORD* in/out
// Order : BOOL
// 構造体/GUIDへのポインタは cdef が通るよう void* で表記(実型は各引数コメント参照)。値渡し構造体・enum は対応する typedef を cdef に追加すること。
// WINAPI(stdcall): x64 では呼出規約が統一されるため問題なし。x86 では __stdcall 対応のラッパが必要な場合あり。import com.sun.jna.*;
import com.sun.jna.ptr.*;
import com.sun.jna.win32.StdCallLibrary;
import com.sun.jna.win32.W32APIOptions;
public interface Iphlpapi extends StdCallLibrary {
Iphlpapi INSTANCE = Native.load("iphlpapi", Iphlpapi.class);
int GetIpNetTable(
Pointer IpNetTable, // MIB_IPNETTABLE* optional, out
IntByReference SizePointer, // DWORD* in/out
boolean Order // BOOL
);
}@[Link("iphlpapi")]
lib LibIPHLPAPI
fun GetIpNetTable = GetIpNetTable(
IpNetTable : MIB_IPNETTABLE*, # MIB_IPNETTABLE* optional, out
SizePointer : UInt32*, # DWORD* in/out
Order : Int32 # BOOL
) : UInt32
end
# 構造体/GUID/enum は lib 内に対応する型定義が必要。
# 呼出規約: x64 は規約統一のため OK。x86(32bit)は WINAPI=stdcall だが Crystal の fun に stdcall 付与構文がなく非対応。import 'dart:ffi';
import 'package:ffi/ffi.dart';
typedef GetIpNetTableNative = Uint32 Function(Pointer<Void>, Pointer<Uint32>, Int32);
typedef GetIpNetTableDart = int Function(Pointer<Void>, Pointer<Uint32>, int);
final GetIpNetTable = DynamicLibrary.open('IPHLPAPI.dll')
.lookupFunction<GetIpNetTableNative, GetIpNetTableDart>('GetIpNetTable');
// IpNetTable : MIB_IPNETTABLE* optional, out -> Pointer<Void>
// SizePointer : DWORD* in/out -> Pointer<Uint32>
// Order : BOOL -> Int32
// 文字列は package:ffi の "...".toNativeUtf16()/toNativeUtf8() で変換。{$mode objfpc}{$H+}
function GetIpNetTable(
IpNetTable: Pointer; // MIB_IPNETTABLE* optional, out
SizePointer: Pointer; // DWORD* in/out
Order: BOOL // BOOL
): DWORD; stdcall;
external 'IPHLPAPI.dll' name 'GetIpNetTable';import Foreign
import Foreign.C.Types
import Foreign.C.String
foreign import stdcall safe "GetIpNetTable"
c_GetIpNetTable :: Ptr () -> Ptr Word32 -> CInt -> IO Word32
-- IpNetTable : MIB_IPNETTABLE* optional, out -> Ptr ()
-- SizePointer : DWORD* in/out -> Ptr Word32
-- Order : BOOL -> CInt
-- 要 GHC(Windows)。stdcall は x64 では ccall として扱われる。ブロックする API は safe 呼び出し推奨。open Ctypes
open Foreign
let getipnettable =
foreign "GetIpNetTable"
((ptr void) @-> (ptr uint32_t) @-> int32_t @-> returning uint32_t)
(* IpNetTable : MIB_IPNETTABLE* optional, out -> (ptr void) *)
(* SizePointer : DWORD* in/out -> (ptr uint32_t) *)
(* Order : BOOL -> int32_t *)
(* foreign は cdecl 前提。x64 Windows では WINAPI と一致。構造体は ctypes structure を定義のこと。 *)(cffi:define-foreign-library iphlpapi (t "IPHLPAPI.dll"))
(cffi:use-foreign-library iphlpapi)
(cffi:defcfun ("GetIpNetTable" get-ip-net-table :convention :stdcall) :uint32
(ip-net-table :pointer) ; MIB_IPNETTABLE* optional, out
(size-pointer :pointer) ; DWORD* in/out
(order :int32)) ; BOOL
; isize/usize(INT_PTR/SIZE_T)は x64 前提で :int64/:uint64。x86 では :int32/:uint32。use Win32::API;
my $GetIpNetTable = Win32::API::More->new('IPHLPAPI',
'DWORD GetIpNetTable(LPVOID IpNetTable, LPVOID SizePointer, BOOL Order)');
# my $ret = $GetIpNetTable->Call($IpNetTable, $SizePointer, $Order);
# IpNetTable : MIB_IPNETTABLE* optional, out -> LPVOID
# SizePointer : DWORD* in/out -> LPVOID
# Order : BOOL -> BOOL
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。関連項目
- f GetIpNetTable2 — 指定アドレスファミリの近隣(ARP/NDP)テーブルを取得する。
- f CreateIpNetEntry — ARPテーブルに新しいIPアドレスと物理アドレスの対応を追加する。
- f DeleteIpNetEntry — ARPテーブルから指定エントリを削除する。
- f FlushIpNetTable — 指定インターフェイスのARPテーブルをすべて消去する。
- s MIB_IPNETROW_LH
- f SetIpNetEntry — ARPテーブルの既存エントリを変更する。