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

MIB_TCP6TABLE2

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

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

フィールド

フィールドサイズx64x86説明
dwNumEntriesDWORD4+0+0table配列に格納されたIPv6 TCP接続行数を示す。
tableMIB_TCP6ROW260+4+4MIB_TCP6ROW2要素を格納する可変長配列の先頭。

各言語での定義

#include <windows.h>

// IN6_ADDR  (x64 16 / x86 16 バイト)
typedef struct IN6_ADDR {
    _u_e__Union u;
} IN6_ADDR;

// MIB_TCP6ROW2  (x64 60 / x86 60 バイト)
typedef struct MIB_TCP6ROW2 {
    IN6_ADDR LocalAddr;
    DWORD dwLocalScopeId;
    DWORD dwLocalPort;
    IN6_ADDR RemoteAddr;
    DWORD dwRemoteScopeId;
    DWORD dwRemotePort;
    MIB_TCP_STATE State;
    DWORD dwOwningPid;
    TCP_CONNECTION_OFFLOAD_STATE dwOffloadState;
} MIB_TCP6ROW2;

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

[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Unicode)]
public struct IN6_ADDR
{
    public _u_e__Union u;
}

[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Unicode)]
public struct MIB_TCP6ROW2
{
    public IN6_ADDR LocalAddr;
    public uint dwLocalScopeId;
    public uint dwLocalPort;
    public IN6_ADDR RemoteAddr;
    public uint dwRemoteScopeId;
    public uint dwRemotePort;
    public int State;
    public uint dwOwningPid;
    public int dwOffloadState;
}

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

<StructLayout(LayoutKind.Sequential, CharSet:=CharSet.Unicode)>
Public Structure IN6_ADDR
    Public u As _u_e__Union
End Structure

<StructLayout(LayoutKind.Sequential, CharSet:=CharSet.Unicode)>
Public Structure MIB_TCP6ROW2
    Public LocalAddr As IN6_ADDR
    Public dwLocalScopeId As UInteger
    Public dwLocalPort As UInteger
    Public RemoteAddr As IN6_ADDR
    Public dwRemoteScopeId As UInteger
    Public dwRemotePort As UInteger
    Public State As Integer
    Public dwOwningPid As UInteger
    Public dwOffloadState As Integer
End Structure

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

class IN6_ADDR(ctypes.Structure):
    _fields_ = [
        ("u", _u_e__Union),
    ]

class MIB_TCP6ROW2(ctypes.Structure):
    _fields_ = [
        ("LocalAddr", IN6_ADDR),
        ("dwLocalScopeId", wintypes.DWORD),
        ("dwLocalPort", wintypes.DWORD),
        ("RemoteAddr", IN6_ADDR),
        ("dwRemoteScopeId", wintypes.DWORD),
        ("dwRemotePort", wintypes.DWORD),
        ("State", ctypes.c_int),
        ("dwOwningPid", wintypes.DWORD),
        ("dwOffloadState", ctypes.c_int),
    ]

class MIB_TCP6TABLE2(ctypes.Structure):
    _fields_ = [
        ("dwNumEntries", wintypes.DWORD),
        ("table", MIB_TCP6ROW2 * 1),
    ]
#[repr(C)]
pub struct IN6_ADDR {
    pub u: _u_e__Union,
}

#[repr(C)]
pub struct MIB_TCP6ROW2 {
    pub LocalAddr: IN6_ADDR,
    pub dwLocalScopeId: u32,
    pub dwLocalPort: u32,
    pub RemoteAddr: IN6_ADDR,
    pub dwRemoteScopeId: u32,
    pub dwRemotePort: u32,
    pub State: i32,
    pub dwOwningPid: u32,
    pub dwOffloadState: i32,
}

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

type IN6_ADDR struct {
	u _u_e__Union
}

type MIB_TCP6ROW2 struct {
	LocalAddr IN6_ADDR
	dwLocalScopeId uint32
	dwLocalPort uint32
	RemoteAddr IN6_ADDR
	dwRemoteScopeId uint32
	dwRemotePort uint32
	State int32
	dwOwningPid uint32
	dwOffloadState int32
}

type MIB_TCP6TABLE2 struct {
	dwNumEntries uint32
	table [1]MIB_TCP6ROW2
}
type
  IN6_ADDR = record
    u: _u_e__Union;
  end;

  MIB_TCP6ROW2 = record
    LocalAddr: IN6_ADDR;
    dwLocalScopeId: DWORD;
    dwLocalPort: DWORD;
    RemoteAddr: IN6_ADDR;
    dwRemoteScopeId: DWORD;
    dwRemotePort: DWORD;
    State: Integer;
    dwOwningPid: DWORD;
    dwOffloadState: Integer;
  end;

  MIB_TCP6TABLE2 = record
    dwNumEntries: DWORD;
    table: array[0..0] of MIB_TCP6ROW2;
  end;
const IN6_ADDR = extern struct {
    u: _u_e__Union,
};

const MIB_TCP6ROW2 = extern struct {
    LocalAddr: IN6_ADDR,
    dwLocalScopeId: u32,
    dwLocalPort: u32,
    RemoteAddr: IN6_ADDR,
    dwRemoteScopeId: u32,
    dwRemotePort: u32,
    State: i32,
    dwOwningPid: u32,
    dwOffloadState: i32,
};

const MIB_TCP6TABLE2 = extern struct {
    dwNumEntries: u32,
    table: [1]MIB_TCP6ROW2,
};
type
  IN6_ADDR {.bycopy.} = object
    u: _u_e__Union

  MIB_TCP6ROW2 {.bycopy.} = object
    LocalAddr: IN6_ADDR
    dwLocalScopeId: uint32
    dwLocalPort: uint32
    RemoteAddr: IN6_ADDR
    dwRemoteScopeId: uint32
    dwRemotePort: uint32
    State: int32
    dwOwningPid: uint32
    dwOffloadState: int32

  MIB_TCP6TABLE2 {.bycopy.} = object
    dwNumEntries: uint32
    table: array[1, MIB_TCP6ROW2]
struct IN6_ADDR
{
    _u_e__Union u;
}

struct MIB_TCP6ROW2
{
    IN6_ADDR LocalAddr;
    uint dwLocalScopeId;
    uint dwLocalPort;
    IN6_ADDR RemoteAddr;
    uint dwRemoteScopeId;
    uint dwRemotePort;
    int State;
    uint dwOwningPid;
    int dwOffloadState;
}

struct MIB_TCP6TABLE2
{
    uint dwNumEntries;
    MIB_TCP6ROW2[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_TCP6TABLE2 サイズ: 64 バイト(x64)
dim st, 16    ; 4byte整数×16(構造体サイズ 64 / 4 切り上げ)
; dwNumEntries : DWORD (+0, 4byte)  st.0 = 値  /  値 = st.0   (lpoke/lpeek も可)
; table : MIB_TCP6ROW2 (+4, 60byte)  varptr(st)+4 を基点に操作(60byte:入れ子/配列)
; ※4byte境界の整数は添字 st.N(N=オフセット/4)で読み書き可。それ以外は peek/poke 系を使用。
; IronHSP は NSTRUCT(構造体)をサポート。32bit/64bit どちらでも同じコードで動作します。
; ※GUID・入れ子構造体はデフォルト型でないため、依存する #defstruct を先に定義(下記に同梱)。
#defstruct global IN6_ADDR
    #field byte u 16
#endstruct

#defstruct global MIB_TCP6ROW2
    #field IN6_ADDR LocalAddr
    #field int dwLocalScopeId
    #field int dwLocalPort
    #field IN6_ADDR RemoteAddr
    #field int dwRemoteScopeId
    #field int dwRemotePort
    #field int State
    #field int dwOwningPid
    #field int dwOffloadState
#endstruct

#defstruct global MIB_TCP6TABLE2
    #field int dwNumEntries
    #field MIB_TCP6ROW2 table 1
#endstruct

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