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

GetUdp6Table

関数
現在のIPv6 UDPエンドポイント一覧を取得する。
DLLIPHLPAPI.dll呼出規約winapi対応OSWindows Vista 以降

シグネチャ

// IPHLPAPI.dll
#include <windows.h>

DWORD GetUdp6Table(
    MIB_UDP6TABLE* Udp6Table,   // optional
    DWORD* SizePointer,
    BOOL Order
);

パラメーター

名前方向説明
Udp6TableMIB_UDP6TABLE*outoptionalIPv6 UDP リスナー テーブルを MIB_UDP6TABLE 構造体として受け取るバッファーへのポインター。
SizePointerDWORD*inout

入力時には、Udp6Table パラメーターが指すバッファーのサイズ (バイト単位) を指定します。

出力時には、返されるリスナー テーブルを格納するにはバッファーが十分でない場合、このパラメーターに必要なバッファー サイズ (バイト単位) が設定されます。

OrderBOOLin

返される UDP リスナー テーブルをソートするかどうかを指定するブール値。このパラメーターが TRUE の場合、テーブルは次の順序でソートされます。

  1. ローカル IPv6 アドレス
  2. ローカル スコープ ID
  3. ローカル ポート

戻り値の型: DWORD

公式ドキュメント

IPv6 のユーザー データグラム プロトコル (UDP) リスナー テーブルを取得します。

戻り値

関数が成功した場合、戻り値は NO_ERROR です。

関数が失敗した場合、戻り値は次のいずれかのエラー コードになります。

戻り値 説明
ERROR_INSUFFICIENT_BUFFER
Udp6Table パラメーターが指すバッファーが十分な大きさではありません。必要なサイズは、SizePointer パラメーターが指す ULONG 変数に返されます。
ERROR_INVALID_PARAMETER
SizePointer パラメーターが NULL であるか、 GetUdp6TableSizePointer パラメーターの指すメモリに書き込めません。
ERROR_NOT_SUPPORTED
この関数は、ローカル システムで使用されているオペレーティング システムではサポートされていません。
その他
返されたエラーのメッセージ文字列を取得するには、 FormatMessage を使用します。

解説(Remarks)

GetUdp6Table 関数は、Windows Vista 以降で定義されています。

出典・ライセンス: 上記「公式ドキュメント」の内容は Microsoft の Win32 API ドキュメント(MicrosoftDocs/sdk-api)を日本語に翻訳・改変したものです。© Microsoft Corporation. CC BY 4.0 で提供。
Microsoft 公式リファレンス: 英語 (en-us) · 日本語 (ja-jp) · 原文ソース (GitHub)

各言語での呼び出し定義

// IPHLPAPI.dll
#include <windows.h>

DWORD GetUdp6Table(
    MIB_UDP6TABLE* Udp6Table,   // optional
    DWORD* SizePointer,
    BOOL Order
);
[DllImport("IPHLPAPI.dll", ExactSpelling = true)]
static extern uint GetUdp6Table(
    IntPtr Udp6Table,   // MIB_UDP6TABLE* optional, out
    ref uint SizePointer,   // DWORD* in/out
    bool Order   // BOOL
);
<DllImport("IPHLPAPI.dll", ExactSpelling:=True)>
Public Shared Function GetUdp6Table(
    Udp6Table As IntPtr,   ' MIB_UDP6TABLE* optional, out
    ByRef SizePointer As UInteger,   ' DWORD* in/out
    Order As Boolean   ' BOOL
) As UInteger
End Function
' Udp6Table : MIB_UDP6TABLE* optional, out
' SizePointer : DWORD* in/out
' Order : BOOL
Declare PtrSafe Function GetUdp6Table Lib "iphlpapi" ( _
    ByVal Udp6Table As LongPtr, _
    ByRef SizePointer As Long, _
    ByVal Order As Long) As Long
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。
import ctypes
from ctypes import wintypes

GetUdp6Table = ctypes.windll.iphlpapi.GetUdp6Table
GetUdp6Table.restype = wintypes.DWORD
GetUdp6Table.argtypes = [
    ctypes.c_void_p,  # Udp6Table : MIB_UDP6TABLE* optional, out
    ctypes.POINTER(wintypes.DWORD),  # SizePointer : DWORD* in/out
    wintypes.BOOL,  # Order : BOOL
]
require 'fiddle'
require 'fiddle/import'

lib = Fiddle.dlopen('IPHLPAPI.dll')
GetUdp6Table = Fiddle::Function.new(
  lib['GetUdp6Table'],
  [
    Fiddle::TYPE_VOIDP,  # Udp6Table : MIB_UDP6TABLE* optional, out
    Fiddle::TYPE_VOIDP,  # SizePointer : DWORD* in/out
    Fiddle::TYPE_INT,  # Order : BOOL
  ],
  -Fiddle::TYPE_INT)
#[link(name = "iphlpapi")]
extern "system" {
    fn GetUdp6Table(
        Udp6Table: *mut MIB_UDP6TABLE,  // MIB_UDP6TABLE* optional, out
        SizePointer: *mut u32,  // DWORD* in/out
        Order: i32  // BOOL
    ) -> u32;
}
// crates: windows-sys provides ready-made bindings for this API.
$sig = @"
[DllImport("IPHLPAPI.dll")]
public static extern uint GetUdp6Table(IntPtr Udp6Table, ref uint SizePointer, bool Order);
"@
$api = Add-Type -MemberDefinition $sig -Name 'IPHLPAPI_GetUdp6Table' -Namespace Win32 -PassThru
# $api::GetUdp6Table(Udp6Table, SizePointer, Order)
#uselib "IPHLPAPI.dll"
#func global GetUdp6Table "GetUdp6Table" sptr, sptr, sptr
; GetUdp6Table varptr(Udp6Table), varptr(SizePointer), Order   ; 戻り値は stat
; Udp6Table : MIB_UDP6TABLE* optional, out -> "sptr"
; SizePointer : DWORD* in/out -> "sptr"
; Order : BOOL -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。
出力引数:
#uselib "IPHLPAPI.dll"
#cfunc global GetUdp6Table "GetUdp6Table" var, var, int
; res = GetUdp6Table(Udp6Table, SizePointer, Order)
; Udp6Table : MIB_UDP6TABLE* optional, out -> "var"
; SizePointer : DWORD* in/out -> "var"
; Order : BOOL -> "int"
; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。
出力引数:
; DWORD GetUdp6Table(MIB_UDP6TABLE* Udp6Table, DWORD* SizePointer, BOOL Order)
#uselib "IPHLPAPI.dll"
#cfunc global GetUdp6Table "GetUdp6Table" var, var, int
; res = GetUdp6Table(Udp6Table, SizePointer, Order)
; Udp6Table : MIB_UDP6TABLE* optional, out -> "var"
; SizePointer : DWORD* in/out -> "var"
; Order : BOOL -> "int"
; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。
import (
	"golang.org/x/sys/windows"
	"unsafe"
)

var (
	iphlpapi = windows.NewLazySystemDLL("IPHLPAPI.dll")
	procGetUdp6Table = iphlpapi.NewProc("GetUdp6Table")
)

// Udp6Table (MIB_UDP6TABLE* optional, out), SizePointer (DWORD* in/out), Order (BOOL)
r1, _, err := procGetUdp6Table.Call(
	uintptr(Udp6Table),
	uintptr(SizePointer),
	uintptr(Order),
)
_ = err  // syscall.Errno (valid when the call sets last-error)
_ = r1   // DWORD
function GetUdp6Table(
  Udp6Table: Pointer;   // MIB_UDP6TABLE* optional, out
  SizePointer: Pointer;   // DWORD* in/out
  Order: BOOL   // BOOL
): DWORD; stdcall;
  external 'IPHLPAPI.dll' name 'GetUdp6Table';
result := DllCall("IPHLPAPI\GetUdp6Table"
    , "Ptr", Udp6Table   ; MIB_UDP6TABLE* optional, out
    , "Ptr", SizePointer   ; DWORD* in/out
    , "Int", Order   ; BOOL
    , "UInt")   ; return: DWORD
●GetUdp6Table(Udp6Table, SizePointer, Order) = DLL("IPHLPAPI.dll", "dword GetUdp6Table(void*, void*, bool)")
# 呼び出し: GetUdp6Table(Udp6Table, SizePointer, Order)
# Udp6Table : MIB_UDP6TABLE* optional, out -> "void*"
# SizePointer : DWORD* in/out -> "void*"
# Order : BOOL -> "bool"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。
const std = @import("std");

extern "iphlpapi" fn GetUdp6Table(
    Udp6Table: [*c]MIB_UDP6TABLE, // MIB_UDP6TABLE* optional, out
    SizePointer: [*c]u32, // DWORD* in/out
    Order: i32 // BOOL
) callconv(std.os.windows.WINAPI) u32;
proc GetUdp6Table(
    Udp6Table: ptr MIB_UDP6TABLE,  # MIB_UDP6TABLE* optional, out
    SizePointer: ptr uint32,  # DWORD* in/out
    Order: int32  # BOOL
): uint32 {.importc: "GetUdp6Table", stdcall, dynlib: "IPHLPAPI.dll".}
pragma(lib, "iphlpapi");
extern(Windows)
uint GetUdp6Table(
    MIB_UDP6TABLE* Udp6Table,   // MIB_UDP6TABLE* optional, out
    uint* SizePointer,   // DWORD* in/out
    int Order   // BOOL
);
ccall((:GetUdp6Table, "IPHLPAPI.dll"), stdcall, UInt32,
      (Ptr{MIB_UDP6TABLE}, Ptr{UInt32}, Int32),
      Udp6Table, SizePointer, Order)
# Udp6Table : MIB_UDP6TABLE* optional, out -> Ptr{MIB_UDP6TABLE}
# SizePointer : DWORD* in/out -> Ptr{UInt32}
# Order : BOOL -> Int32
# stdcall は 32bit のみ意味を持つ(x64 では無視)。
local ffi = require("ffi")
ffi.cdef[[
uint32_t GetUdp6Table(
    void* Udp6Table,
    uint32_t* SizePointer,
    int32_t Order);
]]
local iphlpapi = ffi.load("iphlpapi")
-- iphlpapi.GetUdp6Table(Udp6Table, SizePointer, Order)
-- Udp6Table : MIB_UDP6TABLE* optional, out
-- SizePointer : DWORD* in/out
-- Order : BOOL
-- 構造体/GUIDへのポインタは cdef が通るよう void* で表記(実型は各引数コメント参照)。値渡し構造体・enum は対応する typedef を cdef に追加すること。
const koffi = require('koffi');
const lib = koffi.load('IPHLPAPI.dll');
const GetUdp6Table = lib.func('__stdcall', 'GetUdp6Table', 'uint32_t', ['void *', 'uint32_t *', 'int32_t']);
// GetUdp6Table(Udp6Table, SizePointer, Order)
// Udp6Table : MIB_UDP6TABLE* optional, out -> 'void *'
// SizePointer : DWORD* in/out -> 'uint32_t *'
// Order : BOOL -> 'int32_t'
// 出力ポインタは koffi.out(...) で包む。構造体は koffi.struct で定義。
const lib = Deno.dlopen("IPHLPAPI.dll", {
  GetUdp6Table: { parameters: ["pointer", "pointer", "i32"], result: "u32" },
});
// lib.symbols.GetUdp6Table(Udp6Table, SizePointer, Order)
// Udp6Table : MIB_UDP6TABLE* optional, out -> "pointer"
// SizePointer : DWORD* in/out -> "pointer"
// Order : BOOL -> "i32"
// 文字列引数は "buffer"(NUL 終端のバイト列を Uint8Array で渡す)。
// 値渡し構造体は { struct: [ ...field types... ] } を使用。
<?php
$ffi = FFI::cdef(<<<C
uint32_t GetUdp6Table(
    void* Udp6Table,
    uint32_t* SizePointer,
    int32_t Order);
C, "IPHLPAPI.dll");
// $ffi->GetUdp6Table(Udp6Table, SizePointer, Order);
// Udp6Table : MIB_UDP6TABLE* optional, out
// SizePointer : DWORD* in/out
// Order : BOOL
// 構造体/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 GetUdp6Table(
        Pointer Udp6Table,   // MIB_UDP6TABLE* optional, out
        IntByReference SizePointer,   // DWORD* in/out
        boolean Order   // BOOL
    );
}
@[Link("iphlpapi")]
lib LibIPHLPAPI
  fun GetUdp6Table = GetUdp6Table(
    Udp6Table : MIB_UDP6TABLE*,   # MIB_UDP6TABLE* optional, out
    SizePointer : UInt32*,   # DWORD* in/out
    Order : Int32   # BOOL
  ) : UInt32
end
# 構造体/GUID/enum は lib 内に対応する型定義が必要。
# 呼出規約: x64 は規約統一のため OK。x86(32bit)は WINAPI=stdcall だが Crystal の fun に stdcall 付与構文がなく非対応。
import 'dart:ffi';
import 'package:ffi/ffi.dart';

typedef GetUdp6TableNative = Uint32 Function(Pointer<Void>, Pointer<Uint32>, Int32);
typedef GetUdp6TableDart = int Function(Pointer<Void>, Pointer<Uint32>, int);
final GetUdp6Table = DynamicLibrary.open('IPHLPAPI.dll')
    .lookupFunction<GetUdp6TableNative, GetUdp6TableDart>('GetUdp6Table');
// Udp6Table : MIB_UDP6TABLE* optional, out -> Pointer<Void>
// SizePointer : DWORD* in/out -> Pointer<Uint32>
// Order : BOOL -> Int32
// 文字列は package:ffi の "...".toNativeUtf16()/toNativeUtf8() で変換。
{$mode objfpc}{$H+}
function GetUdp6Table(
  Udp6Table: Pointer;   // MIB_UDP6TABLE* optional, out
  SizePointer: Pointer;   // DWORD* in/out
  Order: BOOL   // BOOL
): DWORD; stdcall;
  external 'IPHLPAPI.dll' name 'GetUdp6Table';
import Foreign
import Foreign.C.Types
import Foreign.C.String

foreign import stdcall safe "GetUdp6Table"
  c_GetUdp6Table :: Ptr () -> Ptr Word32 -> CInt -> IO Word32
-- Udp6Table : MIB_UDP6TABLE* optional, out -> Ptr ()
-- SizePointer : DWORD* in/out -> Ptr Word32
-- Order : BOOL -> CInt
-- 要 GHC(Windows)。stdcall は x64 では ccall として扱われる。ブロックする API は safe 呼び出し推奨。
open Ctypes
open Foreign

let getudp6table =
  foreign "GetUdp6Table"
    ((ptr void) @-> (ptr uint32_t) @-> int32_t @-> returning uint32_t)
(* Udp6Table : MIB_UDP6TABLE* optional, out -> (ptr void) *)
(* SizePointer : DWORD* in/out -> (ptr uint32_t) *)
(* Order : BOOL -> int32_t *)
(* foreign は cdecl 前提。x64 Windows では WINAPI と一致。構造体は ctypes structure を定義のこと。 *)
(cffi:define-foreign-library iphlpapi (t "IPHLPAPI.dll"))
(cffi:use-foreign-library iphlpapi)

(cffi:defcfun ("GetUdp6Table" get-udp6-table :convention :stdcall) :uint32
  (udp6-table :pointer)   ; MIB_UDP6TABLE* optional, out
  (size-pointer :pointer)   ; DWORD* in/out
  (order :int32))   ; BOOL
; isize/usize(INT_PTR/SIZE_T)は x64 前提で :int64/:uint64。x86 では :int32/:uint32。
use Win32::API;
my $GetUdp6Table = Win32::API::More->new('IPHLPAPI',
    'DWORD GetUdp6Table(LPVOID Udp6Table, LPVOID SizePointer, BOOL Order)');
# my $ret = $GetUdp6Table->Call($Udp6Table, $SizePointer, $Order);
# Udp6Table : MIB_UDP6TABLE* optional, out -> LPVOID
# SizePointer : DWORD* in/out -> LPVOID
# Order : BOOL -> BOOL
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。

関連項目

公式の関連項目
使用する型