GetPerTcpConnectionEStats
関数シグネチャ
// IPHLPAPI.dll
#include <windows.h>
DWORD GetPerTcpConnectionEStats(
MIB_TCPROW_LH* Row,
TCP_ESTATS_TYPE EstatsType,
BYTE* Rw, // optional
DWORD RwVersion,
DWORD RwSize,
BYTE* Ros, // optional
DWORD RosVersion,
DWORD RosSize,
BYTE* Rod, // optional
DWORD RodVersion,
DWORD RodSize
);パラメーター
| 名前 | 型 | 方向 | 説明 | ||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| Row | MIB_TCPROW_LH* | in | IPv4 TCP 接続を表す MIB_TCPROW 構造体へのポインターです。 | ||||||||||||||||||||
| EstatsType | TCP_ESTATS_TYPE | in | 要求する TCP の拡張統計情報の種類です。このパラメーターは、呼び出しが成功した場合に Rw、Rod、Ros の各パラメーターで返される情報のデータと形式を決定します。 このパラメーターには、Tcpestats.h ヘッダーファイルで定義されている TCP_ESTATS_TYPE 列挙型のいずれかの値を指定できます。
| ||||||||||||||||||||
| Rw | BYTE* | outoptional | 読み取り/書き込み情報を受け取るバッファーへのポインターです。アプリケーションが TCP 接続の読み取り/書き込み情報を取得しない場合、このパラメーターは NULL ポインターでもかまいません。 | ||||||||||||||||||||
| RwVersion | DWORD | in | 要求する読み取り/書き込み情報のバージョンです。現在サポートされている値はバージョン 0 です。 | ||||||||||||||||||||
| RwSize | DWORD | in | Rw パラメーターが指すバッファーのサイズ (バイト単位) です。 | ||||||||||||||||||||
| Ros | BYTE* | outoptional | 読み取り専用の静的情報を受け取るバッファーへのポインターです。アプリケーションが TCP 接続の読み取り専用の静的情報を取得しない場合、このパラメーターは NULL ポインターでもかまいません。 | ||||||||||||||||||||
| RosVersion | DWORD | in | 要求する読み取り専用の静的情報のバージョンです。現在サポートされている値はバージョン 0 です。 | ||||||||||||||||||||
| RosSize | DWORD | in | Ros パラメーターが指すバッファーのサイズ (バイト単位) です。 | ||||||||||||||||||||
| Rod | BYTE* | outoptional | 読み取り専用の動的情報を受け取るバッファーへのポインターです。アプリケーションが TCP 接続の読み取り専用の動的情報を取得しない場合、このパラメーターは NULL ポインターでもかまいません。 | ||||||||||||||||||||
| RodVersion | DWORD | in | 要求する読み取り専用の動的情報のバージョンです。現在サポートされている値はバージョン 0 です。 | ||||||||||||||||||||
| RodSize | DWORD | in | Rod パラメーターが指すバッファーのサイズ (バイト単位) です。 |
戻り値の型: DWORD
公式ドキュメント
IPv4 TCP 接続の拡張統計情報を取得します。
戻り値
関数が成功した場合、戻り値は NO_ERROR です。
関数が失敗した場合、戻り値は次のエラーコードのいずれかです。
| 戻り値 | 説明 |
|---|---|
|
関数に渡されたバッファーが小さすぎます。このエラーは、Rw、Ros、または Rod パラメーターが指すバッファーがデータを受け取るのに十分な大きさでない場合に返されます。また、Rw、Ros、または Rod パラメーターが指すいずれかのバッファーが NULL であるにもかかわらず、対応する RwSize、RosSize、または RodSize に長さが指定されている場合にも返されます。
このエラー値は Windows Vista および Windows Server 2008 で返されます。 |
|
| パラメーターが正しくありません。このエラーは、Row パラメーターが NULL ポインターの場合に返されます。 | |
指定されたユーザーバッファーは、要求された操作に対して無効です。このエラーは、Rw、Ros、または Rod パラメーターが指すいずれかのバッファーが NULL であるにもかかわらず、対応する RwSize、RosSize、または RodSize に長さが指定されている場合に返されます。その結果、次のいずれかの条件を満たす場合にこのエラーが返されます。
このエラー値は Windows 7 および Windows Server 2008 R2 で返されます。 |
|
| 要求されたエントリが見つかりませんでした。このエラーは、Row パラメーターで指定された TCP 接続が見つからなかった場合に返されます。 | |
| 要求はサポートされていません。このエラーは、RwVersion、RosVersion、または RodVersion パラメーターが 0 に設定されていない場合に返されます。 | |
|
返されたエラーのメッセージ文字列を取得するには、FormatMessage を使用してください。 |
解説(Remarks)
GetPerTcpConnectionEStats 関数は Windows Vista 以降で定義されています。
GetPerTcpConnectionEStats 関数は、ネットワークとアプリケーションの両方におけるパフォーマンスの問題を TCP を使って診断するために設計されています。ネットワークベースのアプリケーションのパフォーマンスが低下している場合、TCP はボトルネックが送信側、受信側、またはネットワーク自体のいずれにあるかを判別できます。ボトルネックがネットワークにある場合、TCP はその性質に関する具体的な情報を提供できます。
GetPerTcpConnectionEStats 関数は、Row パラメーターで渡された IPv4 TCP 接続の拡張統計情報を取得します。取得する拡張統計情報の種類は EstatsType パラメーターで指定します。この TCP 接続の拡張統計情報は、EstatsType パラメーターに TcpConnectionEstatsSynOpts が渡される場合を除き、すべての TCP_ESTATS_TYPE 値について、あらかじめ SetPerTcpConnectionEStats 関数の呼び出しによって有効化されている必要があります。
ローカルコンピューター上の IPv4 TCP 接続テーブルを取得するには、GetTcpTable 関数を使用します。この関数は、MIB_TCPROW エントリの配列を含む MIB_TCPTABLE 構造体を返します。GetPerTcpConnectionEStats 関数に渡す Row パラメーターは、既存の IPv4 TCP 接続のエントリでなければなりません。
現在サポートされている TCP 接続統計情報のバージョンはバージョン 0 のみです。したがって、GetPerTcpConnectionEStats に渡す RwVersion、RosVersion、RodVersion パラメーターは 0 に設定する必要があります。
IPv6 接続の拡張 TCP 統計情報については、GetPerTcp6ConnectionEStats および SetPerTcp6ConnectionEStats 関数を参照してください。
SetPerTcpConnectionEStats 関数は、Administrators グループのメンバーとしてログオンしているユーザーのみが呼び出せます。Administrators グループのメンバーでないユーザーが SetPerTcpConnectionEStats を呼び出した場合、関数呼び出しは失敗し、ERROR_ACCESS_DENIED が返されます。この関数は、Windows Vista 以降のユーザーアカウント制御 (UAC) のために失敗することもあります。この関数を含むアプリケーションが、組み込みの Administrator 以外の Administrators グループのメンバーとしてログオンしているユーザーによって実行された場合、アプリケーションのマニフェストファイルで requestedExecutionLevel が requireAdministrator に設定されていない限り、この呼び出しは失敗します。アプリケーションにこのマニフェストファイルがない場合、組み込みの Administrator 以外の Administrators グループのメンバーとしてログオンしているユーザーがこの関数を成功させるには、組み込みの Administrator として拡張シェルでアプリケーションを実行 (管理者として実行) する必要があります。
GetPerTcpConnectionEStats の呼び出し元は、返された Rw 構造体の EnableCollection フィールドを確認し、それが TRUE でない場合は Ros および Rod 構造体内のデータを無視する必要があります。EnableCollection が FALSE に設定されている場合、Ros および Rod で返されるデータは未定義です。たとえば、これが発生する条件の 1 つは、GetPerTcpConnectionEStats を使用して IPv4 TCP 接続の拡張統計情報を取得しており、事前に SetPerTcpConnectionEStats を呼び出して拡張統計情報を有効化していた場合です。SetPerTcpConnectionEStats の呼び出しが失敗していると、その後の GetPerTcpConnectionEStats の呼び出しは、拡張 TCP 統計情報ではなく無意味なランダムデータを返します。この例は、以下の例を管理者として実行した場合と通常のユーザーとして実行した場合とで観察できます。
例
コード例については、GetPerTcp6ConnectionEStats 関数 のトピックの Examples セクションを参照してください。
Microsoft 公式リファレンス: 英語 (en-us) · 日本語 (ja-jp) · 原文ソース (GitHub)
各言語での呼び出し定義
// IPHLPAPI.dll
#include <windows.h>
DWORD GetPerTcpConnectionEStats(
MIB_TCPROW_LH* Row,
TCP_ESTATS_TYPE EstatsType,
BYTE* Rw, // optional
DWORD RwVersion,
DWORD RwSize,
BYTE* Ros, // optional
DWORD RosVersion,
DWORD RosSize,
BYTE* Rod, // optional
DWORD RodVersion,
DWORD RodSize
);[DllImport("IPHLPAPI.dll", ExactSpelling = true)]
static extern uint GetPerTcpConnectionEStats(
IntPtr Row, // MIB_TCPROW_LH*
int EstatsType, // TCP_ESTATS_TYPE
IntPtr Rw, // BYTE* optional, out
uint RwVersion, // DWORD
uint RwSize, // DWORD
IntPtr Ros, // BYTE* optional, out
uint RosVersion, // DWORD
uint RosSize, // DWORD
IntPtr Rod, // BYTE* optional, out
uint RodVersion, // DWORD
uint RodSize // DWORD
);<DllImport("IPHLPAPI.dll", ExactSpelling:=True)>
Public Shared Function GetPerTcpConnectionEStats(
Row As IntPtr, ' MIB_TCPROW_LH*
EstatsType As Integer, ' TCP_ESTATS_TYPE
Rw As IntPtr, ' BYTE* optional, out
RwVersion As UInteger, ' DWORD
RwSize As UInteger, ' DWORD
Ros As IntPtr, ' BYTE* optional, out
RosVersion As UInteger, ' DWORD
RosSize As UInteger, ' DWORD
Rod As IntPtr, ' BYTE* optional, out
RodVersion As UInteger, ' DWORD
RodSize As UInteger ' DWORD
) As UInteger
End Function' Row : MIB_TCPROW_LH*
' EstatsType : TCP_ESTATS_TYPE
' Rw : BYTE* optional, out
' RwVersion : DWORD
' RwSize : DWORD
' Ros : BYTE* optional, out
' RosVersion : DWORD
' RosSize : DWORD
' Rod : BYTE* optional, out
' RodVersion : DWORD
' RodSize : DWORD
Declare PtrSafe Function GetPerTcpConnectionEStats Lib "iphlpapi" ( _
ByVal Row As LongPtr, _
ByVal EstatsType As Long, _
ByVal Rw As LongPtr, _
ByVal RwVersion As Long, _
ByVal RwSize As Long, _
ByVal Ros As LongPtr, _
ByVal RosVersion As Long, _
ByVal RosSize As Long, _
ByVal Rod As LongPtr, _
ByVal RodVersion As Long, _
ByVal RodSize As Long) As Long
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。import ctypes
from ctypes import wintypes
GetPerTcpConnectionEStats = ctypes.windll.iphlpapi.GetPerTcpConnectionEStats
GetPerTcpConnectionEStats.restype = wintypes.DWORD
GetPerTcpConnectionEStats.argtypes = [
ctypes.c_void_p, # Row : MIB_TCPROW_LH*
ctypes.c_int, # EstatsType : TCP_ESTATS_TYPE
ctypes.POINTER(ctypes.c_ubyte), # Rw : BYTE* optional, out
wintypes.DWORD, # RwVersion : DWORD
wintypes.DWORD, # RwSize : DWORD
ctypes.POINTER(ctypes.c_ubyte), # Ros : BYTE* optional, out
wintypes.DWORD, # RosVersion : DWORD
wintypes.DWORD, # RosSize : DWORD
ctypes.POINTER(ctypes.c_ubyte), # Rod : BYTE* optional, out
wintypes.DWORD, # RodVersion : DWORD
wintypes.DWORD, # RodSize : DWORD
]require 'fiddle'
require 'fiddle/import'
lib = Fiddle.dlopen('IPHLPAPI.dll')
GetPerTcpConnectionEStats = Fiddle::Function.new(
lib['GetPerTcpConnectionEStats'],
[
Fiddle::TYPE_VOIDP, # Row : MIB_TCPROW_LH*
Fiddle::TYPE_INT, # EstatsType : TCP_ESTATS_TYPE
Fiddle::TYPE_VOIDP, # Rw : BYTE* optional, out
-Fiddle::TYPE_INT, # RwVersion : DWORD
-Fiddle::TYPE_INT, # RwSize : DWORD
Fiddle::TYPE_VOIDP, # Ros : BYTE* optional, out
-Fiddle::TYPE_INT, # RosVersion : DWORD
-Fiddle::TYPE_INT, # RosSize : DWORD
Fiddle::TYPE_VOIDP, # Rod : BYTE* optional, out
-Fiddle::TYPE_INT, # RodVersion : DWORD
-Fiddle::TYPE_INT, # RodSize : DWORD
],
-Fiddle::TYPE_INT)#[link(name = "iphlpapi")]
extern "system" {
fn GetPerTcpConnectionEStats(
Row: *mut MIB_TCPROW_LH, // MIB_TCPROW_LH*
EstatsType: i32, // TCP_ESTATS_TYPE
Rw: *mut u8, // BYTE* optional, out
RwVersion: u32, // DWORD
RwSize: u32, // DWORD
Ros: *mut u8, // BYTE* optional, out
RosVersion: u32, // DWORD
RosSize: u32, // DWORD
Rod: *mut u8, // BYTE* optional, out
RodVersion: u32, // DWORD
RodSize: u32 // DWORD
) -> u32;
}
// crates: windows-sys provides ready-made bindings for this API.$sig = @"
[DllImport("IPHLPAPI.dll")]
public static extern uint GetPerTcpConnectionEStats(IntPtr Row, int EstatsType, IntPtr Rw, uint RwVersion, uint RwSize, IntPtr Ros, uint RosVersion, uint RosSize, IntPtr Rod, uint RodVersion, uint RodSize);
"@
$api = Add-Type -MemberDefinition $sig -Name 'IPHLPAPI_GetPerTcpConnectionEStats' -Namespace Win32 -PassThru
# $api::GetPerTcpConnectionEStats(Row, EstatsType, Rw, RwVersion, RwSize, Ros, RosVersion, RosSize, Rod, RodVersion, RodSize)#uselib "IPHLPAPI.dll"
#func global GetPerTcpConnectionEStats "GetPerTcpConnectionEStats" sptr, sptr, sptr, sptr, sptr, sptr, sptr, sptr, sptr, sptr, sptr
; GetPerTcpConnectionEStats varptr(Row), EstatsType, varptr(Rw), RwVersion, RwSize, varptr(Ros), RosVersion, RosSize, varptr(Rod), RodVersion, RodSize ; 戻り値は stat
; Row : MIB_TCPROW_LH* -> "sptr"
; EstatsType : TCP_ESTATS_TYPE -> "sptr"
; Rw : BYTE* optional, out -> "sptr"
; RwVersion : DWORD -> "sptr"
; RwSize : DWORD -> "sptr"
; Ros : BYTE* optional, out -> "sptr"
; RosVersion : DWORD -> "sptr"
; RosSize : DWORD -> "sptr"
; Rod : BYTE* optional, out -> "sptr"
; RodVersion : DWORD -> "sptr"
; RodSize : DWORD -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。#uselib "IPHLPAPI.dll" #cfunc global GetPerTcpConnectionEStats "GetPerTcpConnectionEStats" var, int, var, int, int, var, int, int, var, int, int ; res = GetPerTcpConnectionEStats(Row, EstatsType, Rw, RwVersion, RwSize, Ros, RosVersion, RosSize, Rod, RodVersion, RodSize) ; Row : MIB_TCPROW_LH* -> "var" ; EstatsType : TCP_ESTATS_TYPE -> "int" ; Rw : BYTE* optional, out -> "var" ; RwVersion : DWORD -> "int" ; RwSize : DWORD -> "int" ; Ros : BYTE* optional, out -> "var" ; RosVersion : DWORD -> "int" ; RosSize : DWORD -> "int" ; Rod : BYTE* optional, out -> "var" ; RodVersion : DWORD -> "int" ; RodSize : DWORD -> "int" ; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。#uselib "IPHLPAPI.dll" #cfunc global GetPerTcpConnectionEStats "GetPerTcpConnectionEStats" sptr, int, sptr, int, int, sptr, int, int, sptr, int, int ; res = GetPerTcpConnectionEStats(varptr(Row), EstatsType, varptr(Rw), RwVersion, RwSize, varptr(Ros), RosVersion, RosSize, varptr(Rod), RodVersion, RodSize) ; Row : MIB_TCPROW_LH* -> "sptr" ; EstatsType : TCP_ESTATS_TYPE -> "int" ; Rw : BYTE* optional, out -> "sptr" ; RwVersion : DWORD -> "int" ; RwSize : DWORD -> "int" ; Ros : BYTE* optional, out -> "sptr" ; RosVersion : DWORD -> "int" ; RosSize : DWORD -> "int" ; Rod : BYTE* optional, out -> "sptr" ; RodVersion : DWORD -> "int" ; RodSize : DWORD -> "int" ; ※出力/バッファ引数はポインタ方式(token=sptr / 呼び出しは varptr(変数))。
; DWORD GetPerTcpConnectionEStats(MIB_TCPROW_LH* Row, TCP_ESTATS_TYPE EstatsType, BYTE* Rw, DWORD RwVersion, DWORD RwSize, BYTE* Ros, DWORD RosVersion, DWORD RosSize, BYTE* Rod, DWORD RodVersion, DWORD RodSize) #uselib "IPHLPAPI.dll" #cfunc global GetPerTcpConnectionEStats "GetPerTcpConnectionEStats" var, int, var, int, int, var, int, int, var, int, int ; res = GetPerTcpConnectionEStats(Row, EstatsType, Rw, RwVersion, RwSize, Ros, RosVersion, RosSize, Rod, RodVersion, RodSize) ; Row : MIB_TCPROW_LH* -> "var" ; EstatsType : TCP_ESTATS_TYPE -> "int" ; Rw : BYTE* optional, out -> "var" ; RwVersion : DWORD -> "int" ; RwSize : DWORD -> "int" ; Ros : BYTE* optional, out -> "var" ; RosVersion : DWORD -> "int" ; RosSize : DWORD -> "int" ; Rod : BYTE* optional, out -> "var" ; RodVersion : DWORD -> "int" ; RodSize : DWORD -> "int" ; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。; DWORD GetPerTcpConnectionEStats(MIB_TCPROW_LH* Row, TCP_ESTATS_TYPE EstatsType, BYTE* Rw, DWORD RwVersion, DWORD RwSize, BYTE* Ros, DWORD RosVersion, DWORD RosSize, BYTE* Rod, DWORD RodVersion, DWORD RodSize) #uselib "IPHLPAPI.dll" #cfunc global GetPerTcpConnectionEStats "GetPerTcpConnectionEStats" intptr, int, intptr, int, int, intptr, int, int, intptr, int, int ; res = GetPerTcpConnectionEStats(varptr(Row), EstatsType, varptr(Rw), RwVersion, RwSize, varptr(Ros), RosVersion, RosSize, varptr(Rod), RodVersion, RodSize) ; Row : MIB_TCPROW_LH* -> "intptr" ; EstatsType : TCP_ESTATS_TYPE -> "int" ; Rw : BYTE* optional, out -> "intptr" ; RwVersion : DWORD -> "int" ; RwSize : DWORD -> "int" ; Ros : BYTE* optional, out -> "intptr" ; RosVersion : DWORD -> "int" ; RosSize : DWORD -> "int" ; Rod : BYTE* optional, out -> "intptr" ; RodVersion : DWORD -> "int" ; RodSize : DWORD -> "int" ; ※出力/バッファ引数はポインタ方式(token=intptr / 呼び出しは varptr(変数))。
import (
"golang.org/x/sys/windows"
"unsafe"
)
var (
iphlpapi = windows.NewLazySystemDLL("IPHLPAPI.dll")
procGetPerTcpConnectionEStats = iphlpapi.NewProc("GetPerTcpConnectionEStats")
)
// Row (MIB_TCPROW_LH*), EstatsType (TCP_ESTATS_TYPE), Rw (BYTE* optional, out), RwVersion (DWORD), RwSize (DWORD), Ros (BYTE* optional, out), RosVersion (DWORD), RosSize (DWORD), Rod (BYTE* optional, out), RodVersion (DWORD), RodSize (DWORD)
r1, _, err := procGetPerTcpConnectionEStats.Call(
uintptr(Row),
uintptr(EstatsType),
uintptr(Rw),
uintptr(RwVersion),
uintptr(RwSize),
uintptr(Ros),
uintptr(RosVersion),
uintptr(RosSize),
uintptr(Rod),
uintptr(RodVersion),
uintptr(RodSize),
)
_ = err // syscall.Errno (valid when the call sets last-error)
_ = r1 // DWORDfunction GetPerTcpConnectionEStats(
Row: Pointer; // MIB_TCPROW_LH*
EstatsType: Integer; // TCP_ESTATS_TYPE
Rw: Pointer; // BYTE* optional, out
RwVersion: DWORD; // DWORD
RwSize: DWORD; // DWORD
Ros: Pointer; // BYTE* optional, out
RosVersion: DWORD; // DWORD
RosSize: DWORD; // DWORD
Rod: Pointer; // BYTE* optional, out
RodVersion: DWORD; // DWORD
RodSize: DWORD // DWORD
): DWORD; stdcall;
external 'IPHLPAPI.dll' name 'GetPerTcpConnectionEStats';result := DllCall("IPHLPAPI\GetPerTcpConnectionEStats"
, "Ptr", Row ; MIB_TCPROW_LH*
, "Int", EstatsType ; TCP_ESTATS_TYPE
, "Ptr", Rw ; BYTE* optional, out
, "UInt", RwVersion ; DWORD
, "UInt", RwSize ; DWORD
, "Ptr", Ros ; BYTE* optional, out
, "UInt", RosVersion ; DWORD
, "UInt", RosSize ; DWORD
, "Ptr", Rod ; BYTE* optional, out
, "UInt", RodVersion ; DWORD
, "UInt", RodSize ; DWORD
, "UInt") ; return: DWORD●GetPerTcpConnectionEStats(Row, EstatsType, Rw, RwVersion, RwSize, Ros, RosVersion, RosSize, Rod, RodVersion, RodSize) = DLL("IPHLPAPI.dll", "dword GetPerTcpConnectionEStats(void*, int, void*, dword, dword, void*, dword, dword, void*, dword, dword)")
# 呼び出し: GetPerTcpConnectionEStats(Row, EstatsType, Rw, RwVersion, RwSize, Ros, RosVersion, RosSize, Rod, RodVersion, RodSize)
# Row : MIB_TCPROW_LH* -> "void*"
# EstatsType : TCP_ESTATS_TYPE -> "int"
# Rw : BYTE* optional, out -> "void*"
# RwVersion : DWORD -> "dword"
# RwSize : DWORD -> "dword"
# Ros : BYTE* optional, out -> "void*"
# RosVersion : DWORD -> "dword"
# RosSize : DWORD -> "dword"
# Rod : BYTE* optional, out -> "void*"
# RodVersion : DWORD -> "dword"
# RodSize : DWORD -> "dword"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。const std = @import("std");
extern "iphlpapi" fn GetPerTcpConnectionEStats(
Row: [*c]MIB_TCPROW_LH, // MIB_TCPROW_LH*
EstatsType: i32, // TCP_ESTATS_TYPE
Rw: [*c]u8, // BYTE* optional, out
RwVersion: u32, // DWORD
RwSize: u32, // DWORD
Ros: [*c]u8, // BYTE* optional, out
RosVersion: u32, // DWORD
RosSize: u32, // DWORD
Rod: [*c]u8, // BYTE* optional, out
RodVersion: u32, // DWORD
RodSize: u32 // DWORD
) callconv(std.os.windows.WINAPI) u32;proc GetPerTcpConnectionEStats(
Row: ptr MIB_TCPROW_LH, # MIB_TCPROW_LH*
EstatsType: int32, # TCP_ESTATS_TYPE
Rw: ptr uint8, # BYTE* optional, out
RwVersion: uint32, # DWORD
RwSize: uint32, # DWORD
Ros: ptr uint8, # BYTE* optional, out
RosVersion: uint32, # DWORD
RosSize: uint32, # DWORD
Rod: ptr uint8, # BYTE* optional, out
RodVersion: uint32, # DWORD
RodSize: uint32 # DWORD
): uint32 {.importc: "GetPerTcpConnectionEStats", stdcall, dynlib: "IPHLPAPI.dll".}pragma(lib, "iphlpapi");
extern(Windows)
uint GetPerTcpConnectionEStats(
MIB_TCPROW_LH* Row, // MIB_TCPROW_LH*
int EstatsType, // TCP_ESTATS_TYPE
ubyte* Rw, // BYTE* optional, out
uint RwVersion, // DWORD
uint RwSize, // DWORD
ubyte* Ros, // BYTE* optional, out
uint RosVersion, // DWORD
uint RosSize, // DWORD
ubyte* Rod, // BYTE* optional, out
uint RodVersion, // DWORD
uint RodSize // DWORD
);ccall((:GetPerTcpConnectionEStats, "IPHLPAPI.dll"), stdcall, UInt32,
(Ptr{MIB_TCPROW_LH}, Int32, Ptr{UInt8}, UInt32, UInt32, Ptr{UInt8}, UInt32, UInt32, Ptr{UInt8}, UInt32, UInt32),
Row, EstatsType, Rw, RwVersion, RwSize, Ros, RosVersion, RosSize, Rod, RodVersion, RodSize)
# Row : MIB_TCPROW_LH* -> Ptr{MIB_TCPROW_LH}
# EstatsType : TCP_ESTATS_TYPE -> Int32
# Rw : BYTE* optional, out -> Ptr{UInt8}
# RwVersion : DWORD -> UInt32
# RwSize : DWORD -> UInt32
# Ros : BYTE* optional, out -> Ptr{UInt8}
# RosVersion : DWORD -> UInt32
# RosSize : DWORD -> UInt32
# Rod : BYTE* optional, out -> Ptr{UInt8}
# RodVersion : DWORD -> UInt32
# RodSize : DWORD -> UInt32
# stdcall は 32bit のみ意味を持つ(x64 では無視)。local ffi = require("ffi")
ffi.cdef[[
uint32_t GetPerTcpConnectionEStats(
void* Row,
int32_t EstatsType,
uint8_t* Rw,
uint32_t RwVersion,
uint32_t RwSize,
uint8_t* Ros,
uint32_t RosVersion,
uint32_t RosSize,
uint8_t* Rod,
uint32_t RodVersion,
uint32_t RodSize);
]]
local iphlpapi = ffi.load("iphlpapi")
-- iphlpapi.GetPerTcpConnectionEStats(Row, EstatsType, Rw, RwVersion, RwSize, Ros, RosVersion, RosSize, Rod, RodVersion, RodSize)
-- Row : MIB_TCPROW_LH*
-- EstatsType : TCP_ESTATS_TYPE
-- Rw : BYTE* optional, out
-- RwVersion : DWORD
-- RwSize : DWORD
-- Ros : BYTE* optional, out
-- RosVersion : DWORD
-- RosSize : DWORD
-- Rod : BYTE* optional, out
-- RodVersion : DWORD
-- RodSize : DWORD
-- 構造体/GUIDへのポインタは cdef が通るよう void* で表記(実型は各引数コメント参照)。値渡し構造体・enum は対応する typedef を cdef に追加すること。const koffi = require('koffi');
const lib = koffi.load('IPHLPAPI.dll');
const GetPerTcpConnectionEStats = lib.func('__stdcall', 'GetPerTcpConnectionEStats', 'uint32_t', ['void *', 'int32_t', 'uint8_t *', 'uint32_t', 'uint32_t', 'uint8_t *', 'uint32_t', 'uint32_t', 'uint8_t *', 'uint32_t', 'uint32_t']);
// GetPerTcpConnectionEStats(Row, EstatsType, Rw, RwVersion, RwSize, Ros, RosVersion, RosSize, Rod, RodVersion, RodSize)
// Row : MIB_TCPROW_LH* -> 'void *'
// EstatsType : TCP_ESTATS_TYPE -> 'int32_t'
// Rw : BYTE* optional, out -> 'uint8_t *'
// RwVersion : DWORD -> 'uint32_t'
// RwSize : DWORD -> 'uint32_t'
// Ros : BYTE* optional, out -> 'uint8_t *'
// RosVersion : DWORD -> 'uint32_t'
// RosSize : DWORD -> 'uint32_t'
// Rod : BYTE* optional, out -> 'uint8_t *'
// RodVersion : DWORD -> 'uint32_t'
// RodSize : DWORD -> 'uint32_t'
// 出力ポインタは koffi.out(...) で包む。構造体は koffi.struct で定義。const lib = Deno.dlopen("IPHLPAPI.dll", {
GetPerTcpConnectionEStats: { parameters: ["pointer", "i32", "pointer", "u32", "u32", "pointer", "u32", "u32", "pointer", "u32", "u32"], result: "u32" },
});
// lib.symbols.GetPerTcpConnectionEStats(Row, EstatsType, Rw, RwVersion, RwSize, Ros, RosVersion, RosSize, Rod, RodVersion, RodSize)
// Row : MIB_TCPROW_LH* -> "pointer"
// EstatsType : TCP_ESTATS_TYPE -> "i32"
// Rw : BYTE* optional, out -> "pointer"
// RwVersion : DWORD -> "u32"
// RwSize : DWORD -> "u32"
// Ros : BYTE* optional, out -> "pointer"
// RosVersion : DWORD -> "u32"
// RosSize : DWORD -> "u32"
// Rod : BYTE* optional, out -> "pointer"
// RodVersion : DWORD -> "u32"
// RodSize : DWORD -> "u32"
// 文字列引数は "buffer"(NUL 終端のバイト列を Uint8Array で渡す)。
// 値渡し構造体は { struct: [ ...field types... ] } を使用。<?php
$ffi = FFI::cdef(<<<C
uint32_t GetPerTcpConnectionEStats(
void* Row,
int32_t EstatsType,
uint8_t* Rw,
uint32_t RwVersion,
uint32_t RwSize,
uint8_t* Ros,
uint32_t RosVersion,
uint32_t RosSize,
uint8_t* Rod,
uint32_t RodVersion,
uint32_t RodSize);
C, "IPHLPAPI.dll");
// $ffi->GetPerTcpConnectionEStats(Row, EstatsType, Rw, RwVersion, RwSize, Ros, RosVersion, RosSize, Rod, RodVersion, RodSize);
// Row : MIB_TCPROW_LH*
// EstatsType : TCP_ESTATS_TYPE
// Rw : BYTE* optional, out
// RwVersion : DWORD
// RwSize : DWORD
// Ros : BYTE* optional, out
// RosVersion : DWORD
// RosSize : DWORD
// Rod : BYTE* optional, out
// RodVersion : DWORD
// RodSize : DWORD
// 構造体/GUIDへのポインタは cdef が通るよう void* で表記(実型は各引数コメント参照)。値渡し構造体・enum は対応する typedef を cdef に追加すること。
// WINAPI(stdcall): x64 では呼出規約が統一されるため問題なし。x86 では __stdcall 対応のラッパが必要な場合あり。import com.sun.jna.*;
import com.sun.jna.ptr.*;
import com.sun.jna.win32.StdCallLibrary;
import com.sun.jna.win32.W32APIOptions;
public interface Iphlpapi extends StdCallLibrary {
Iphlpapi INSTANCE = Native.load("iphlpapi", Iphlpapi.class);
int GetPerTcpConnectionEStats(
Pointer Row, // MIB_TCPROW_LH*
int EstatsType, // TCP_ESTATS_TYPE
byte[] Rw, // BYTE* optional, out
int RwVersion, // DWORD
int RwSize, // DWORD
byte[] Ros, // BYTE* optional, out
int RosVersion, // DWORD
int RosSize, // DWORD
byte[] Rod, // BYTE* optional, out
int RodVersion, // DWORD
int RodSize // DWORD
);
}@[Link("iphlpapi")]
lib LibIPHLPAPI
fun GetPerTcpConnectionEStats = GetPerTcpConnectionEStats(
Row : MIB_TCPROW_LH*, # MIB_TCPROW_LH*
EstatsType : Int32, # TCP_ESTATS_TYPE
Rw : UInt8*, # BYTE* optional, out
RwVersion : UInt32, # DWORD
RwSize : UInt32, # DWORD
Ros : UInt8*, # BYTE* optional, out
RosVersion : UInt32, # DWORD
RosSize : UInt32, # DWORD
Rod : UInt8*, # BYTE* optional, out
RodVersion : UInt32, # DWORD
RodSize : UInt32 # DWORD
) : UInt32
end
# 構造体/GUID/enum は lib 内に対応する型定義が必要。
# 呼出規約: x64 は規約統一のため OK。x86(32bit)は WINAPI=stdcall だが Crystal の fun に stdcall 付与構文がなく非対応。import 'dart:ffi';
import 'package:ffi/ffi.dart';
typedef GetPerTcpConnectionEStatsNative = Uint32 Function(Pointer<Void>, Int32, Pointer<Uint8>, Uint32, Uint32, Pointer<Uint8>, Uint32, Uint32, Pointer<Uint8>, Uint32, Uint32);
typedef GetPerTcpConnectionEStatsDart = int Function(Pointer<Void>, int, Pointer<Uint8>, int, int, Pointer<Uint8>, int, int, Pointer<Uint8>, int, int);
final GetPerTcpConnectionEStats = DynamicLibrary.open('IPHLPAPI.dll')
.lookupFunction<GetPerTcpConnectionEStatsNative, GetPerTcpConnectionEStatsDart>('GetPerTcpConnectionEStats');
// Row : MIB_TCPROW_LH* -> Pointer<Void>
// EstatsType : TCP_ESTATS_TYPE -> Int32
// Rw : BYTE* optional, out -> Pointer<Uint8>
// RwVersion : DWORD -> Uint32
// RwSize : DWORD -> Uint32
// Ros : BYTE* optional, out -> Pointer<Uint8>
// RosVersion : DWORD -> Uint32
// RosSize : DWORD -> Uint32
// Rod : BYTE* optional, out -> Pointer<Uint8>
// RodVersion : DWORD -> Uint32
// RodSize : DWORD -> Uint32
// 文字列は package:ffi の "...".toNativeUtf16()/toNativeUtf8() で変換。{$mode objfpc}{$H+}
function GetPerTcpConnectionEStats(
Row: Pointer; // MIB_TCPROW_LH*
EstatsType: Integer; // TCP_ESTATS_TYPE
Rw: Pointer; // BYTE* optional, out
RwVersion: DWORD; // DWORD
RwSize: DWORD; // DWORD
Ros: Pointer; // BYTE* optional, out
RosVersion: DWORD; // DWORD
RosSize: DWORD; // DWORD
Rod: Pointer; // BYTE* optional, out
RodVersion: DWORD; // DWORD
RodSize: DWORD // DWORD
): DWORD; stdcall;
external 'IPHLPAPI.dll' name 'GetPerTcpConnectionEStats';import Foreign
import Foreign.C.Types
import Foreign.C.String
foreign import stdcall safe "GetPerTcpConnectionEStats"
c_GetPerTcpConnectionEStats :: Ptr () -> Int32 -> Ptr Word8 -> Word32 -> Word32 -> Ptr Word8 -> Word32 -> Word32 -> Ptr Word8 -> Word32 -> Word32 -> IO Word32
-- Row : MIB_TCPROW_LH* -> Ptr ()
-- EstatsType : TCP_ESTATS_TYPE -> Int32
-- Rw : BYTE* optional, out -> Ptr Word8
-- RwVersion : DWORD -> Word32
-- RwSize : DWORD -> Word32
-- Ros : BYTE* optional, out -> Ptr Word8
-- RosVersion : DWORD -> Word32
-- RosSize : DWORD -> Word32
-- Rod : BYTE* optional, out -> Ptr Word8
-- RodVersion : DWORD -> Word32
-- RodSize : DWORD -> Word32
-- 要 GHC(Windows)。stdcall は x64 では ccall として扱われる。ブロックする API は safe 呼び出し推奨。open Ctypes
open Foreign
let getpertcpconnectionestats =
foreign "GetPerTcpConnectionEStats"
((ptr void) @-> int32_t @-> (ptr uint8_t) @-> uint32_t @-> uint32_t @-> (ptr uint8_t) @-> uint32_t @-> uint32_t @-> (ptr uint8_t) @-> uint32_t @-> uint32_t @-> returning uint32_t)
(* Row : MIB_TCPROW_LH* -> (ptr void) *)
(* EstatsType : TCP_ESTATS_TYPE -> int32_t *)
(* Rw : BYTE* optional, out -> (ptr uint8_t) *)
(* RwVersion : DWORD -> uint32_t *)
(* RwSize : DWORD -> uint32_t *)
(* Ros : BYTE* optional, out -> (ptr uint8_t) *)
(* RosVersion : DWORD -> uint32_t *)
(* RosSize : DWORD -> uint32_t *)
(* Rod : BYTE* optional, out -> (ptr uint8_t) *)
(* RodVersion : DWORD -> uint32_t *)
(* RodSize : DWORD -> uint32_t *)
(* foreign は cdecl 前提。x64 Windows では WINAPI と一致。構造体は ctypes structure を定義のこと。 *)(cffi:define-foreign-library iphlpapi (t "IPHLPAPI.dll"))
(cffi:use-foreign-library iphlpapi)
(cffi:defcfun ("GetPerTcpConnectionEStats" get-per-tcp-connection-estats :convention :stdcall) :uint32
(row :pointer) ; MIB_TCPROW_LH*
(estats-type :int32) ; TCP_ESTATS_TYPE
(rw :pointer) ; BYTE* optional, out
(rw-version :uint32) ; DWORD
(rw-size :uint32) ; DWORD
(ros :pointer) ; BYTE* optional, out
(ros-version :uint32) ; DWORD
(ros-size :uint32) ; DWORD
(rod :pointer) ; BYTE* optional, out
(rod-version :uint32) ; DWORD
(rod-size :uint32)) ; DWORD
; isize/usize(INT_PTR/SIZE_T)は x64 前提で :int64/:uint64。x86 では :int32/:uint32。use Win32::API;
my $GetPerTcpConnectionEStats = Win32::API::More->new('IPHLPAPI',
'DWORD GetPerTcpConnectionEStats(LPVOID Row, int EstatsType, LPVOID Rw, DWORD RwVersion, DWORD RwSize, LPVOID Ros, DWORD RosVersion, DWORD RosSize, LPVOID Rod, DWORD RodVersion, DWORD RodSize)');
# my $ret = $GetPerTcpConnectionEStats->Call($Row, $EstatsType, $Rw, $RwVersion, $RwSize, $Ros, $RosVersion, $RosSize, $Rod, $RodVersion, $RodSize);
# Row : MIB_TCPROW_LH* -> LPVOID
# EstatsType : TCP_ESTATS_TYPE -> int
# Rw : BYTE* optional, out -> LPVOID
# RwVersion : DWORD -> DWORD
# RwSize : DWORD -> DWORD
# Ros : BYTE* optional, out -> LPVOID
# RosVersion : DWORD -> DWORD
# RosSize : DWORD -> DWORD
# Rod : BYTE* optional, out -> LPVOID
# RodVersion : DWORD -> DWORD
# RodSize : DWORD -> DWORD
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。関連項目
- f GetPerTcp6ConnectionEStats — 指定IPv6 TCP接続の拡張統計(ESTATS)情報を取得する。
- f GetTcpTable — 現在のTCP接続一覧をMIB_TCPTABLEとして取得する。
- s MIB_TCPTABLE
- f SetPerTcp6ConnectionEStats — 指定IPv6 TCP接続の拡張統計(ESTATS)収集を設定する。
- f SetPerTcpConnectionEStats — 指定IPv4 TCP接続の拡張統計(ESTATS)収集を設定する。
- s TCP_ESTATS_BANDWIDTH_ROD_v0
- s TCP_ESTATS_BANDWIDTH_RW_v0
- s TCP_ESTATS_DATA_ROD_v0
- s TCP_ESTATS_DATA_RW_v0
- s TCP_ESTATS_FINE_RTT_ROD_v0
- s TCP_ESTATS_FINE_RTT_RW_v0
- s TCP_ESTATS_OBS_REC_ROD_v0