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

MIB_IFTABLE

構造体
サイズx64: 864 バイト / x86: 864 バイト

サイズ=各フィールドのバイト数(x64/x86 で異なる場合は x64/x86 と併記)。x64/x86 列=フィールドのバイトオフセット(HSPで dupptr / lpoke / wpoke 等に使用)。

フィールド

フィールドサイズx64x86説明
dwNumEntriesDWORD4+0+0table配列に格納されたインターフェース行数を示す。
tableMIB_IFROW860+4+4MIB_IFROW要素を格納する可変長配列の先頭。

各言語での定義

#include <windows.h>

// MIB_IFROW  (x64 860 / x86 860 バイト)
typedef struct MIB_IFROW {
    WCHAR wszName[256];
    DWORD dwIndex;
    DWORD dwType;
    DWORD dwMtu;
    DWORD dwSpeed;
    DWORD dwPhysAddrLen;
    BYTE bPhysAddr[8];
    DWORD dwAdminStatus;
    INTERNAL_IF_OPER_STATUS dwOperStatus;
    DWORD dwLastChange;
    DWORD dwInOctets;
    DWORD dwInUcastPkts;
    DWORD dwInNUcastPkts;
    DWORD dwInDiscards;
    DWORD dwInErrors;
    DWORD dwInUnknownProtos;
    DWORD dwOutOctets;
    DWORD dwOutUcastPkts;
    DWORD dwOutNUcastPkts;
    DWORD dwOutDiscards;
    DWORD dwOutErrors;
    DWORD dwOutQLen;
    DWORD dwDescrLen;
    BYTE bDescr[256];
} MIB_IFROW;

// MIB_IFTABLE  (x64 864 / x86 864 バイト)
typedef struct MIB_IFTABLE {
    DWORD dwNumEntries;
    MIB_IFROW table[1];
} MIB_IFTABLE;
using System;
using System.Runtime.InteropServices;

[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Unicode)]
public struct MIB_IFROW
{
    [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 256)] public string wszName;
    public uint dwIndex;
    public uint dwType;
    public uint dwMtu;
    public uint dwSpeed;
    public uint dwPhysAddrLen;
    [MarshalAs(UnmanagedType.ByValArray, SizeConst = 8)] public byte[] bPhysAddr;
    public uint dwAdminStatus;
    public int dwOperStatus;
    public uint dwLastChange;
    public uint dwInOctets;
    public uint dwInUcastPkts;
    public uint dwInNUcastPkts;
    public uint dwInDiscards;
    public uint dwInErrors;
    public uint dwInUnknownProtos;
    public uint dwOutOctets;
    public uint dwOutUcastPkts;
    public uint dwOutNUcastPkts;
    public uint dwOutDiscards;
    public uint dwOutErrors;
    public uint dwOutQLen;
    public uint dwDescrLen;
    [MarshalAs(UnmanagedType.ByValArray, SizeConst = 256)] public byte[] bDescr;
}

[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Unicode)]
public struct MIB_IFTABLE
{
    public uint dwNumEntries;
    [MarshalAs(UnmanagedType.ByValArray, SizeConst = 1)] public MIB_IFROW[] table;
}
Imports System.Runtime.InteropServices

<StructLayout(LayoutKind.Sequential, CharSet:=CharSet.Unicode)>
Public Structure MIB_IFROW
    <MarshalAs(UnmanagedType.ByValTStr, SizeConst:=256)> Public wszName As String
    Public dwIndex As UInteger
    Public dwType As UInteger
    Public dwMtu As UInteger
    Public dwSpeed As UInteger
    Public dwPhysAddrLen As UInteger
    <MarshalAs(UnmanagedType.ByValArray, SizeConst:=8)> Public bPhysAddr() As Byte
    Public dwAdminStatus As UInteger
    Public dwOperStatus As Integer
    Public dwLastChange As UInteger
    Public dwInOctets As UInteger
    Public dwInUcastPkts As UInteger
    Public dwInNUcastPkts As UInteger
    Public dwInDiscards As UInteger
    Public dwInErrors As UInteger
    Public dwInUnknownProtos As UInteger
    Public dwOutOctets As UInteger
    Public dwOutUcastPkts As UInteger
    Public dwOutNUcastPkts As UInteger
    Public dwOutDiscards As UInteger
    Public dwOutErrors As UInteger
    Public dwOutQLen As UInteger
    Public dwDescrLen As UInteger
    <MarshalAs(UnmanagedType.ByValArray, SizeConst:=256)> Public bDescr() As Byte
End Structure

<StructLayout(LayoutKind.Sequential, CharSet:=CharSet.Unicode)>
Public Structure MIB_IFTABLE
    Public dwNumEntries As UInteger
    <MarshalAs(UnmanagedType.ByValArray, SizeConst:=1)> Public table() As MIB_IFROW
End Structure
import ctypes
from ctypes import wintypes

class MIB_IFROW(ctypes.Structure):
    _fields_ = [
        ("wszName", ctypes.c_wchar * 256),
        ("dwIndex", wintypes.DWORD),
        ("dwType", wintypes.DWORD),
        ("dwMtu", wintypes.DWORD),
        ("dwSpeed", wintypes.DWORD),
        ("dwPhysAddrLen", wintypes.DWORD),
        ("bPhysAddr", ctypes.c_ubyte * 8),
        ("dwAdminStatus", wintypes.DWORD),
        ("dwOperStatus", ctypes.c_int),
        ("dwLastChange", wintypes.DWORD),
        ("dwInOctets", wintypes.DWORD),
        ("dwInUcastPkts", wintypes.DWORD),
        ("dwInNUcastPkts", wintypes.DWORD),
        ("dwInDiscards", wintypes.DWORD),
        ("dwInErrors", wintypes.DWORD),
        ("dwInUnknownProtos", wintypes.DWORD),
        ("dwOutOctets", wintypes.DWORD),
        ("dwOutUcastPkts", wintypes.DWORD),
        ("dwOutNUcastPkts", wintypes.DWORD),
        ("dwOutDiscards", wintypes.DWORD),
        ("dwOutErrors", wintypes.DWORD),
        ("dwOutQLen", wintypes.DWORD),
        ("dwDescrLen", wintypes.DWORD),
        ("bDescr", ctypes.c_ubyte * 256),
    ]

class MIB_IFTABLE(ctypes.Structure):
    _fields_ = [
        ("dwNumEntries", wintypes.DWORD),
        ("table", MIB_IFROW * 1),
    ]
#[repr(C)]
pub struct MIB_IFROW {
    pub wszName: [u16; 256],
    pub dwIndex: u32,
    pub dwType: u32,
    pub dwMtu: u32,
    pub dwSpeed: u32,
    pub dwPhysAddrLen: u32,
    pub bPhysAddr: [u8; 8],
    pub dwAdminStatus: u32,
    pub dwOperStatus: i32,
    pub dwLastChange: u32,
    pub dwInOctets: u32,
    pub dwInUcastPkts: u32,
    pub dwInNUcastPkts: u32,
    pub dwInDiscards: u32,
    pub dwInErrors: u32,
    pub dwInUnknownProtos: u32,
    pub dwOutOctets: u32,
    pub dwOutUcastPkts: u32,
    pub dwOutNUcastPkts: u32,
    pub dwOutDiscards: u32,
    pub dwOutErrors: u32,
    pub dwOutQLen: u32,
    pub dwDescrLen: u32,
    pub bDescr: [u8; 256],
}

#[repr(C)]
pub struct MIB_IFTABLE {
    pub dwNumEntries: u32,
    pub table: [MIB_IFROW; 1],
}
import "golang.org/x/sys/windows"

type MIB_IFROW struct {
	wszName [256]uint16
	dwIndex uint32
	dwType uint32
	dwMtu uint32
	dwSpeed uint32
	dwPhysAddrLen uint32
	bPhysAddr [8]byte
	dwAdminStatus uint32
	dwOperStatus int32
	dwLastChange uint32
	dwInOctets uint32
	dwInUcastPkts uint32
	dwInNUcastPkts uint32
	dwInDiscards uint32
	dwInErrors uint32
	dwInUnknownProtos uint32
	dwOutOctets uint32
	dwOutUcastPkts uint32
	dwOutNUcastPkts uint32
	dwOutDiscards uint32
	dwOutErrors uint32
	dwOutQLen uint32
	dwDescrLen uint32
	bDescr [256]byte
}

type MIB_IFTABLE struct {
	dwNumEntries uint32
	table [1]MIB_IFROW
}
type
  MIB_IFROW = record
    wszName: array[0..255] of WideChar;
    dwIndex: DWORD;
    dwType: DWORD;
    dwMtu: DWORD;
    dwSpeed: DWORD;
    dwPhysAddrLen: DWORD;
    bPhysAddr: array[0..7] of Byte;
    dwAdminStatus: DWORD;
    dwOperStatus: Integer;
    dwLastChange: DWORD;
    dwInOctets: DWORD;
    dwInUcastPkts: DWORD;
    dwInNUcastPkts: DWORD;
    dwInDiscards: DWORD;
    dwInErrors: DWORD;
    dwInUnknownProtos: DWORD;
    dwOutOctets: DWORD;
    dwOutUcastPkts: DWORD;
    dwOutNUcastPkts: DWORD;
    dwOutDiscards: DWORD;
    dwOutErrors: DWORD;
    dwOutQLen: DWORD;
    dwDescrLen: DWORD;
    bDescr: array[0..255] of Byte;
  end;

  MIB_IFTABLE = record
    dwNumEntries: DWORD;
    table: array[0..0] of MIB_IFROW;
  end;
const MIB_IFROW = extern struct {
    wszName: [256]u16,
    dwIndex: u32,
    dwType: u32,
    dwMtu: u32,
    dwSpeed: u32,
    dwPhysAddrLen: u32,
    bPhysAddr: [8]u8,
    dwAdminStatus: u32,
    dwOperStatus: i32,
    dwLastChange: u32,
    dwInOctets: u32,
    dwInUcastPkts: u32,
    dwInNUcastPkts: u32,
    dwInDiscards: u32,
    dwInErrors: u32,
    dwInUnknownProtos: u32,
    dwOutOctets: u32,
    dwOutUcastPkts: u32,
    dwOutNUcastPkts: u32,
    dwOutDiscards: u32,
    dwOutErrors: u32,
    dwOutQLen: u32,
    dwDescrLen: u32,
    bDescr: [256]u8,
};

const MIB_IFTABLE = extern struct {
    dwNumEntries: u32,
    table: [1]MIB_IFROW,
};
type
  MIB_IFROW {.bycopy.} = object
    wszName: array[256, uint16]
    dwIndex: uint32
    dwType: uint32
    dwMtu: uint32
    dwSpeed: uint32
    dwPhysAddrLen: uint32
    bPhysAddr: array[8, uint8]
    dwAdminStatus: uint32
    dwOperStatus: int32
    dwLastChange: uint32
    dwInOctets: uint32
    dwInUcastPkts: uint32
    dwInNUcastPkts: uint32
    dwInDiscards: uint32
    dwInErrors: uint32
    dwInUnknownProtos: uint32
    dwOutOctets: uint32
    dwOutUcastPkts: uint32
    dwOutNUcastPkts: uint32
    dwOutDiscards: uint32
    dwOutErrors: uint32
    dwOutQLen: uint32
    dwDescrLen: uint32
    bDescr: array[256, uint8]

  MIB_IFTABLE {.bycopy.} = object
    dwNumEntries: uint32
    table: array[1, MIB_IFROW]
struct MIB_IFROW
{
    wchar[256] wszName;
    uint dwIndex;
    uint dwType;
    uint dwMtu;
    uint dwSpeed;
    uint dwPhysAddrLen;
    ubyte[8] bPhysAddr;
    uint dwAdminStatus;
    int dwOperStatus;
    uint dwLastChange;
    uint dwInOctets;
    uint dwInUcastPkts;
    uint dwInNUcastPkts;
    uint dwInDiscards;
    uint dwInErrors;
    uint dwInUnknownProtos;
    uint dwOutOctets;
    uint dwOutUcastPkts;
    uint dwOutNUcastPkts;
    uint dwOutDiscards;
    uint dwOutErrors;
    uint dwOutQLen;
    uint dwDescrLen;
    ubyte[256] bDescr;
}

struct MIB_IFTABLE
{
    uint dwNumEntries;
    MIB_IFROW[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_IFTABLE サイズ: 864 バイト(x64)
dim st, 216    ; 4byte整数×216(構造体サイズ 864 / 4 切り上げ)
; dwNumEntries : DWORD (+0, 4byte)  st.0 = 値  /  値 = st.0   (lpoke/lpeek も可)
; table : MIB_IFROW (+4, 860byte)  varptr(st)+4 を基点に操作(860byte:入れ子/配列)
; ※4byte境界の整数は添字 st.N(N=オフセット/4)で読み書き可。それ以外は peek/poke 系を使用。
; IronHSP は NSTRUCT(構造体)をサポート。32bit/64bit どちらでも同じコードで動作します。
; ※GUID・入れ子構造体はデフォルト型でないため、依存する #defstruct を先に定義(下記に同梱)。
#defstruct global MIB_IFROW
    #field wchar wszName 256
    #field int dwIndex
    #field int dwType
    #field int dwMtu
    #field int dwSpeed
    #field int dwPhysAddrLen
    #field byte bPhysAddr 8
    #field int dwAdminStatus
    #field int dwOperStatus
    #field int dwLastChange
    #field int dwInOctets
    #field int dwInUcastPkts
    #field int dwInNUcastPkts
    #field int dwInDiscards
    #field int dwInErrors
    #field int dwInUnknownProtos
    #field int dwOutOctets
    #field int dwOutUcastPkts
    #field int dwOutNUcastPkts
    #field int dwOutDiscards
    #field int dwOutErrors
    #field int dwOutQLen
    #field int dwDescrLen
    #field byte bDescr 256
#endstruct

#defstruct global MIB_IFTABLE
    #field int dwNumEntries
    #field MIB_IFROW table 1
#endstruct

stdim st, MIB_IFTABLE        ; NSTRUCT 変数を確保
st->dwNumEntries = 100
mes "dwNumEntries=" + st->dwNumEntries