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

MIB_TCP6TABLE_OWNER_PID

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

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

フィールド

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

各言語での定義

#include <windows.h>

// MIB_TCP6ROW_OWNER_PID  (x64 56 / x86 56 バイト)
typedef struct MIB_TCP6ROW_OWNER_PID {
    BYTE ucLocalAddr[16];
    DWORD dwLocalScopeId;
    DWORD dwLocalPort;
    BYTE ucRemoteAddr[16];
    DWORD dwRemoteScopeId;
    DWORD dwRemotePort;
    DWORD dwState;
    DWORD dwOwningPid;
} MIB_TCP6ROW_OWNER_PID;

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

[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Unicode)]
public struct MIB_TCP6ROW_OWNER_PID
{
    [MarshalAs(UnmanagedType.ByValArray, SizeConst = 16)] public byte[] ucLocalAddr;
    public uint dwLocalScopeId;
    public uint dwLocalPort;
    [MarshalAs(UnmanagedType.ByValArray, SizeConst = 16)] public byte[] ucRemoteAddr;
    public uint dwRemoteScopeId;
    public uint dwRemotePort;
    public uint dwState;
    public uint dwOwningPid;
}

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

<StructLayout(LayoutKind.Sequential, CharSet:=CharSet.Unicode)>
Public Structure MIB_TCP6ROW_OWNER_PID
    <MarshalAs(UnmanagedType.ByValArray, SizeConst:=16)> Public ucLocalAddr() As Byte
    Public dwLocalScopeId As UInteger
    Public dwLocalPort As UInteger
    <MarshalAs(UnmanagedType.ByValArray, SizeConst:=16)> Public ucRemoteAddr() As Byte
    Public dwRemoteScopeId As UInteger
    Public dwRemotePort As UInteger
    Public dwState As UInteger
    Public dwOwningPid As UInteger
End Structure

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

class MIB_TCP6ROW_OWNER_PID(ctypes.Structure):
    _fields_ = [
        ("ucLocalAddr", ctypes.c_ubyte * 16),
        ("dwLocalScopeId", wintypes.DWORD),
        ("dwLocalPort", wintypes.DWORD),
        ("ucRemoteAddr", ctypes.c_ubyte * 16),
        ("dwRemoteScopeId", wintypes.DWORD),
        ("dwRemotePort", wintypes.DWORD),
        ("dwState", wintypes.DWORD),
        ("dwOwningPid", wintypes.DWORD),
    ]

class MIB_TCP6TABLE_OWNER_PID(ctypes.Structure):
    _fields_ = [
        ("dwNumEntries", wintypes.DWORD),
        ("table", MIB_TCP6ROW_OWNER_PID * 1),
    ]
#[repr(C)]
pub struct MIB_TCP6ROW_OWNER_PID {
    pub ucLocalAddr: [u8; 16],
    pub dwLocalScopeId: u32,
    pub dwLocalPort: u32,
    pub ucRemoteAddr: [u8; 16],
    pub dwRemoteScopeId: u32,
    pub dwRemotePort: u32,
    pub dwState: u32,
    pub dwOwningPid: u32,
}

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

type MIB_TCP6ROW_OWNER_PID struct {
	ucLocalAddr [16]byte
	dwLocalScopeId uint32
	dwLocalPort uint32
	ucRemoteAddr [16]byte
	dwRemoteScopeId uint32
	dwRemotePort uint32
	dwState uint32
	dwOwningPid uint32
}

type MIB_TCP6TABLE_OWNER_PID struct {
	dwNumEntries uint32
	table [1]MIB_TCP6ROW_OWNER_PID
}
type
  MIB_TCP6ROW_OWNER_PID = record
    ucLocalAddr: array[0..15] of Byte;
    dwLocalScopeId: DWORD;
    dwLocalPort: DWORD;
    ucRemoteAddr: array[0..15] of Byte;
    dwRemoteScopeId: DWORD;
    dwRemotePort: DWORD;
    dwState: DWORD;
    dwOwningPid: DWORD;
  end;

  MIB_TCP6TABLE_OWNER_PID = record
    dwNumEntries: DWORD;
    table: array[0..0] of MIB_TCP6ROW_OWNER_PID;
  end;
const MIB_TCP6ROW_OWNER_PID = extern struct {
    ucLocalAddr: [16]u8,
    dwLocalScopeId: u32,
    dwLocalPort: u32,
    ucRemoteAddr: [16]u8,
    dwRemoteScopeId: u32,
    dwRemotePort: u32,
    dwState: u32,
    dwOwningPid: u32,
};

const MIB_TCP6TABLE_OWNER_PID = extern struct {
    dwNumEntries: u32,
    table: [1]MIB_TCP6ROW_OWNER_PID,
};
type
  MIB_TCP6ROW_OWNER_PID {.bycopy.} = object
    ucLocalAddr: array[16, uint8]
    dwLocalScopeId: uint32
    dwLocalPort: uint32
    ucRemoteAddr: array[16, uint8]
    dwRemoteScopeId: uint32
    dwRemotePort: uint32
    dwState: uint32
    dwOwningPid: uint32

  MIB_TCP6TABLE_OWNER_PID {.bycopy.} = object
    dwNumEntries: uint32
    table: array[1, MIB_TCP6ROW_OWNER_PID]
struct MIB_TCP6ROW_OWNER_PID
{
    ubyte[16] ucLocalAddr;
    uint dwLocalScopeId;
    uint dwLocalPort;
    ubyte[16] ucRemoteAddr;
    uint dwRemoteScopeId;
    uint dwRemotePort;
    uint dwState;
    uint dwOwningPid;
}

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

#defstruct global MIB_TCP6TABLE_OWNER_PID
    #field int dwNumEntries
    #field MIB_TCP6ROW_OWNER_PID table 1
#endstruct

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