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

MIB_UDP6TABLE

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

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

フィールド

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

各言語での定義

#include <windows.h>

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

// MIB_UDP6ROW  (x64 24 / x86 24 バイト)
typedef struct MIB_UDP6ROW {
    IN6_ADDR dwLocalAddr;
    DWORD dwLocalScopeId;
    DWORD dwLocalPort;
} MIB_UDP6ROW;

// MIB_UDP6TABLE  (x64 28 / x86 28 バイト)
typedef struct MIB_UDP6TABLE {
    DWORD dwNumEntries;
    MIB_UDP6ROW table[1];
} MIB_UDP6TABLE;
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_UDP6ROW
{
    public IN6_ADDR dwLocalAddr;
    public uint dwLocalScopeId;
    public uint dwLocalPort;
}

[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Unicode)]
public struct MIB_UDP6TABLE
{
    public uint dwNumEntries;
    [MarshalAs(UnmanagedType.ByValArray, SizeConst = 1)] public MIB_UDP6ROW[] 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_UDP6ROW
    Public dwLocalAddr As IN6_ADDR
    Public dwLocalScopeId As UInteger
    Public dwLocalPort As UInteger
End Structure

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

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

class MIB_UDP6ROW(ctypes.Structure):
    _fields_ = [
        ("dwLocalAddr", IN6_ADDR),
        ("dwLocalScopeId", wintypes.DWORD),
        ("dwLocalPort", wintypes.DWORD),
    ]

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

#[repr(C)]
pub struct MIB_UDP6ROW {
    pub dwLocalAddr: IN6_ADDR,
    pub dwLocalScopeId: u32,
    pub dwLocalPort: u32,
}

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

type IN6_ADDR struct {
	u _u_e__Union
}

type MIB_UDP6ROW struct {
	dwLocalAddr IN6_ADDR
	dwLocalScopeId uint32
	dwLocalPort uint32
}

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

  MIB_UDP6ROW = record
    dwLocalAddr: IN6_ADDR;
    dwLocalScopeId: DWORD;
    dwLocalPort: DWORD;
  end;

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

const MIB_UDP6ROW = extern struct {
    dwLocalAddr: IN6_ADDR,
    dwLocalScopeId: u32,
    dwLocalPort: u32,
};

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

  MIB_UDP6ROW {.bycopy.} = object
    dwLocalAddr: IN6_ADDR
    dwLocalScopeId: uint32
    dwLocalPort: uint32

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

struct MIB_UDP6ROW
{
    IN6_ADDR dwLocalAddr;
    uint dwLocalScopeId;
    uint dwLocalPort;
}

struct MIB_UDP6TABLE
{
    uint dwNumEntries;
    MIB_UDP6ROW[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_UDP6TABLE サイズ: 28 バイト(x64)
dim st, 7    ; 4byte整数×7(構造体サイズ 28 / 4 切り上げ)
; dwNumEntries : DWORD (+0, 4byte)  st.0 = 値  /  値 = st.0   (lpoke/lpeek も可)
; table : MIB_UDP6ROW (+4, 24byte)  varptr(st)+4 を基点に操作(24byte:入れ子/配列)
; ※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_UDP6ROW
    #field IN6_ADDR dwLocalAddr
    #field int dwLocalScopeId
    #field int dwLocalPort
#endstruct

#defstruct global MIB_UDP6TABLE
    #field int dwNumEntries
    #field MIB_UDP6ROW table 1
#endstruct

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