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

MIB_UDP6TABLE2

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

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

フィールド

フィールドサイズx64x86説明
dwNumEntriesDWORD4+0+0table配列に格納されたIPv6 UDPエンドポイントエントリの数を示す。
tableMIB_UDP6ROW2200+8+8拡張IPv6 UDP行(MIB_UDP6ROW2)の可変長配列である。

各言語での定義

#include <windows.h>

// MIB_UDP6ROW2  (x64 200 / x86 200 バイト)
typedef struct MIB_UDP6ROW2 {
    BYTE ucLocalAddr[16];
    DWORD dwLocalScopeId;
    DWORD dwLocalPort;
    DWORD dwOwningPid;
    LONGLONG liCreateTimestamp;
    _Anonymous_e__Union Anonymous;
    ULONGLONG OwningModuleInfo[16];
    BYTE ucRemoteAddr[16];
    DWORD dwRemoteScopeId;
    DWORD dwRemotePort;
} MIB_UDP6ROW2;

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

[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Unicode)]
public struct MIB_UDP6ROW2
{
    [MarshalAs(UnmanagedType.ByValArray, SizeConst = 16)] public byte[] ucLocalAddr;
    public uint dwLocalScopeId;
    public uint dwLocalPort;
    public uint dwOwningPid;
    public long liCreateTimestamp;
    public _Anonymous_e__Union Anonymous;
    [MarshalAs(UnmanagedType.ByValArray, SizeConst = 16)] public ulong[] OwningModuleInfo;
    [MarshalAs(UnmanagedType.ByValArray, SizeConst = 16)] public byte[] ucRemoteAddr;
    public uint dwRemoteScopeId;
    public uint dwRemotePort;
}

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

<StructLayout(LayoutKind.Sequential, CharSet:=CharSet.Unicode)>
Public Structure MIB_UDP6ROW2
    <MarshalAs(UnmanagedType.ByValArray, SizeConst:=16)> Public ucLocalAddr() As Byte
    Public dwLocalScopeId As UInteger
    Public dwLocalPort As UInteger
    Public dwOwningPid As UInteger
    Public liCreateTimestamp As Long
    Public Anonymous As _Anonymous_e__Union
    <MarshalAs(UnmanagedType.ByValArray, SizeConst:=16)> Public OwningModuleInfo() As ULong
    <MarshalAs(UnmanagedType.ByValArray, SizeConst:=16)> Public ucRemoteAddr() As Byte
    Public dwRemoteScopeId As UInteger
    Public dwRemotePort As UInteger
End Structure

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

class MIB_UDP6ROW2(ctypes.Structure):
    _fields_ = [
        ("ucLocalAddr", ctypes.c_ubyte * 16),
        ("dwLocalScopeId", wintypes.DWORD),
        ("dwLocalPort", wintypes.DWORD),
        ("dwOwningPid", wintypes.DWORD),
        ("liCreateTimestamp", ctypes.c_longlong),
        ("Anonymous", _Anonymous_e__Union),
        ("OwningModuleInfo", ctypes.c_ulonglong * 16),
        ("ucRemoteAddr", ctypes.c_ubyte * 16),
        ("dwRemoteScopeId", wintypes.DWORD),
        ("dwRemotePort", wintypes.DWORD),
    ]

class MIB_UDP6TABLE2(ctypes.Structure):
    _fields_ = [
        ("dwNumEntries", wintypes.DWORD),
        ("table", MIB_UDP6ROW2 * 1),
    ]
#[repr(C)]
pub struct MIB_UDP6ROW2 {
    pub ucLocalAddr: [u8; 16],
    pub dwLocalScopeId: u32,
    pub dwLocalPort: u32,
    pub dwOwningPid: u32,
    pub liCreateTimestamp: i64,
    pub Anonymous: _Anonymous_e__Union,
    pub OwningModuleInfo: [u64; 16],
    pub ucRemoteAddr: [u8; 16],
    pub dwRemoteScopeId: u32,
    pub dwRemotePort: u32,
}

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

type MIB_UDP6ROW2 struct {
	ucLocalAddr [16]byte
	dwLocalScopeId uint32
	dwLocalPort uint32
	dwOwningPid uint32
	liCreateTimestamp int64
	Anonymous _Anonymous_e__Union
	OwningModuleInfo [16]uint64
	ucRemoteAddr [16]byte
	dwRemoteScopeId uint32
	dwRemotePort uint32
}

type MIB_UDP6TABLE2 struct {
	dwNumEntries uint32
	table [1]MIB_UDP6ROW2
}
type
  MIB_UDP6ROW2 = record
    ucLocalAddr: array[0..15] of Byte;
    dwLocalScopeId: DWORD;
    dwLocalPort: DWORD;
    dwOwningPid: DWORD;
    liCreateTimestamp: Int64;
    Anonymous: _Anonymous_e__Union;
    OwningModuleInfo: array[0..15] of UInt64;
    ucRemoteAddr: array[0..15] of Byte;
    dwRemoteScopeId: DWORD;
    dwRemotePort: DWORD;
  end;

  MIB_UDP6TABLE2 = record
    dwNumEntries: DWORD;
    table: array[0..0] of MIB_UDP6ROW2;
  end;
const MIB_UDP6ROW2 = extern struct {
    ucLocalAddr: [16]u8,
    dwLocalScopeId: u32,
    dwLocalPort: u32,
    dwOwningPid: u32,
    liCreateTimestamp: i64,
    Anonymous: _Anonymous_e__Union,
    OwningModuleInfo: [16]u64,
    ucRemoteAddr: [16]u8,
    dwRemoteScopeId: u32,
    dwRemotePort: u32,
};

const MIB_UDP6TABLE2 = extern struct {
    dwNumEntries: u32,
    table: [1]MIB_UDP6ROW2,
};
type
  MIB_UDP6ROW2 {.bycopy.} = object
    ucLocalAddr: array[16, uint8]
    dwLocalScopeId: uint32
    dwLocalPort: uint32
    dwOwningPid: uint32
    liCreateTimestamp: int64
    Anonymous: _Anonymous_e__Union
    OwningModuleInfo: array[16, uint64]
    ucRemoteAddr: array[16, uint8]
    dwRemoteScopeId: uint32
    dwRemotePort: uint32

  MIB_UDP6TABLE2 {.bycopy.} = object
    dwNumEntries: uint32
    table: array[1, MIB_UDP6ROW2]
struct MIB_UDP6ROW2
{
    ubyte[16] ucLocalAddr;
    uint dwLocalScopeId;
    uint dwLocalPort;
    uint dwOwningPid;
    long liCreateTimestamp;
    _Anonymous_e__Union Anonymous;
    ulong[16] OwningModuleInfo;
    ubyte[16] ucRemoteAddr;
    uint dwRemoteScopeId;
    uint dwRemotePort;
}

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

#defstruct global MIB_UDP6TABLE2
    #field int dwNumEntries
    #field MIB_UDP6ROW2 table 1
#endstruct

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