MIB_IPADDRTABLE
構造体サイズ=各フィールドのバイト数(x64/x86 で異なる場合は x64/x86 と併記)。x64/x86 列=フィールドのバイトオフセット(HSPで dupptr / lpoke / wpoke 等に使用)。
フィールド
| フィールド | 型 | サイズ | x64 | x86 | 説明 |
|---|---|---|---|---|---|
| dwNumEntries | DWORD | 4 | +0 | +0 | テーブル内の IPv4 アドレスエントリの数。 |
| table | MIB_IPADDRROW_XP | 24 | +4 | +4 | MIB_IPADDRROW 構造体の配列として実装された、IPv4 アドレスエントリのテーブルへのポインター。 |
公式ドキュメント
MIB_IPADDRTABLE 構造体は、IPv4 アドレスエントリのテーブルを格納します。
解説(Remarks)
GetIpAddrTable 関数は、ローカルコンピューター上のインターフェイスと IPv4 アドレスの対応テーブルを取得し、その情報を MIB_IPADDRTABLE 構造体で返します。
MIB_IPADDRTABLE 構造体には、dwNumEntries メンバーと table メンバー内の最初の MIB_IPADDRROW 配列エントリとの間に、アライメントのためのパディングが含まれる場合があります。また、table メンバー内の MIB_IPADDRROW 配列エントリ同士の間にもアライメントのためのパディングが存在する場合があります。MIB_IPADDRROW 配列エントリにアクセスする際は、パディングが存在する可能性を想定してください。
Windows Vista 以降向けにリリースされた Microsoft Windows Software Development Kit (SDK) ではヘッダーファイルの構成が変更されており、MIB_IPADDRROW は Iprtrmib.h ヘッダーファイルではなく Ipmib.h ヘッダーファイルで定義されています。Ipmib.h ヘッダーファイルは Iprtrmib.h に自動的にインクルードされ、Iprtrmib.h は Iphlpapi.h ヘッダーファイルに自動的にインクルードされることに注意してください。Ipmib.h および Iprtrmib.h ヘッダーファイルを直接使用しないでください。
例
MIB_IPADDRTABLE 構造体を取得し、このテーブル内の MIB_IPADDRROW 構造体を出力する例については、GetIpAddrTable 関数を参照してください。
Microsoft 公式リファレンス: 英語 (en-us) · 日本語 (ja-jp) · 原文ソース (GitHub)
各言語での定義
#include <windows.h>
// MIB_IPADDRROW_XP (x64 24 / x86 24 バイト)
typedef struct MIB_IPADDRROW_XP {
DWORD dwAddr;
DWORD dwIndex;
DWORD dwMask;
DWORD dwBCastAddr;
DWORD dwReasmSize;
WORD unused1;
WORD wType;
} MIB_IPADDRROW_XP;
// MIB_IPADDRTABLE (x64 28 / x86 28 バイト)
typedef struct MIB_IPADDRTABLE {
DWORD dwNumEntries;
MIB_IPADDRROW_XP table[1];
} MIB_IPADDRTABLE;using System;
using System.Runtime.InteropServices;
[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Unicode)]
public struct MIB_IPADDRROW_XP
{
public uint dwAddr;
public uint dwIndex;
public uint dwMask;
public uint dwBCastAddr;
public uint dwReasmSize;
public ushort unused1;
public ushort wType;
}
[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Unicode)]
public struct MIB_IPADDRTABLE
{
public uint dwNumEntries;
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 1)] public MIB_IPADDRROW_XP[] table;
}Imports System.Runtime.InteropServices
<StructLayout(LayoutKind.Sequential, CharSet:=CharSet.Unicode)>
Public Structure MIB_IPADDRROW_XP
Public dwAddr As UInteger
Public dwIndex As UInteger
Public dwMask As UInteger
Public dwBCastAddr As UInteger
Public dwReasmSize As UInteger
Public unused1 As UShort
Public wType As UShort
End Structure
<StructLayout(LayoutKind.Sequential, CharSet:=CharSet.Unicode)>
Public Structure MIB_IPADDRTABLE
Public dwNumEntries As UInteger
<MarshalAs(UnmanagedType.ByValArray, SizeConst:=1)> Public table() As MIB_IPADDRROW_XP
End Structureimport ctypes
from ctypes import wintypes
class MIB_IPADDRROW_XP(ctypes.Structure):
_fields_ = [
("dwAddr", wintypes.DWORD),
("dwIndex", wintypes.DWORD),
("dwMask", wintypes.DWORD),
("dwBCastAddr", wintypes.DWORD),
("dwReasmSize", wintypes.DWORD),
("unused1", ctypes.c_ushort),
("wType", ctypes.c_ushort),
]
class MIB_IPADDRTABLE(ctypes.Structure):
_fields_ = [
("dwNumEntries", wintypes.DWORD),
("table", MIB_IPADDRROW_XP * 1),
]#[repr(C)]
pub struct MIB_IPADDRROW_XP {
pub dwAddr: u32,
pub dwIndex: u32,
pub dwMask: u32,
pub dwBCastAddr: u32,
pub dwReasmSize: u32,
pub unused1: u16,
pub wType: u16,
}
#[repr(C)]
pub struct MIB_IPADDRTABLE {
pub dwNumEntries: u32,
pub table: [MIB_IPADDRROW_XP; 1],
}import "golang.org/x/sys/windows"
type MIB_IPADDRROW_XP struct {
dwAddr uint32
dwIndex uint32
dwMask uint32
dwBCastAddr uint32
dwReasmSize uint32
unused1 uint16
wType uint16
}
type MIB_IPADDRTABLE struct {
dwNumEntries uint32
table [1]MIB_IPADDRROW_XP
}type
MIB_IPADDRROW_XP = record
dwAddr: DWORD;
dwIndex: DWORD;
dwMask: DWORD;
dwBCastAddr: DWORD;
dwReasmSize: DWORD;
unused1: Word;
wType: Word;
end;
MIB_IPADDRTABLE = record
dwNumEntries: DWORD;
table: array[0..0] of MIB_IPADDRROW_XP;
end;const MIB_IPADDRROW_XP = extern struct {
dwAddr: u32,
dwIndex: u32,
dwMask: u32,
dwBCastAddr: u32,
dwReasmSize: u32,
unused1: u16,
wType: u16,
};
const MIB_IPADDRTABLE = extern struct {
dwNumEntries: u32,
table: [1]MIB_IPADDRROW_XP,
};type
MIB_IPADDRROW_XP {.bycopy.} = object
dwAddr: uint32
dwIndex: uint32
dwMask: uint32
dwBCastAddr: uint32
dwReasmSize: uint32
unused1: uint16
wType: uint16
MIB_IPADDRTABLE {.bycopy.} = object
dwNumEntries: uint32
table: array[1, MIB_IPADDRROW_XP]struct MIB_IPADDRROW_XP
{
uint dwAddr;
uint dwIndex;
uint dwMask;
uint dwBCastAddr;
uint dwReasmSize;
ushort unused1;
ushort wType;
}
struct MIB_IPADDRTABLE
{
uint dwNumEntries;
MIB_IPADDRROW_XP[1] table;
}HSP用 定義
HSP3.7/3.8 は構造体機能が無いため4byte整数配列(dim)+peek/poke で操作(32/64bitでサイズ・位置が異なる場合はタブで分割)。IronHSP は NSTRUCT(#defstruct/stdim/->)で32/64bit共通。
; HSP3.7/3.8 は構造体機能が無いため、4byte整数の配列変数で操作します。(x64 レイアウト)
; MIB_IPADDRTABLE サイズ: 28 バイト(x64)
dim st, 7 ; 4byte整数×7(構造体サイズ 28 / 4 切り上げ)
; dwNumEntries : DWORD (+0, 4byte) st.0 = 値 / 値 = st.0 (lpoke/lpeek も可)
; table : MIB_IPADDRROW_XP (+4, 24byte) varptr(st)+4 を基点に操作(24byte:入れ子/配列)
; ※4byte境界の整数は添字 st.N(N=オフセット/4)で読み書き可。それ以外は peek/poke 系を使用。; IronHSP は NSTRUCT(構造体)をサポート。32bit/64bit どちらでも同じコードで動作します。
; ※GUID・入れ子構造体はデフォルト型でないため、依存する #defstruct を先に定義(下記に同梱)。
#defstruct global MIB_IPADDRROW_XP
#field int dwAddr
#field int dwIndex
#field int dwMask
#field int dwBCastAddr
#field int dwReasmSize
#field short unused1
#field short wType
#endstruct
#defstruct global MIB_IPADDRTABLE
#field int dwNumEntries
#field MIB_IPADDRROW_XP table 1
#endstruct
stdim st, MIB_IPADDRTABLE ; NSTRUCT 変数を確保
st->dwNumEntries = 100
mes "dwNumEntries=" + st->dwNumEntries